Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8716019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:58:44+00:00 2026-06-13T05:58:44+00:00

Below is the code I keep trying; I’m basically just trying to use this

  • 0

Below is the code I keep trying; I’m basically just trying to use this to track the page with General GA; then assign a class that tracks onClick events within a category and generates a 1,2,3 automatically at the end of the file name. I’m essentially just trying to streamline tracking my onClick files within a website; I do not want to continue manually adding onClick code to every file I’m trying to track on a page. What is the matter with my below code?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-35609953-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/LowRes01.jpg']);


  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

<!-- GA track all onClicks -->

<script>
$(function(){
    $('.downloadsmall a').attr("onclick", function(i){
        var x='LowRes0'+(i+1)+'.jpg';
        return "_gaq.push(['_trackPageview', '/downloads/img/"+x+"'])";
        return "_gaq.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/"+x+"'])";

    });
});​
</script>

<!-- End GA track all onClicks -->

<style>

#wrap {
    width: 940px;
    margin-left: 0 auto;
}

#left {
    width: 50%;
    float: left;
}

#right {
    width: 50%;
    float: right;
}

.downloadsmall {
height: 50px;
width: 200px;
border: 3px dotted #333;
}


</style>

</head>

<body>

    <div id="wrap"><!-- Wrap -->

    <div id="left">

<p class="downloadsmall">
    download: <a href="http://www.google.com">Low Res</a>
</p>

    </div>

  <div id="right">

<p class="downloadsmall">
    download: <a href="http://www.yahoo.com">Low Res</a>
</p>

    </div>
    </div><!-- Wrap -->

UPDATED —-

Below is the code updated per Jasper’s Response; (thanks !) I have it in and am awaiting to see how it resolves.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<!-- GA track all onClicks -->

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-35609953-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/"+x+"']);


$(function(){
    $('.downloadsmall a').on("click", function(){
        var theHREF = $(this).attr('href'),
            myGAQ   = _gaq || [];
        myGAQ.push(['_trackPageview', theHREF]);
        myGAQ.push(['_trackEvent', 'Downloads', 'JPG', theHREF]);

    });
});

</script>

<!-- End GA track all onClicks -->
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:58:48+00:00Added an answer on June 13, 2026 at 5:58 am

    You are returning a string from your event handler, which won’t actually do anything. Instead, just run the code normally. Also, once you return something from a function, the function stops executing, so your second return isn’t even being run.

    Try this:

    $(function(){
        $('.downloadsmall a').on("click", function(i){
            var x     = 'LowRes0'+(i+1)+'.jpg',
                myGAQ = _gaq || [];
            myGAQ.push(['_trackPageview', '/downloads/img/' + x]);
            myGAQ.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/' + x]);
    
        });
    });​
    

    This code is actually accessing the GA _gaq object and asking it to create a page-view and an event tracking beacon.

    The code still shouldn’t work though, as the i argument in your event handler is really the event object, not an index (which I’m assuming is what you want). You could get the actual HREF of the link and use it as your tracking data:

    $(function(){
        $('.downloadsmall a').on("click", function(){
            var theHREF = $(this).attr('href'),
                myGAQ   = _gaq || [];
            myGAQ.push(['_trackPageview', theHREF]);
            myGAQ.push(['_trackEvent', 'Downloads', 'JPG', theHREF]);
    
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run the code below and I keep getting this error back:
Being new to this I really am trying to learn how to keep code
I'm trying to use the below code to bring back all records that are
I'm trying to get the code below to keep an E-mail form deactivated until
UPDATED: SEE BELOW I've been porting the code for this assignment: http://www.stanford.edu/class/cs221/progAssignments/PA1/search.html (the entire
This question is quite specific to the code i'm trying to use, 1st ill
Using the code below, I want to keep the same menu div opened in
below code is my databasehandler class i got it from a tutorial. Beside that
Trying to figure out how to use haml link_to with Ruby code in order
In the code below, I am trying to create a function patient_count that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.