Announcement

Collapse
No announcement yet.

Asynchronous Google Tracking Code, Verification and Merchant Account

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Asynchronous Google Tracking Code, Verification and Merchant Account

    Asynchronous Google Tracking Code, Verification and Merchant Account

    Client has v12 site with built in SD Google analytics tracking. He ran into some issues and I saw he had added a second block of Google Analytics code to the head which was though the be causing javascript conflicts so I removed it. The Usual code in the footer was still visible on 'view source' but Google decided that his site was no longer verified and unclaimed his site from his Google Merchant Account.

    I opened Google Analytics Tracking Code in Design Library and replaced the code with the new code incorporating (hopefully correctly - please can anyone check) the receipt page bit.

    Saved and placed in Javascript Header Functions at the bottom and removed from the bottom of the outer layouts. Once the new code was in place I was able to re-verify the site and reclaim the URL in Google Merchant. All because Google now only looks in the head section for the analytics code!

    Here is the new code:
    Code:
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true" >
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '<actinic:variable name="GoogleAnalyticsNumber" />']);
      _gaq.push(['_trackPageview'<actinic:block if="%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%3d%3d%20%22Receipt%22">,'/receipt.html'</actinic:block>]);
    
      (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>
    
    </actinic:block>

    Please remember I am not a great coding expert, I haven't touched the other google layouts in the design library. Will any of these other layouts now need changing?

    Thank you
    Last edited by graphicz; 13-Jan-2015, 04:10 PM. Reason: Edited new code - ga'+'.'+'js' to avoid spurious 'acatalog' on home page
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    #2
    The problem now is that Google Merchant want the order transmission details. The built in Google code is te old one so I have to rewrite Order Transmission Layout in asynchronous form. This layout picks up the data produced by Item Details, Transaction Details, and Variable Setup.

    I have no way of knowing if what I have done is correct, please can anyone advise and correct me if neccessary?

    Here is my effort:

    Code:
    <actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true%29%20AND%20%28%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%20%3d%3d%20%22Receipt%22%29" >
    <script type="text/javascript">
    <!--
      var _gaq = _gaq || [];
      
      _gaq.push(['_setAccount', '<actinic:variable name="GoogleAnalyticsNumber" />']);
    
      _gaq.push(['_initData']);
    
    _gaq.push(function() {
    
      eval(act_order);
      
      eval(act_item);
      
      }
    
    _gaq.push(['_trackPageview']);
    
    _gaq.push(['_trackTrans']);
    //-->
    </script>
    </actinic:block>
    Thank you so much

    Jonathan
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    Comment


      #3
      Matthew Foley in support has come up with new Google Analytics codes. Remember to put the Google Analytics Tracking Code at the end of the Javascript header functions, not before the </body> tag.

      Please make the following changes to their layouts after backing up:

      Google Analytics Item Details

      Code:
      <actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true%29%20AND%20%28%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%20%3d%3d%20%22Receipt%22%29" >
      <script type="text/javascript">
      <!--
      var act_productname = "<actinic:variable name="ProductNameOnline" />";
      act_productname = act_productname.replace(rRemoveEncoded, " ");
      ga('ecommerce:addItem', {
      'id': act_ordernumber, // Transaction ID. Required
      'name': act_productname, // Product name. Required
      'sku': '<actinic:variable name="ProdRef" />', // SKU/code
      'category': '', // Category or variation
      'price': act_price, // Unit price
      'quantity': '<actinic:variable name="Quantity" />' // Quantity
      });
      //-->
      </script>
      </actinic:block>
      Google Analytics Order Transmission

      Code:
      <actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true%29%20AND%20%28%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%20%3d%3d%20%22Receipt%22%29" >
      <script type="text/javascript">
      <!--
      ga('create', '<actinic:variable name="GoogleAnalyticsNumber" />', 'auto');
      ga('send', 'pageview');
      ga('require', 'ecommerce'); // Load the ecommerce plug-in.
      
      ga('ecommerce:send'); // Send transaction and item data to Google Analytics.
      //-->
      </script>
      </actinic:block>
      Google Analytics Tracking Code

      Code:
      <actinic:block if="%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true" >
      <!-- Google Analytics -->
      <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      
      ga('create', '<actinic:variable name="GoogleAnalyticsNumber" />', 'auto'); // Replace with your property ID.
      ga('send', 'pageview');
      
      </script>
      <!-- End Google Analytics -->
      </actinic:block>
      Google Analytics Transaction Details

      Code:
      <actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true%29%20AND%20%28%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%20%3d%3d%20%22Receipt%22%29" >
      <script type="text/javascript">
      <!--
      var act_total = "<actinic:variable name="Total" />"
      act_total = act_total.replace(rConverDot, ".");
      act_total = act_total.replace(rRemoveEncoded, "");
      var act_tax = "<actinic:variable name="Tax1" />";
      act_tax = act_tax.replace(rConverDot, ".");
      act_tax = act_tax.replace(rRemoveEncoded, "");
      var act_shipping = "<actinic:variable name="Shipping" />"
      act_shipping = act_shipping.replace(rConverDot, ".");
      act_shipping = act_shipping.replace(rRemoveEncoded, "");
      ga('create', '<actinic:variable name="GoogleAnalyticsNumber" />', 'auto');
      ga('send', 'pageview');
      ga('require', 'ecommerce'); // Load the ecommerce plug-in.
      ga('ecommerce:addTransaction', {
      'id': act_ordernumber, // Transaction ID. Required
      'affiliation': '<actinic:variable name="StoreName" />', // Affiliation or store name
      'revenue': act_total, // Grand Total
      'shipping': act_shipping, // Shipping
      'tax': act_tax // Tax
      });
      //-->
      </script>
      
      </actinic:block>
      Jonathan Chappell
      Website Designer
      SellerDeck Website Designer
      Actinic to SellerDeck upgrades
      Graphicz Limited - www.graphicz.co.uk

      Comment


        #4
        Hi - I have a couple of questions....

        1. The receipt page seems to only have the following layouts related to Google Analytics:-
        Google Analytics Tracking Code (in the <head>)
        Google Analytics Variable Setup (just after the <body>)
        Google Analytics Order Transmission (just before the </body>).
        Does Matthew's code above advise then that these three layouts need to be all between the <head></head> tags?

        2. The code suggested includes four separate layouts:-
        a. Google Analytics Item Details
        b. Google Analytics Order Transmission
        c. Google Analytics Tracking Code
        d. Google Analytics Transaction Details
        It is obvious that b & c replace the associated layouts in the receipt page but what of the other two - do they both go into the Google Analytics Variable Setup layout?

        3. Does this work.
        Ok - a slightly glib comment I know, but do these new sets of code actually work? It is SO frustrating trying to keep up to date with Google's constantly changing code requirements, particularly when they seem at odds with the default setup in SellerDeck (v11 through to v14 the receipt page layouts are the same despite loads of changes at Google's end.

        Help very much appreciated.
        Thanks,
        Chris
        Chris Adams

        Comment

        Working...
        X