Hi,
I am starting this thread as sort of a feeler for what it might take to migrate all of our site's tracking to Google Tag Manager.
I like the idea of having all tracking code in one place and only having one piece of code on our site to fire the desired tracking.
The following are the current tracking that is on our site and I'd be interested in migrating it all to Google Tag Manager.
-Google Analytics (Universal Analytics Enhanced Eccomerce)
-Google Ads (gtag code provided by Logical Position (Google Ads Management Company)
-Google Remarketing
-Bing Ads
-SharASale Affiliate tracking
-UpSalo Affiliate Tracking
I am currently working on setting up the ShareASale tracking and custom pixel in GTM as sort of a test to see whats possible and I am almost there but need to figure out how to include the variables (transactionId and transactionSubtotal) they need in our data layer so they are read properly in GTM and affiliate transactions are recorded properly.
I also stumbled upon this Github provided by Steve Osoule that is specific to Miva that may be the key in these variables being set properly in our data layer. Which in turn, can probably be used to pass any of the transaction or pageview information to GTM for any of the above tracking we'd like to migrate to GTM.
The Github is here:
https://gist.github.com/steveosoule/74f326de0f0c473f007e/revisions
I went ahead and compiled all the revisions into one set of full and current code
Here it is:
My question is this.
Can I replace the built in google analytics tracking code with the code above? (tailored to suit our specific needs of course)
Then follow the above code with the Google Tag Manager code?
Or do I need to take a different approach and put all of that code in the Head Tag Content and remove the built in GA Tracking Item (<mvt:item name="ga_tracking" />)?
Thanks in advance for any help or useful information shed on this topic,
Nick Harkins
I am starting this thread as sort of a feeler for what it might take to migrate all of our site's tracking to Google Tag Manager.
I like the idea of having all tracking code in one place and only having one piece of code on our site to fire the desired tracking.
The following are the current tracking that is on our site and I'd be interested in migrating it all to Google Tag Manager.
-Google Analytics (Universal Analytics Enhanced Eccomerce)
-Google Ads (gtag code provided by Logical Position (Google Ads Management Company)
-Google Remarketing
-Bing Ads
-SharASale Affiliate tracking
-UpSalo Affiliate Tracking
I am currently working on setting up the ShareASale tracking and custom pixel in GTM as sort of a test to see whats possible and I am almost there but need to figure out how to include the variables (transactionId and transactionSubtotal) they need in our data layer so they are read properly in GTM and affiliate transactions are recorded properly.
I also stumbled upon this Github provided by Steve Osoule that is specific to Miva that may be the key in these variables being set properly in our data layer. Which in turn, can probably be used to pass any of the transaction or pageview information to GTM for any of the above tracking we'd like to migrate to GTM.
The Github is here:
https://gist.github.com/steveosoule/74f326de0f0c473f007e/revisions
I went ahead and compiled all the revisions into one set of full and current code
Here it is:
Code:
<!-- Google Tag Manager - Data Layer --> <script> var dataLayer = dataLayer || []; <mvt:comment><!-- Page Type Assignment --></mvt:comment> <mvt:if expr="l.settings:page:code EQ 'SFNT'"> <mvt:assign name="l.settings:dataLayer:pageType" value="'home'" /> <mvt:elseif expr="l.settings:page:code EQ 'SRCH' OR l.settings:page:code EQ 'SEARCH'"> <mvt:assign name="l.settings:dataLayer:pageType" value="'searchresults'" /> <mvt:elseif expr="l.settings:page:code EQ 'CTGY'"> <mvt:assign name="l.settings:dataLayer:pageType" value="'category'" /> <mvt:elseif expr="l.settings:page:code EQ 'PROD'"> <mvt:assign name="l.settings:dataLayer:pageType" value="'product'" /> <mvt:elseif expr="l.settings:page:code CIN 'BASK,ORDL,OCST,OUS1,OUSM,OSEL,OPAY'"> <mvt:assign name="l.settings:dataLayer:pageType" value="'cart'" /> <mvt:elseif expr="l.settings:page:code EQ 'INVC'"> <mvt:assign name="l.settings:dataLayer:pageType" value="'purchase'" /> <mvt:else> <mvt:assign name="l.settings:dataLayer:pageType" value="'other'" /> </mvt:if> <mvt:if expr="l.settings:page:code EQ 'BASK'"> <mvt:assign name="l.settings:datalayer:checkout_step" value="1"/> <mvt:elseif expr="l.settings:page:code EQ 'ORDL'"> <mvt:assign name="l.settings:datalayer:checkout_step" value="2"/> <mvt:elseif expr="l.settings:page:code EQ 'OCST'"> <mvt:assign name="l.settings:datalayer:checkout_step" value="3"/> <mvt:elseif expr="g.Screen EQ 'OUSL'"> <mvt:assign name="l.settings:datalayer:checkout_step" value="4"/> <mvt:elseif expr="l.settings:page:code EQ 'OSEL'"> <mvt:assign name="l.settings:datalayer:checkout_step" value="5"/> <mvt:elseif expr="l.settings:page:code EQ 'OPAY'"> <mvt:assign name="l.settings:datalayer:checkout_step" value="6"/> </mvt:if> <mvt:if expr="g.customer:bill_email"> <mvt:assign name="l.settings:datalayer:userEmail" value="g.customer:bill_email" /> <mvt:elseif expr="g.basket:bill_email"> <mvt:assign name="l.settings:datalayer:userEmail" value="g.basket:bill_email" /> <mvt:else> <mvt:assign name="l.settings:datalayer:userEmail" value="''" /> </mvt:if> dataLayer.push({ <mvt:if expr="g.Screen EQ 'NTFD'"> "canonicalUri": "<mvt:eval expr="encodejavascriptstring( s.request_uri )" />", "event": "NTFD", <mvt:elseif expr="g.Screen EQ 'SRCH'"> "canonicalUri": "<mvt:eval expr="encodejavascriptstring( s.request_uri )" />", "searchTerm": "&mvtj:global:Search;", "event": "SRCH", <mvt:else> "canonicalUri": "&mvtj:ga_tracking:url_override_unencoded;", </mvt:if> "requestUri": "<mvt:eval expr="encodejavascriptstring( s.request_uri )" />", "refererUri": "<mvt:eval expr="encodejavascriptstring( s.http_referer )" />", "pageCode": "&mvtj:page:code;", "pageType": "&mvtj:datalayer:pageType;", "pageName": "&mvtj:datalayer:pageName;", "userId": "&mvtj:global:basket:cust_id;", "userEmail": "&mvtj:datalayer:userEmail;", "basketId": "&mvtj:global:basket:basket_id;", "categoryCode": "&mvtj:global:Category_Code;", "categoryName": "&mvtj:datalayer:categoryName;", "productCode": "&mvtj:product:code;", "checkoutStep": "&mvtj:datalayer:checkout_step;" }); <mvt:if expr="l.settings:page:code EQ 'PROD'"> dataLayer.push({ "ecommerce": { "detail": { "products": [{ "name": "&mvtj:product:name;", "id": "&mvtj:product:code;", "price": "&mvtj:product:price;", "sku": "&mvtj:item:sku;", "category": "", "variant": "" }] } }, "content_type": "product", "content_ids": '&mvtj:product:code;', "value": &mvt:product:price;, "currency": "USD" }); </mvt:if> <mvt:if expr="l.settings:page:code EQ 'INVC'"> <mvt:foreach iterator="charge" array="order:charges"> <mvt:if expr="l.settings:charge:type EQ 'TAX'"> <mvt:assign name="l.settings:gtm:tax" value="l.settings:charge:disp_amt" /> <mvt:elseif expr="l.settings:charge:type EQ 'SHIPPING'"> <mvt:assign name="l.settings:gtm:shipping" value="l.settings:charge:disp_amt" /> </mvt:if> </mvt:foreach> <mvt:if expr="miva_array_elements(l.settings:order:items) GT 1"> <mvt:assign name="l.settings:content_ids" value="'['" /> </mvt:if> <mvt:foreach iterator="item" array="order:items"> <mvt:if expr="POS1 GT 1"> <mvt:assign name="l.settings:content_ids" value="l.settings:content_ids $ ',' $ asciichar(39) $ encodejavascriptstring( l.settings:item:code ) $ asciichar(39)" /> <mvt:else> <mvt:assign name="l.settings:content_ids" value="l.settings:content_ids $ asciichar(39) $ encodejavascriptstring( l.settings:item:code ) $ asciichar(39)" /> </mvt:if> </mvt:foreach> <mvt:if expr="miva_array_elements(l.settings:order:items) GT 1"> <mvt:assign name="l.settings:content_ids" value="l.settings:content_ids $ ']'" /> </mvt:if> dataLayer.push({ 'ecommerce': { 'purchase': { 'actionField': { 'id': '&mvtj:order:id;', 'revenue': '&mvtj:order:total;', 'tax': '&mvtj:gtm:tax;', 'shipping': '&mvtj:gtm:shipping;' }, 'products': [ <mvt:foreach iterator="item" array="order:groups"> <mvt:if expr="POS1 GT 1">,</mvt:if> { 'name': '&mvtj:item:name;', 'id': '&mvtj:item:code;', 'price': '&mvtj:item:price;', <mvt:if expr="miva_array_elements(l.settings:item:options) GT 0"> <mvt:assign name="l.settings:item:gtm_variant" value="''" /> <mvt:foreach iterator="option" array="item:options"> <mvt:if expr="POS2 GT 1"> <mvt:assign name="l.settings:item:gtm_variant" value="l.settings:item:gtm_variant $ ' ' " /> </mvt:if> <mvt:assign name="l.settings:item:gtm_variant" value="l.settings:item:gtm_variant $ l.settings:option:opt_code" /> </mvt:foreach> <mvt:if expr="l.settings:item:gtm_variant"> 'variant': '&mvtj:item:gtm_variant;', </mvt:if> </mvt:if> 'quantity': &mvtj:item:quantity; } </mvt:foreach> ] } }, "order_id": '&mvt:order:id;', "order_total": '&mvt:order:total;', "content_type": "product", "content_ids": &mvt:content_ids;, "value": &mvt:order:total;, "currency": "USD" }); <mvt:elseif expr="l.settings:datalayer:checkout_step"> <mvt:if expr="miva_array_elements(l.settings:basket:items) GT 1"> <mvt:assign name="l.settings:content_ids" value="'['" /> </mvt:if> <mvt:foreach iterator="item" array="basket:items"> <mvt:if expr="POS1 GT 1"> <mvt:assign name="l.settings:content_ids" value="l.settings:content_ids $ ',' $ asciichar(39) $ encodejavascriptstring( l.settings:item:code ) $ asciichar(39)" /> <mvt:else> <mvt:assign name="l.settings:content_ids" value="l.settings:content_ids $ asciichar(39) $ encodejavascriptstring( l.settings:item:code ) $ asciichar(39)" /> </mvt:if> </mvt:foreach> <mvt:if expr="miva_array_elements(l.settings:basket:items) GT 1"> <mvt:assign name="l.settings:content_ids" value="l.settings:content_ids $ ']'" /> </mvt:if> dataLayer.push({ "event": "checkout", "ecommerce": { "checkout": { "actionField": { "step": &mvt:datalayer:checkout_step; }, "products": [ <mvt:foreach iterator="item" array="global_minibasket:items"> { "name": "&mvtj:item:name;", "id": "&mvte:item:product:code;", "price": "&mvte:item:price;", "sku": "&mvte:item:code;", "category": "", "variant": "", "quantity": &mvte:item:quantity; }, </mvt:foreach> ] } }, "content_type": "product", "content_ids": &mvt:content_ids;, "value": &mvt:basket:total;, "currency": "USD" }); </mvt:if> </script> <!-- End Google Tag Manager - Data Layer -->
Can I replace the built in google analytics tracking code with the code above? (tailored to suit our specific needs of course)
Then follow the above code with the Google Tag Manager code?
Code:
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-XXXXXXX');</script> <!-- End Google Tag Manager -->
Thanks in advance for any help or useful information shed on this topic,
Nick Harkins
Comment