Google Global Site Tag (gtag.js) integration with ShopSite

Forum Forums Tutorials Google Global Site Tag (gtag.js) integration with ShopSite

This topic contains 0 replies, has 1 voice, and was last updated by  lexiconn 5 years, 8 months ago.

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

    lexiconn
    Keymaster

    What is Google Global Site Tag?

    Google’s global site tag (gtag.js) is a javascript library that integrates tracking between several Google products (Analytics, Adwords, etc).  If you add this library to your site, it replaces any existing analytics tracking scripts you have in place, including Analytics code added automatically by ShopSite under Merchandising -> Google Services -> Analytics.  There is no automated integration of gtag.js by ShopSite at this time, but it may be an option in a future update.  At this time, you should only consider changing to the global site tag if it is required by Google for tracking.

    Integration gtag.js with ShopSite:

    1. The first step is to remove any Google Analytics code from your templates, and turn off Google Analytics tracking under Merchandising -> Google Services -> Analytics.  Otherwise you will have duplicate tracking for all of your pages.

    2. Next, you will need to add the following code as high in the <head> of the page as possible in the [-- DEFINE PAGE --] section of your page templates, in the [-- DEFINE MORE_INFO_PAGE --] section of your product templates, and in the [-- DEFINE ShoppingCart --] and [-- DEFINE Shipping --] section of your shopping cart template:

    <script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'GA_TRACKING_ID');
     
      ga('send', 'pageview');
     
    </script>

    (of course, replace GA_TRACKING_ID in both locations with your GA tracking id).

    3. Add the following code to the [-- DEFINE ThankYou --] section of your shopping cart template:

    <script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'GA_TRACKING_ID');
     
      ga('send', 'pageview');
      ga('require', 'ecommerce');
    
      ga('ecommerce:addTransaction', {
              'id': ss_ordernum,
              'affiliation': '[-- STORE.Name {JS_ENCODE} --]',
              'revenue': ss_ordertotal,
              'shipping': ss_shipping,
              'tax': ss_tax
       });
    
       for(n=0; n<ss_sku.length; n++){
               ga('ecommerce:addItem', {
                      'id': ss_ordernum,
                      'name': ss_name[n],
                      'sku': ss_sku[n],
                      'price': ss_price[n],
                      'quantity': ss_quantity[n]
                    });
       }
    
       ga('ecommerce:send');
    
    </script>

    (again, replace GA_TRACKING_ID in both locations with your GA tracking id).

    4. Regenerate your site (Utilities -> Publish – Regenerate) to apply the new code to all pages on your site.

    • This topic was modified 5 years, 8 months ago by  lexiconn.
    • This topic was modified 5 years, 8 months ago by  lexiconn.
    • This topic was modified 5 years, 8 months ago by  lexiconn.
    • This topic was modified 5 years, 8 months ago by  lexiconn.
    • This topic was modified 5 years, 5 months ago by  lexiconn.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.