Results 1 to 4 of 4

Thread: Event Tracking with Google Analytics

  1. #1
    Join Date
    Jul 2006
    Posts
    70

    Smile Event Tracking with Google Analytics

    I saw GA released event tracking to all last thursday (http://analytics.blogspot.com/2009/0...le-in-all.html).

    Has anyone implemented this with the Event Tracker in ASPDNSF.

    I was able to use it manually on some pages but haven't used the Event Tracker in the ADMIN section.

    Is there going to be an addition to the Manual, maybe and KB article?

    Chaz.

  2. #2
    Join Date
    Jul 2006
    Posts
    70

    Default

    Okay. So, I started playing around with the Event Handling in ASPDNSF there doesn't seem to be an easy way to incorporate the Analytics event tracking code into it. I might just have to hard code it.

    Anyone else playing around with this feature?

    Chaz.

  3. #3
    Join Date
    Jan 2012
    Posts
    6

    Default Event Tracking attempt

    Hi,

    I'm currently having a little luck attaching an event to the "add to cart" button. I modified the code that generates the button in shoppingcart.cs (line 9050 for me) to call some javascript function doGoogleAnalyticsAdd(). Then my function looks like this -

    Code:
    var skus = new Array();
    var prices = new Array();
    
    <xsl:for-each select="/root/Products/Product">
            skus[<xsl:value-of select="VariantID" />] = "<xsl:value-of select="SkuSuffix" />";
    	prices[<xsl:value-of select="VariantID" />] = "<xsl:value-of select="Price" />";
    </xsl:for-each>
    
    
    function doGoogleAnalyticsAdd()
    {
    	_gaq.push(['_trackEvent', 'SHOPPING', 'ADD_TO_CART', skus[theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value], prices[theForm.VariantID_<xsl:value-of select="/root/Products/Product/ProductID" />_<xsl:value-of select="$defaultVariant" />.value]]);
    }
    It's acting funny though - it only triggers the function doGoogleAnalyticsAdd() when I push the button, press back in my browser, then push the button again. Also, when it does work, it doesn't load the shopping cart page like it should.

    I'll report back if I find out how to get it to work.
    Last edited by nickelbob; 05-31-2012 at 01:29 PM.

  4. #4
    Join Date
    Jan 2012
    Posts
    6

    Default

    Instead of attaching the onclick event in the html code (shoppingcart.cs) you'll want to do it at runtime like so

    Code:
    //Make the first shoe the default
    $("document").ready(function() {
           $("#addToCartControls .AddToCartButton").on("click", function() {doGoogleAnalyticsAdd();var selectedVariant = document.getElementById('variantSelect').value;ValidateVariant(selectedVariant, null);});
    });
    Make sure you're not replacing any pre-attached onclick functions as by default aspdnsf uses a few functions to validate the form when items are added to the cart. In my case, these are the lines of code

    Code:
    var selectedVariant = document.getElementById('variantSelect').value;ValidateVariant(selectedVariant, null);
    found after my custom event function "doGoogleAnalyticsAdd".
    Last edited by nickelbob; 06-04-2012 at 12:21 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •