dvdsmpsn’s blog has moved elsewhere

has moved to http://davidsimpson.me/

jGoogleAnalytics – Google Analytics integration for jQuery

with 13 comments

Written by David Simpson PhD

June 18, 2008 at 10:43 am

13 Responses

Subscribe to comments with RSS.

  1. […] to support the new ga.js script from Google Analytics. Hence, I am very interested in trying out dvdsmpsn’s jGoogleAnalytics plugin, which not only converts my original plugin to work with ga.js, but also adds a slew of additional […]

  2. Hi,

    Thanks for this, it looks like a good upgrade from Jason Huck’s code, I’m interested how I can track events that only happen on a single page (so shouldn’t be wired up throughout the site). e.g. Upselling, at the moment we do this onclick: javascript:urchinTracker(‘/upsold/false/Some-Item’);

    Is that possible with your code?

    Tim

    Tim

    July 8, 2008 at 2:59 pm

  3. Great stuff!

    Bert

    July 18, 2008 at 12:11 pm

  4. Tim: If your upselling links had a parent container with a class name of “upsell”, e.g.


    [ul class="upsell"]
    [li][a href="http://example1.com"]Example 1[/a][/li]
    [li][a href="http://example2.com"]Example 2[/a][/li]
    [li][a href="http://example3.com"]Example 3[/a][/li]
    [/ul]

    …sorry for the square brackets

    Your call to jGoogleAnalytics would be:

    $.jGoogleAnalytics( 'UA-XXXXXX-X', evalClickEvents: {'.upsell a': "'/upsell/'+ $(this).text()"} );

    This registers a click event for each anchor in the .upsell container, evaluates the link text and send it to GA.

    The page impressions in GA for each link above would read:
    /upsell/Example 1
    /upsell/Example 2
    /upsell/Example 3

    dvdsmpsn

    July 18, 2008 at 8:20 pm

  5. Thanks for getting back to me, I’ve done something similar however as my upsell links are image buttons (so no text) I’ve done the following (the user has the choice in upgrading or not hence the true/false):

    $.jGoogleAnalytics(
    ‘UA-123456-7’,
    {
    evalClickEvents: {
    ‘.upsellt’: “‘/upsell/true/’ + $(this).attr(‘title’)”,
    ‘.upsellf’: “‘/upsell/false/’ + $(this).attr(‘title’)”
    }
    }
    );

    And here’s the relevant HTML:

    But I can’t see the upsell being logged anywhere in Google (but the page hits are).

    Any ideas?

    Tim

    Tim

    July 21, 2008 at 10:00 am

  6. Ops sorry about the html (with square brackets):

    [a href=”/order/?li=241&vi=167&act=add” class=”upsellt” title=”Classic+Wax+100g”][img src=”/img/bYes.png” /][/a]

    Tim

    July 21, 2008 at 1:32 pm

  7. Great plugin! Thanks! One problem though…

    Using $.getScript will reload ga.js from google every time a page is requested. I fixed it by creating a function with the following code:

    return jQuery.ajax({
    type: “GET”,
    url: gaScriptURL,
    dataType: “script”,
    cache: true,
    success: function() { setupTracking(); }
    });

    The essential part is to pass parameter cache: true. Now, jQuery will not force reloading the script every time.

    Harri Kauhanen

    September 28, 2008 at 7:23 pm

  8. @Harri:
    Thanks. I’ll get it updated.

    dvdsmpsn

    September 28, 2008 at 11:11 pm

  9. I just wanted to say thanks. We have this in testing over on our site and it has worked like a dream. I’ll let you know when we get a compressed version uploaded.

    Erik Karulf

    October 14, 2008 at 2:53 am

  10. @Erik:
    I’m glad it’s working for you – please let me know the sites you’ve got it on.

    Sorry – I guess I could have compressed it, but when we build our javascript, we compress many files into one, so it’s of no use to me 😉

    dvdsmpsn

    January 30, 2009 at 9:51 pm

  11. What happened to the post? You said it moved, but i get a 404.

    Eluck Twix

    February 26, 2010 at 8:33 am

  12. 🙂

    David Simpson PhD

    August 18, 2016 at 10:45 am


Leave a reply to Tim Cancel reply