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

  • SEARCH
  • Home
  • 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 8314339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:47:05+00:00 2026-06-08T20:47:05+00:00

I am attempting to use the gaAddons Google Analytics jQuery plugin to track downloads

  • 0

I am attempting to use the gaAddons Google Analytics jQuery plugin to track downloads on my site, so any .JPGs, .PNGs, .PDFs etc that have been downloaded I want to track by executing some tracking code.

Clearly something is not working correctly, as I cannot seem to get the _trackEvent to fire.

This is the JavaScript which resides in the gaAddons plugin.

///////////////////
// _trackDownloads
jQuery(document).ready(function($) {
    // helper function - allow regex as jQuery selector
    $.expr[':'].regex = function(e, i, m) {
        var mP = m[3].split(','),
            l = /^(data|css):/,
            a = {
                method: mP[0].match(l) ? mP[0].split(':')[0] : 'attr',
                property: mP.shift().replace(l, '')
            },
            r = new RegExp(mP.join('').replace(/^\s+|\s+$/g, ''), 'ig');
        return r.test($(e)[a.method](a.property));
    };

    $('a:regex(href,"\\.(zip|mp\\d+|mpe*g|pdf|docx*|pptx*|xlsx*|jpe*g|png|gif|tiff*)")$').live('click', function(e) {
        _gaq.push(['_trackEvent', 'download', 'click', this.href.replace(/^.*\/\//, '')]);
    });
});

I have the above code included on the page and my simple anchor linking to a PDF file below.

<a href="http://www.ayrshireminis.com/downloads/Files/pdfs/turnberry.pdf" target="blank">DOWNLOAD</a>

Is there something wrong with the JavaScript or is there a simpler way to check for jpg/png/pdf file downloads? I can probably ignore the zip/ppt/tiff files as they will not be on the site.

  • 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-08T20:47:07+00:00Added an answer on June 8, 2026 at 8:47 pm

    I have raked around for hours and came across this solution, hope this helps someone:

    jQuery(document).ready(function($) {
        var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
        var baseHref = '';
        if (jQuery('base').attr('href') != undefined)
            baseHref = jQuery('base').attr('href');
            jQuery('a').each(function() {
                var href = jQuery(this).attr('href');
                if (href && href.match(filetypes)) {
                    jQuery(this).click(function() {
                        var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                        var filePath = href;
                        _gaq.push(['_trackEvent', 'Download', 'Click-' + extension, filePath]);
                        if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
                            setTimeout(function() { location.href = baseHref + href; }, 200);
                            return false;
                        }
                    });
                }
            });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to use the AutoComplete plugin for jQuery UI, specifically the multiple
I'm attempting to use Google's Guava ImmutableSet class to create a set of immutable
I'm attempting to use the Google geocoder API to enter user's location information directly
I am attempting to use the Struts2 JUnit Plugin (v2.2.3 w/ Struts2 v2.2.3) and
I am attempting to use coffeescript/jQuery to do the following: 1) Retrieve all the
I am attempting to use jQuery Mobile's Select Menu in a Navbar as a
I am attempting to use Chrome-Frame on a site I'm building. In IE8 and
I am attempting to use oauth API to authenticate a google service account through
Attempting to use the data series from this example no longer passes the JSONLint
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng

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.