Manually Adding Google Analytics To Your Site

Forum Forums Tutorials Manually Adding Google Analytics To Your Site

This topic contains 0 replies, has 1 voice, and was last updated by  Anonymous 13 years, 3 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #48766

    Anonymous
    Participant

    If you are looking to use Google Analytics to track your ShopSite store and you’re using ShopSite to generate all your pages you can configure ShopSite to add the tracking code for you automatically. This can be done in the ShopSite back office under Merchandising > Google Services > Analytics.

    The feature has a wizard which will step you through the process of configuring the settings and when you publish your store ShopSite will automatically add all the tracking code to the store and shopping cart pages.

    If you have pages generated outside of ShopSite or you have a need for customized Google tracking code you will need to add the code manually to your site. In this tutorial we’ll step through the details on how to do that and will provide sample tracking code as well.

    ShopSite Documentation

    ShopSite has details on how to sign up for a Google account and steps for manually adding the code to ShopSite generated pages here:

    http://www.shopsite.com/help/10.2/en-US/sc/pro/googleanalytics.html

    The code in Step 1 of the “Put Google Analytics Code on Store Pages” section of the documentation is an older version of the tracking code, so instead of using the code you see there you would want to use this code:

    Traditional Code

    <script type="text/javascript"> 
     var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
     document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); 
     </script> 
     <script type="text/javascript"> 
     try{ 
     var pageTracker = _gat._getTracker("UA-xxxxxx-x"); 
     pageTracker._trackPageview(); 
     } catch(err) {} 
     </script> 
    

     

    The code above is the “Traditional” version of Google’s tracking code, and there is also a newer “Asynchronous” version that you may use instead:

    Asynchronous Code

    <script type="text/javascript"> 
       var _gaq = _gaq || []; 
       _gaq.push(['_setAccount', 'UA-xxxxxx-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'; 
         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
       })(); 
     </script> 
    

     

    NOTE: Be sure to change the “UA-xxxxxx-x” text to your “UA” tracking code provided by Google.

    Either code version above will work to track your site, and here are details from Google regarding the new Asynchronous version:

    “The latest version of the Analytics tracking code offers an improved way to track website visitors with Google Analytics. It takes advantage of browser support for asynchronous JavaScript to enhance the speed in which the tracking code is loaded. With this version of the tracking code, you can also place the Analytics snippet higher in the page without delaying subsequent content from rendering.”

    For further reading about the new code, Google has details here:

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

    Store & Product Pages
    The code above goes on every page of your site except for the Thank You page. Continue through the remaining steps of the “Put Google Analytics Code on Store Pages” section of the documentation for tips on how to add the code to your pages in ShopSite. You would also manually add the code to any pages that were created outside of ShopSite.

    Shopping Cart Pages
    While the “Put Google Analytics Code on Shopping Cart Pages” of the ShopSite documentation has details about adding the tracking code to each step of your shopping cart process, we have steps below that we recommend you follow. These steps will use the new code we provided above:

    To begin, you will take the same tracking code you selected above (Traditional or Asynchronous) and add it to the following fields in the ShopSite back office:

    1. Click on Commerce Setup > Order System > Shopping Cart and paste the code into the Text at the Bottom of the Shopping Cart Screen text box, then click Save Changes.
    2. Click on Commerce Setup > Order System > Checkout and paste the code into the Text at the Bottom of the Shipping Screen text box, then click Save Changes.
    3. If you are using a confirmation screen, click on Commerce Setup > Order System > Confirmation and paste the code into the Text at the Bottom of the Confirmation Screen text box, then click Save Changes.

    The remaining page will be the Thank You page, which will use different code in order to properly track the ecommerce values of the store along with the standard traffic and usage details.

    If you’re using the Traditional code for tracking, you will use this code for the Thank You page:

    <script type="text/javascript"> 
     var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
     document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); 
     </script> 
     
     <script type="text/javascript"> 
     try{ 
       var pageTracker = _gat._getTracker("UA-xxxxxx-x"); 
       pageTracker._trackPageview(); 
     
        pageTracker._addTrans(ss_ordernum, ss_associate, ss_ordertotal, ss_taxtotal, ss_shiptotal, ss_city, ss_state, ss_country); 
        for (var p = 0 ; p < number_products ; p++) { 
           pageTracker._addItem(ss_ordernum, ss_sku[p], ss_name[p], "Products", ss_price[p], ss_quantity[p]); 
        } 
        for (var c = 0 ; c < number_coupons ; c++) { 
           pageTracker._addItem(ss_ordernum, ss_coupon_name[c], ss_coupon_name[c], "Coupons", ss_coupon_discount[c], 1); 
        } 
        pageTracker._trackTrans(); 
     }  catch(err) {} 
     </script> 
    

     

    ..or if you are using the Asynchronous code for tracking, you will use this code:

    <script type="text/javascript"> 
     
       var _gaq = _gaq || []; 
       _gaq.push(['_setAccount', 'UA-xxxxxx-x']); 
       _gaq.push(['_trackPageview']); 
       _gaq.push(['_addTrans', 
         ss_ordernum,           // order ID - required 
         ss_associate,  // affiliation or store name 
         ss_ordertotal,          // total - required 
         ss_taxtotal,           // tax 
         ss_shiptotal,              // shipping 
         ss_city,       // city 
         ss_state,     // state or province 
         ss_country             // country 
       ]); 
     
        // add item might be called for every item in the shopping cart 
        // where your ecommerce engine loops through each item in the cart and 
        // prints out _addItem for each 
        for (var p = 0 ; p < number_products ; p++) { 
       _gaq.push(['_addItem', 
         ss_ordernum,           // order ID - required 
         ss_sku[p],           // SKU/code - required 
         ss_name,        // product name 
         'Products',   // category or variation 
         ss_price[p],          // unit price - required 
         ss_quantity[p]               // quantity - required 
       ]); 
       } 
       for (var c = 0 ; c < number_coupons ; c++) { 
       _gaq.push(['_addItem', 
         ss_ordernum,           // order ID - required 
         ss_coupon_name[c],           // Coupon Name - required 
         ss_coupon_name[c],        // Coupon name 
         'Coupons',   // category or variation 
         ss_coupon_discount[c],          // Coupon Discount - required 
         '1'               // quantity - required 
       ]); 
       } 
       _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers 
     
       (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> 
    

     

    NOTE: Be sure to change the “UA-xxxxxx-x” text to your “UA” tracking code provided by Google.

    To add this code to your site, click on Commerce Setup > Order System > Thank You and paste the code into the Text at the Bottom of the Thank You Screen text box, then click Save Changes.

    TIP: If you’re using the Asynchronous code and you’re familiar with editing your ShopSite templates you may instead add the tracking code to the ” DEFINE ThankYou” section of your Shopping Cart template, within the “” section of the code. This will allow the tracking code to load faster, but this change is not required.

    Note: If you’re using the Traditional code, it must be within the “” section and not the header. The “Text at the Bottom of the Thank You Screen” field mentioned above will work fine for that version of the code.

    For additional reference, Google has details on the eCommerce tracking features of Google Analytics here:

    http://code.google.com/apis/analytics/docs/tracking/gaTrackingEcommerce.html

    • This topic was modified 9 years, 11 months ago by  admin.
    • This topic was modified 9 years, 11 months ago by  admin.
    • This topic was modified 9 years, 11 months ago by  admin.
    • This topic was modified 9 years, 11 months ago by  admin.
    • This topic was modified 9 years, 11 months ago by  admin.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.