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 8690275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:52:04+00:00 2026-06-12T23:52:04+00:00

I’m trying to come up with a Script; using perhaps, ‘ Math Method in

  • 0

I’m trying to come up with a Script; using perhaps, ‘Math Method in Javascript — that allows me to simply attach a CSS class to dozens of files / photos / media, etc that I am using google Analytics to track onClick.

Essentially; I’ve been implementing the below, manually; across dozens of sites where I want to track onClick.

<p class="downloadsmall">download: <a href="jpg/LOW/1.jpg" onClick="_gaq.push(['_trackPageview', '/downloads/img/LowRes/1.jpg']);">Low Res</a></p>

I’m wondering if I can simply define a class here; and within a JavaScript array or similar; I call the class attached to the mark-up; that assigns Google’s onClick Tracking code automatically; while at the same time populating the name differently, in a simple way; like adding a 1,2,3 etc at the end of the name.

EG;

'/downloads/img/LowRes01.jpg']);">Low Res</a></p>
'/downloads/img/LowRes02.jpg']);">Low Res</a></p>

*Anyone have any suggestions as to how I can write this? Is it possible?*


Update: //
Below is the full code I’m trying; The standard GA seems to read, but it is not resolving any of the onClicks? I’ve checked under ‘Content Drilldown’ and ‘Events’ and nothing is seeming to resolve except the Basic ‘GA’ Reading.

<!doctype html>

<head>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-35609953-1']);
  _gaq.push(['_trackPageview']);

  (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+"'])";
    });
});​
</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 -->


</body>

</html>

UPDATE —
// I now have it so it is reading the page ‘events’ and is tracking the page views, but it is not categorizing as LowRes01.jpg – LowRes02.jpg according to the attached class; which was the main goal — Below is my updated Full Code. What am I doing wrong here ?

<!doctype html>

<head>

<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 -->


</body>

</html>
  • 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-12T23:52:05+00:00Added an answer on June 12, 2026 at 11:52 pm

    Did you mean something like this

    $(function(){
        $('.downloadsmall a').attr("onclick", function(i){
            var x='LowRes0'+(i+1)+'.jpg';
            return "_gaq.push(['_trackPageview', '/downloads/img/"+x+"'])";
        });
    });​
    

    DEMO (See the html source).

    Source

    <p class="downloadsmall"> download: <a href="jpg/LOW/1.jpg">Low Res</a></p>
    <p class="downloadsmall"> download: <a href="jpg/LOW/2.jpg">Low Res</a></p>
    

    Outout

    <p class="downloadsmall">
        download: <a href="jpg/LOW/1.jpg" onclick="_gaq.push(['_trackPageview', '/downloads/img/LowRes01.jpg'])">Low Res</a>
    </p>
    <p class="downloadsmall">
        download: <a href="jpg/LOW/2.jpg" onclick="_gaq.push(['_trackPageview', '/downloads/img/LowRes02.jpg'])">Low Res</a>
    </p>
    

    Update:

    To track the event you have to use event tracking method of GA, i.e

    _gaq.push(['_trackEvent', 'Downloads', 'JPG', '/downloads/img/LowRes01.jpg']);
    

    and that’s displayed as Events in the Analytics reporting interface. So, I think it should be like

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

    For more read this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.