Google

ProStores Google Analytics Ansynchronous Tracking Plug-in – FREE

Written on:February 12, 2010
Comments
Add One

Post to Twitter

I am happy to offer our new ProStores Google Analytics Ansynchronous Tracking Plug-in for free here on our blog.

From Google, “asynchronous tracking optimizes how browsers load ga.js so its impact on user experience is minimized. It also allows you to put your Analytics snippet higher in the page without delaying subsequent content from rendering.”

Its also much more flexible and advanced, as well as more accurate, you can push multiple commands at once and you can even split the snippet up depending on your configuration.

1. Remove your old Google Analytics code from the footer if you have it. If you have Google E-commerce tracking in your Order Confirm page leave it, neither code will bother the other one.
2. Open your Header Template, saving a baseline as always, and paste in the code below just after the <body> tag.
3. Make sure you replace UA-xxxxxxx-x with your Google Analytics account number.

<!-- Begin Google CODE -->
<ss:if test="$page.bodytemplate.name = 'orderconfirm'">
<ss:comment>do nothing</ss:comment>
<ss:else/>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxx-x']);
  _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';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();
</script>
</ss:if>
<!-- End Google CODE -->
Visit tracking only, doesn’t track e-commerce purchases or purchase information. See my GA – E-Commerce Plug-in to track purchases in your ProStores store.

If you still need assistance Professional install service is available, if you follow me on twitter you can get a discount.

11 Comments add one

  1. Brian says:

    Google advises putting the async snippet in the section, not the head:

    http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html#Installation

  2. Matt says:

    According to the page you linked it says that the best place to put the snippet it at the top of the <body> tag section, in a ProStores based site that is in whats known as the Header Template. I tweaked a couple things in the post to make what I was saying more clear. thanks for the note!

  3. Matt says:

    Also if you want to post a html tag in the comments you need to wrap it in < code > tags. That way it will show up and not be removed.

  4. Eric Katz says:

    Can this be used in conjunction with the order confirmation template javacsript you posted in your tutorials, such as:

      <script type="text/javascript">
          
    var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-461677-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);
      })();
        pageTracker._addTrans(
          "<ss:value source="$invoice.confirmationNumber" />",
          "x",
          "<ss:value source="$invoice.storeSubTotal"/>",
          "0",
          "0",
          "<ss:value source="$invoice.billToCity"/>",
          "<ss:value source="$invoice.billToState"/>",
          "<ss:value source="$invoice.billToCountry"/>"
        );
        <ss:foreach item="detail" within="$invoice.details">
        pageTracker._addItem(
          "<ss:value source="$invoice.confirmationNumber"/>",
          "<ss:value source="$detail.sku"/>",
          "<ss:value source="$detail.product.name"/>",
          "<ss:value source="$detail.product.oem"/>",
          "<ss:value format="none" source="$detail.price"/>",
          "<ss:value source="$detail.quantity"/>"
        );
        </ss:foreach>
        pageTracker._trackTrans();
      </script>

  5. Eric Katz says:

    Can this be used in conjunction with the order confirmation template javacsript you posted in your tutorials, such as:

      <script type="text/javascript">
          
    var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-*****-**']);
      _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);
      })();
        pageTracker._addTrans(
          "<ss:value source="$invoice.confirmationNumber" />",
          "x",
          "<ss:value source="$invoice.storeSubTotal"/>",
          "0",
          "0",
          "<ss:value source="$invoice.billToCity"/>",
          "<ss:value source="$invoice.billToState"/>",
          "<ss:value source="$invoice.billToCountry"/>"
        );
        <ss:foreach item="detail" within="$invoice.details">
        pageTracker._addItem(
          "<ss:value source="$invoice.confirmationNumber"/>",
          "<ss:value source="$detail.sku"/>",
          "<ss:value source="$detail.product.name"/>",
          "<ss:value source="$detail.product.oem"/>",
          "<ss:value format="none" source="$detail.price"/>",
          "<ss:value source="$detail.quantity"/>"
        );
        </ss:foreach>
        pageTracker._trackTrans();
      </script>

  6. Eric Katz says:

    Feel free to delete my other comments, but I did some researching it looks like this should be the proper formating with the gaq_ , you don’t need to publish this comment either but if you could please contact me if I am doing something obviously wrong.

    
      <script type="text/javascript">
          
    var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-461677-1']);
      _gaq.push(['_trackPageview']);
    _gaq.push(['_addTrans',
       '<ss:value source="$invoice.confirmationNumber" />',           // order ID - required - confirmation number
       'AK Athletics', // affiliation or store name
       '<ss:value source="$invoice.storeSubTotal"/>',          // total - required
       '<ss:value source="$invoice.storeTax"/>',           // tax
       '<ss:value source="$invoice.storeShipping"/>',          // shipping
       '<ss:value source="$invoice.billToCity"/>',       // city
       '<ss:value source="$invoice.billToState"/>',     // state or province
       '<ss:value source="$invoice.billToCountry"/>'             // country
    ]);
    <ss:foreach item="detail" within="$invoice.details">
    _gaq.push(['_addItem',
       '<ss:value source="$invoice.confirmationNumber"/>',           // order ID - necessary to associate item with transaction - confirmation number
       '<ss:value source="$detail.sku"/>',           // SKU/code - required
       '<ss:value source="$detail.product.name"/>',        // product name
       'AK Athletics',   // category or variation
       '<ss:value format="none" source="$detail.price"/>',          // unit price - required
       '<ss:value source="$detail.quantity"/>'               // quantity - required
    ]);
    </ss:foreach>
    _gaq.push(['_trackTrans']);
      (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>
    

  7. Eric Katz says:

    Or just approve them all and don’t delete them. ;D

  8. Matt says:

    Lol, well actually your posts get auto approved. :)

    The Async visit tracking code I listed here does in fact work with the previous e-commerce tracking code from here: http://www.onetakemedia.net/prostoresplugins.html#GA :)

    I’ve got it live on several sites and its been working since I posted this.

    I haven’t reworked the E-commerce version of plug-in because it works just fine and the Order Confirm page doesn’t really need the speed boost since that page is disallowed in robots.txt by association. Thusly I have not spent the time to re-code it. :)

    Just by glancing at it your code does seem to be laid out correctly. You can always give it a whirl for a couple purchases and then put the old code back up and check the next day to see if those purchases work. :)

  9. Eric Katz says:

    Thanks Matt, it seems like I am still getting very inconsistent results with the ecommerce tracking. For instance my most popular product doesn’t even come up in my analytics tracking.

  10. Philip says:

    Matt,

    Just wanted to tell you that you contributions are fantastic. I’ve searched high and low for some solutions for prostores. These look like they will do the trick. I think I’ll give you guys a call for confirmation.

  11. Matt says:

    Thanks Philip, I enjoyed my conversation with you. :-)

Leave a Comment

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>