Announcement

Collapse
No announcement yet.

Migrating to Google Tag Manager for all Tracking

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

    Migrating to Google Tag Manager for all Tracking

    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:

    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 -->
    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?

    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 -->
    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
    Nick Harkins
    www.loveisarose.com

    #2
    We are looking to do this as well. Are there any instructions anywhere?

    Comment


      #3
      Do you already have a google tag manager account/container?
      Nick Harkins
      www.loveisarose.com

      Comment


        #4
        The client just created the tag manager account. But actually the client changed their mind. Instead of using the tag manager, we are to add Facebook tracking 'add to cart' events. Now I am trying to figure that code out. Code I found on another forum post isn't working unfortunately.

        Comment


          #5
          Okay. When I have the time I will create a new how to thread to help anyone out in the future. I'll add the link here when I post it.
          Nick Harkins
          www.loveisarose.com

          Comment


            #6
            I was able to get the Facebook tracking code working. I didn't realize we need to use mvtj instead of mvt since this is javascript:

            This is for product pages:
            Code:
            <script>
              fbq('track', 'ViewContent', {
                value: 0.00,
                currency: 'USD',
                content_ids: '&mvtj:product:code;',
                content_type: 'product',
              });
            </script>
            This is for the basket page:
            Code:
            <!--fb pixel-->
            <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>
            <script>
              fbq('track', 'AddToCart', {
                value: 0.00,
                currency: 'USD',
                content_ids: '&mvtj:content_ids;',
                content_type: 'product',
              });
            </script>
            <!--end-->
            It does seem like going forward it would be a lot simpler to use Google Tag Manager.

            Comment


              #7
              Originally posted by afiumano View Post
              I was able to get the Facebook tracking code working. I didn't realize we need to use mvtj instead of mvt since this is javascript:

              This is for product pages:
              Code:
              <script>
              fbq('track', 'ViewContent', {
              value: 0.00,
              currency: 'USD',
              content_ids: '&mvtj:product:code;',
              content_type: 'product',
              });
              </script>
              This is for the basket page:
              Code:
              <!--fb pixel-->
              <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>
              <script>
              fbq('track', 'AddToCart', {
              value: 0.00,
              currency: 'USD',
              content_ids: '&mvtj:content_ids;',
              content_type: 'product',
              });
              </script>
              <!--end-->
              It does seem like going forward it would be a lot simpler to use Google Tag Manager.
              Point of clarification - this code is for the Facebook tracking code and NOT the Google Tag Manager? Since the GTM is the way Google is going it would make seen for Miva to move towards it too.
              Leslie Kirk
              Miva Certified Developer
              Miva Merchant Specialist since 1997
              Previously of Webs Your Way
              (aka Leslie Nord leslienord)

              Email me: [email protected]
              www.lesliekirk.com

              Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

              Comment


                #8
                Originally posted by SidFeyDesigns View Post
                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:

                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 -->
                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?

                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 -->
                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
                Nick, did you ever get an answer as to if the code you provided can indeed replace the current GA Tracking code item?
                Leslie Kirk
                Miva Certified Developer
                Miva Merchant Specialist since 1997
                Previously of Webs Your Way
                (aka Leslie Nord leslienord)

                Email me: [email protected]
                www.lesliekirk.com

                Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

                Comment


                  #9
                  I didn't get an answer from miva but I did get it working with a little help from the PPC company we work with.

                  I decided to leave the built in code for google analytics so I could easily revert back if I needed to.

                  Instead I removed this item <mvt:item name="ga_tracking" /> which happened to be in the global head tag for me. Could also be in the global footer.

                  Then I removed this item <mvt:item name="ga_transaction" /> from the INVC page.

                  Here is the code I currently have in our global head tag. It includes the Google Tag Manager Code and the Data Layer.

                  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-YOURIDX');</script>
                  <!-- End Google Tag Manager -->
                  <!-- Google Tag Manager - Data Layer -->
                  <script>
                      var dataLayer = dataLayer || [];
                      <mvt:comment><!-- Checkout Step Assignment --></mvt:comment>
                      <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 'OCST'">
                          <mvt:assign name="l.settings:datalayer:checkout_step" value="2"/>
                      <mvt:elseif expr="l.settings:page:code EQ 'OSEL'">
                          <mvt:assign name="l.settings:datalayer:checkout_step" value="3"/>
                      <mvt:elseif expr="l.settings:page:code EQ 'OPAY'">
                          <mvt:assign name="l.settings:datalayer:checkout_step" value="4"/>
                      <mvt:elseif expr="l.settings:page:code EQ 'INVC'">
                          <mvt:assign name="l.settings:datalayer:checkout_step" value="5"/>
                      </mvt:if>
                  
                      dataLayer.push({
                          <mvt:if expr="g.Screen EQ 'INVC'">
                              'requestUri': '\/INVC.html',
                          <mvt:else>
                              'requestUri': '<mvt:eval expr="encodejavascriptstring( s.request_uri )" />',
                          </mvt:if>
                          'refererUri': '<mvt:eval expr="encodejavascriptstring( s.http_referer )" />',
                          'pageCode': '&mvtj:page:code;',
                          'categoryCode': '&mvtj:category:code;',
                          'productCode': '&mvtj:product:code;',
                          'checkoutStep': '&mvtj:datalayer:checkout_step;'
                      });
                      <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({
                              'event': 'checkout',
                              'ecommerce': {
                                  'checkout': {
                                      'actionField': {
                                          'step': '5'
                                      },
                                      '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;',
                                              'quantity': '&mvtj:item:quantity;'
                                          }
                                      </mvt:foreach>
                                      ]
                                  }
                              },
                          });
                  
                          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;',
                                          'quantity': '&mvtj:item:quantity;'
                                      }
                                  </mvt:foreach>
                                  ]
                              }
                          },
                          'order_id': '&mvtj:order:id;',
                          <mvt:item name="toolkit" param="subtotalorder|ordersubtotal" />
                          <mvt:item name="toolkit" param="orderother|ocount|order:id" />
                          <mvt:item name="toolkit" param="math_add|X_subtotal|g.orderother|g.ordersubtotal" />
                          'order_subtotal': '&mvtj:global:X_subtotal;',
                          'order_total': '&mvtj:order:total;',
                          'content_type': 'product',
                          'content_name': '&mvtj:item:name;',
                          'content_ids': '&mvtj:content_ids;',
                          'quantity': '&mvtj:item:quantity;',
                          'value': '&mvtj:order:total;',
                          'currency': 'USD'
                      });
                      dataLayer.push({
                         'transactionId': '&mvtj:order:id;',
                         'transactionAffiliation': 'Love Is A Rose',
                         'transactionTotal': '&mvtj:order:total;',
                         'transactionTax': '&mvtj:gtm:tax;',
                         'transactionShipping': '&mvtj:gtm:tax;',
                         'transactionProducts': [
                          <mvt:foreach iterator="item" array="order:groups">
                              {
                                  'sku': '&mvtj:item:code;',
                                  'name': '&mvtj:item:name;',
                                  'price': '&mvtj:item:price;',
                                  'quantity': '&mvtj:item:quantity;'
                              },
                          </mvt:foreach>
                             ]
                      });
                      <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': '&mvtj:datalayer:checkout_step;'
                                      },
                                      'products': [
                                          <mvt:foreach iterator="item" array="global_minibasket:items">
                                              {
                                                  'name': '&mvtj:item:name;',
                                                  'id': '&mvtj:item:code;',
                                                  'price': "&mvtj:item:price;",
                                                  'quantity': '&mvtj:item:quantity;'
                                              },
                                          </mvt:foreach>
                                      ]
                                  }
                              },
                              'content_type': 'product',
                              'content_ids': '&mvtj:content_ids;',
                              'value': '&mvtj:basket:total;',
                              'currency': 'USD'
                          });
                      </mvt:if>
                  </script>
                  <!-- End Google Tag Manager - Data Layer -->
                  Once that is all set up you'll need to add any conversion tracking tags, third party affiliate tracking pixel tags, etc. in Google Tag Manager.

                  Setting up the google conversions tracking was a little tricky since the INVC page URL ends up being www.mydomain.com/mm5/merchant.mvc?

                  To combat that in GTM set the trigger for the INVC page and make sure the trigger type is Page View - Window Loaded with the Trigger Fires on setting set to Some Window Loaded Events.

                  You of course will also need to have Data Layer Variables set up within GTM that match the data layer above after you add it to the global head tag.

                  This makes it possible to pass that data to Google Analytics.

                  Ex: 'pageCode': '&mvtj:page:code;' needs to have a variable with the name pageCode in GTM so you can reference it.

                  That's how we were able to make the conversion tracking work properly. We now had the ability to tell GTM that the page code INVC was indeed our invoice screen and a successful transaction was made.

                  It's a totally different animal than the traditional tracking methods and is a little harder to learn, but once it is set up it is very nice to have all tracking, google ads tracking, affiliate pixels, etc. in one place.

                  If you have any more specific questions or hit any hurdles, let me know and I can do my best to help.

                  Hope this is helpful.

                  Good luck!
                  Nick Harkins
                  www.loveisarose.com

                  Comment


                    #10
                    Oh and you should also add the No Script GTM code at the beginning of your global header.

                    Code:
                    <!-- Google Tag Manager (noscript) -->
                    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-YOURIDX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
                    <!-- End Google Tag Manager (noscript) -->
                    Nick Harkins
                    www.loveisarose.com

                    Comment


                      #11
                      I don’t want to use the tag manager, since there is so much to set up and it seems to be working except formour checkout funnel.

                      any ideas on how to get Miva to have the url,of the invoice be invoice.html? This tokenlist shows it so I don’t get why it isn’t being detected in analytics.. I can only guess that is because it isn’t the actual url in the browser.

                      Comment


                        #12
                        SidFeyDesigns, we would like to implement this in our store, would your code work in M10 (Levels ReadyThemes)?

                        Would I need to replace current Google Analytics, or can I also use both as you mentioned?

                        Any additional implementation tips you can share to make things easier?

                        Finally, would you know if this is already included in the latest Shadows ReadyTheme?
                        Thank you, Bill Davis

                        Comment


                          #13
                          SidFeyDesigns I forgot to mention, if the following is a good idea could it be easily incorporated to your snippet? If so, how?


                          Article: How to dynamically filter traffic from employees in Google Analytics (with dynamic IP address)
                          Thank you, Bill Davis

                          Comment


                            #14
                            Hi William Davis I have updated the code we use quite a bit to be more efficient and I have added Google Analytics 4 to start collecting a history of data in case it becomes the new analytics standard, so later today or tomorrow I can share it here.

                            There are also a few good Google Tag Manager tutorials I used to help learn how to set everything up properly within the GTM workspace. I'll see if I can find those links and share them as well.

                            You will definitely want to get everything set up within GTM first before changing anything within Miva.

                            You would not use both at the same time. This would technically replace the current GA implementation but it would only remove <mvt:item name="ga_tracking" /> from the global head tag or footer depending on where your <mvt:item name="ga_tracking" /> is placed on the site. You would also remove the <mvt:item name="ga_transaction" /> from the INVC page.

                            This allows you to retain the current code in the Google Analytics tab within the Utilities menu in the Miva admin just incase you need to revert back and put the items mentioned above back where you removed them from.

                            I would recommend keeping the above items where they are at first though and wrap the new code within <mvt:comment></mvt:comment> tags until you think you have it fully ready and you are ready to test.

                            That way you can remove the <mvt:comment> tags and <mvt:item name="ga_tracking" /> at the same time and easily revert back.

                            GTM has a preview mode you can use to help make sure the tags are firing properly. You can also use the Google Tag Assistant browser extension.

                            You'll want to make sure these tags are firing properly so your data is getting tracked properly.

                            I do have a few quick questions though.

                            Which version of GA are you using? Universal (analytics.js), Universal Enhanced Ecommerce (analytics.js), or Classic (ga.js)?

                            Are you tracking the conversions?

                            Are you tracking the checkout flow? (in GA it is here: Conversions > Ecommerce > Checkout Behavior)

                            Having a list of everything being tracked within GA would be helpful.

                            I don't believe any of this code is within the latest Shadows ReadyTheme but I can't confirm because I do not work for Miva and we currently use a heavily modified version of the Suivant ReadyTheme

                            I'm not entirely sure how you would dynamically filter internal traffic within the code although I bet it would be possible.

                            I just used https://whatismyipaddress.com/ on each computer in the office and added a filter within the GA admin for each ip address that excludes tracking their traffic. I also added the Google Analytics Opt-out Add-on (by Google) extension to the browsers. We have a small office so this was easily done.
                            Last edited by SidFeyDesigns; 06-15-21, 07:36 AM.
                            Nick Harkins
                            www.loveisarose.com

                            Comment


                              #15
                              SidFeyDesigns, thanks for your reply.
                              1. Q. Which version of GA are you using? Universal (analytics.js), Universal Enhanced Ecommerce (analytics.js), or Classic (ga.js)? A. Universal
                              2. Q. Are you tracking the conversions? A. Yes.
                              3. Q. Are you tracking the checkout flow? (in GA it is here: Conversions > Ecommerce > Checkout Behavior) A. No, thought we did, I would like to fix that.
                              Would like to significantly improve our analytics data capturing.

                              Would like capture page type analytics, Home, Category and Product pages, also all categories.
                              Thank you, Bill Davis

                              Comment

                              Working...
                              X