{"id":190,"date":"2015-06-09T13:02:55","date_gmt":"2015-06-09T19:02:55","guid":{"rendered":"https:\/\/www.visualfuture.com\/davetech\/?p=190"},"modified":"2015-06-09T13:05:04","modified_gmt":"2015-06-09T19:05:04","slug":"google-tag-manager-for-bigcommerce","status":"publish","type":"post","link":"https:\/\/www.visualfuture.com\/davetech\/2015\/06\/09\/google-tag-manager-for-bigcommerce\/","title":{"rendered":"Google Tag Manager for BigCommerce"},"content":{"rendered":"<p>Yes, it IS possible to use Google Tag Manager to implement Google Analytics on a BigCommerce site.<\/p>\n<p>Before we dive in I want to thank one of my developers, Scott Rarden and also Anirudh from Google for their help.<\/p>\n<p>And a huge thanks to Jeremy &amp; the others on the GTM threads.\u00a0 I&#8217;m very new to BigCommerce and the paths they forged were incredibly helpful in coming up with a solution.<\/p>\n<p>Now for the gory details:<\/p>\n<p>As Jeremy mentioned previously you will need to add a new Panel to every page that should include GTM.\u00a0 The GTM Panel should be placed just after the opening &lt;body&gt; tag.<\/p>\n<p>Create a new file \/template\/Panel\/GoogleTagManagerTag.html<\/p>\n<p>The file should contain the Google Tag Manager code for your site which will look similar to the one below:<\/p>\n<pre>\u00a0&lt;!-- Google Tag Manager --&gt;\r\n&lt;noscript&gt;&lt;iframe src=\"\/\/www.googletagmanager.com\/ns.html?id=GTM-YOURCODE\"\r\nheight=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"&gt;&lt;\/iframe&gt;&lt;\/noscript&gt;\r\n&lt;script&gt;(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\r\nnew Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\r\nj=d.createElement(s),dl=l!='dataLayer'?'&amp;l='+l:'';j.async=true;j.src=\r\n'\/\/www.googletagmanager.com\/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\r\n})(window,document,'script','dataLayer','GTM-YOURCODE');&lt;\/script&gt;\r\n&lt;!-- End Google Tag Manager --&gt;<\/pre>\n<p>Make sure you use the GTM code that your receive from the GTM website.\u00a0 Don&#8217;t copy\/paste the example above.<\/p>\n<p>Once the Panel is created it then needs to be included on every page of your site.<\/p>\n<p>For either method below you will likely need to review all of the template files that a visitor is capable of viewing.<\/p>\n<p>Option 1:<\/p>\n<p>Add the new GTM panel to all of your publicly visible pages by hand. Depending on the design you&#8217;re using for your site this can be 55-60 (or more) pages.<\/p>\n<p>Option 2:<\/p>\n<p>If you already have a Panel appearing in the correct spot then we can add our GTM Panel to the existing Panel.<\/p>\n<p>Review your template files.<\/p>\n<p>Open each of the files in the top level of the \/template folder and view them in a text editor.<\/p>\n<p>Locate the opening &lt;body&gt; tag.<\/p>\n<p>Determine if there is (or is not) a Panel immediately after the opening &lt;body&gt; tag on all pages.<\/p>\n<ul>\n<li>If there IS a Panel immediately after the opening body tag on all pages then you can use Option 2.<\/li>\n<\/ul>\n<ul>\n<li>If there is NOT a panel immediately after then you will need to edit the file and include the Panel by hand.<\/li>\n<\/ul>\n<p>Option 1 Example:<\/p>\n<pre>&lt;body id=\"home\"&gt;\r\n\u00a0\u00a0 \u00a0&lt;div class=\"page\"&gt;\r\n\u00a0 \u00a0\u00a0 \u00a0%%Panel.Header%%\r\n\u00a0\u00a0\u00a0 %%Panel.HomeSlideShowJavaScript%%<\/pre>\n<p>Since there is no Panel immediately after the &lt;body&gt; tag one must be created.\u00a0 The GTM tag should NEVER be placed inside of a &lt;div&gt; or other tag.\u00a0 It must reside directly within the &lt;body&gt; tag.<\/p>\n<pre>&lt;body id=\"home\"&gt;\r\n\u00a0\u00a0 \u00a0%%Panel.GoogleTagManagerTag%%\r\n\u00a0\u00a0 \u00a0&lt;div class=\"page\"&gt;\r\n\u00a0 \u00a0\u00a0 \u00a0%%Panel.Header%%\r\n\u00a0\u00a0\u00a0 %%Panel.HomeSlideShowJavaScript%%<\/pre>\n<p>Option 2 Example:<\/p>\n<pre>&lt;body id=\"home\"&gt;\r\n\u00a0\u00a0 \u00a0%%Panel.DrawerMenu%%\r\n\u00a0\u00a0 \u00a0&lt;div class=\"page\"&gt;\r\n\u00a0 \u00a0\u00a0 \u00a0%%Panel.Header%%\r\n\u00a0\u00a0\u00a0 %%Panel.HomeSlideShowJavaScript%%<\/pre>\n<p>The %%Panel.DrawerMenu%% is in the correct location for the GTM tag.\u00a0 As long as the %%Panel.DrawerMenu%% appears on all of the publicly visible pages we can simply add our GTM Panel to the existing Panel.<\/p>\n<ul>\n<li>edit\/customize the existing \/template\/Panels\/DrawerMenu.html file<\/li>\n<li>add %%Panel.GoogleTagManagerTag%% to the top of the file.<\/li>\n<\/ul>\n<p>Before:<\/p>\n<pre>&lt;div id=\"DrawerMenu\"&gt;\r\n\u00a0\u00a0\u00a0 &lt;div class=\"inner\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideCategoryList%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideShopByBrand%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideCategoryShopByPrice%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideAdditionalInformation%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideAccountNavigation%%\r\n\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n%%Panel.DrawerMenuJavascript%%<\/pre>\n<p>After:<\/p>\n<pre>%%Panel.GoogleTagManagerTag%%\r\n&lt;div id=\"DrawerMenu\"&gt;\r\n\u00a0\u00a0\u00a0 &lt;div class=\"inner\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideCategoryList%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideShopByBrand%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideCategoryShopByPrice%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideAdditionalInformation%%\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 %%Panel.SideAccountNavigation%%\r\n\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n%%Panel.DrawerMenuJavascript%%<\/pre>\n<p>If you make it through all of the above then Google Tag Manager should be appearing on all of your pages.<\/p>\n<p>The next big hurdle is to accommodate Ecommerce Transaction reporting.<\/p>\n<blockquote><p>Note: The instructions below are for &#8216;standard&#8217; Ecommerce tracking.\u00a0 We&#8217;ll have to tackle Enhanced Ecommerce Reporting another day!<\/p><\/blockquote>\n<h2>Ecommerce Transaction Tracking<\/h2>\n<p>In short the existing &#8216;traditional format&#8217; GA Transaction code needs to be translated into the new &#8216;dataLayer&#8217; syntax for GTM.\u00a0 As Jeremy pointed out back on 07-23-2014 it would take some scripting to make this work.\u00a0 The script below will do the job.<\/p>\n<blockquote><p>Note: WordPress tends to mess with single &amp; double quote characters.\u00a0 A text-only copy of the script is available <a href=\"http:\/\/www.visualfuture.com\/gtm-4-bc\/googletagmanage-for-bigcommerce.txt\" target=\"_blank\">here<\/a>.<\/p><\/blockquote>\n<pre>&lt;script type=\"text\/javascript\"&gt;\r\nvar dataLayer = new Array();\r\n\/\/ console.log(dataLayer);\r\nfunction trackGTMEcommerce() {\r\n\u00a0\u00a0\u00a0 this._addTrans = addTrans;\r\n\u00a0\u00a0\u00a0 this._addItem = addItems;\r\n\u00a0\u00a0\u00a0 this._trackTrans = trackTrans;\r\n}\r\n\r\nvar transaction = {};\r\ntransaction.transactionProducts = [];\r\n\r\nfunction addTrans(orderID, store, total, tax, shipping, city, state, country) {\r\n\u00a0\u00a0\u00a0 transaction.transactionId = orderID;\r\n\u00a0\u00a0\u00a0 transaction.transactionAffiliation = store;\r\n\u00a0\u00a0\u00a0 transaction.transactionTotal = total;\r\n\u00a0\u00a0\u00a0 transaction.transactionTax = tax;\r\n\u00a0\u00a0\u00a0 transaction.transactionShipping = shipping;\r\n\u00a0\u00a0\u00a0 \/\/ console.log(11)\r\n}\r\n\r\n\r\nfunction addItems(orderID, sku, product, variation, price, quantity) {\r\n\u00a0\u00a0\u00a0 transaction.transactionProducts.push({\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'id': orderID,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'sku': sku,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'name': product,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'category': variation,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'price': price,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'quantity': quantity\r\n\u00a0\u00a0\u00a0 });\r\n\u00a0\u00a0\u00a0 \/\/ console.log('a')\r\n}\r\n\r\nfunction trackTrans() {\r\n\u00a0\u00a0\u00a0 transaction.event = 'bcTransactionComplete';\r\n\u00a0\u00a0\u00a0 \/\/ console.log(transaction);\r\n\u00a0\u00a0\u00a0 dataLayer.push(transaction);\r\n}\r\n\r\nvar pageTracker = new trackGTMEcommerce();\r\n&lt;\/script&gt;<\/pre>\n<p>For an easy setup:<\/p>\n<p>Go to Settings =&gt; Web Analytics and enable Google Analytics.<br \/>\nThen paste the script into the &#8216;Tracking Code&#8217; box for Google Analytics<\/p>\n<p>For a more precise setup:<\/p>\n<p>This script really only needs to appear on the \/finishorder.php page.<br \/>\nThus you could put it into the &lt;head&gt; section of just that page.<\/p>\n<p>Caveat: You will need to put something in the Google Analytics &#8216;Tracking Code&#8217; box under Settings =&gt; Web Analytics in order for the Ecommerce data to appear.<br \/>\nA comment works fine.<\/p>\n<p>IMPORTANT:<\/p>\n<p>You will need to trigger the GA Transaction tag in GTM using a custom event.<br \/>\nIn the example script above the event name is set on the line:<\/p>\n<pre>transaction.event = 'bcTransactionComplete';<\/pre>\n<p>You will need to configure GTM to fire the GA Transaction tag on the &#8216;bcTransactionComplete&#8217; event.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes, it IS possible to use Google Tag Manager to implement Google Analytics on a BigCommerce site. Before we dive in I want to thank one of my developers, Scott Rarden and also Anirudh from Google for their help. And a huge thanks to Jeremy &amp; the others on the GTM threads.\u00a0 I&#8217;m very new &hellip; <a href=\"https:\/\/www.visualfuture.com\/davetech\/2015\/06\/09\/google-tag-manager-for-bigcommerce\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Google Tag Manager for BigCommerce<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[1,13,9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/posts\/190"}],"collection":[{"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":6,"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/posts\/190\/revisions\/196"}],"wp:attachment":[{"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.visualfuture.com\/davetech\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}