AnalyticsAgency will set GTM to trigger on one of these three rules:

image092

  1. {{dataLayer.google_tag_params.
    ecomm_pagetype}}=purchase
  2. {{Event}}=transaction
  3. {{url path}}=/checkout/onepage/success

 

Do not remove the existing GA ecommerce code yet:

<script type=”text/javascript”>

// Existing GA ecommerce code on /checkout/thankyou.htm

var _gaq = _gaq || [];

_gaq.push([‘_setDomainName’,’clientdomain.com’],[‘_setAccount’,’UA-00000-2′]);

_gaq.push([‘_addTrans’,

‘T000012345’,    // Order_ID

‘Aff123’,        // Affiliation

‘130.00’,                 // Revenue – Inc VAT and Shipping

‘20.00’,         // Vat Tax @ 20%

‘10.00’,         // Shipping – Inc VAT

”,”,”         // Depreciated Region, City & Country

]);

_gaq.push([‘_addItem’,

‘T000012345’,    // Order_ID

‘BS123’,         // ProductSKU or ProductID – required

‘Blue Shoes’,    // ProductName – Pls escaped quotes & commas

‘Shoes’,         // prod_category – Pls escaped quotes & commas

‘120.00’,                 // Price Inc VAT @ 20%

‘1’

]);

_gaq.push([‘_trackTrans’]); // submit transaction

</script>

 

On the sale complete pages /checkout/onepage/success insert the following dataLayer

making sure that the variables displayed in <bold> are changed appropriately.

 

<!– Google Tag Manager dataLayer for Sale page only –>

<script>

window.dataLayer = window.dataLayer || [];

dataLayer.push({

// Global settings

“version”            : “1.0”, // W3C digital dataLayer version

“environmentIdentifier”           : “dev“, // dev, staging or live

“pageBrandName”                  : “big brand”, // If using multiple brands in rollup then use this field

“pageLanguage”                    : “en”, // locale-code for page language e.g. en

“pageCountry”                     : “us”, // Use 2character ISO Country list e.g. us

“pageGeoRegion”                   : “new york”, // Only needed for large localised websites

 

// Page values

“pageVirtual”                     : “”, // e.g. “/virtual” + location.pathname + location.search

“pageAttributesSysEnv”            : “desktop”, // Responsive CSS = desktop | tablet | mobile.

“pageHttpResponseCode”            : “<?php http_response_code(); ?>”, // e.g 200 or 404 or 500

“page.id”            : “1234”,

“pageSiteSearchResults”           : “”, // 0 means 0 results returned

//”pageGroup1_manualClassification”: “”, // reserved slot for manual names

“pageGroup2_category” : “”, // pageCategory

“pageGroup3_subCategory”          : “”, // pageSubcategory, pagePostType or paymentStep

“pageGroup4_templateName”         : “”, // pageTemplateName, pageBreadcrumb or pagePostAuthor

//”pageGroup5_containerVersion”     : “”, // reserved slot for {{autoContainerVersion}}

“pageContentCreated” : “”, // 2013-01-01 server-side variable

“pageContentModified” : “”, // 2013-01-01 server-side variable

“pageForumPosts”                  : “”, // e.g. 25

 

// Visitors preference and Safari view mode

“user_authIsUserIdToSessionIdOverrideEnabled”: “false”, // true|false is set on Login or Register complete page. userIDoveride MUST default to false. Only change if consent gained or DNT=0

“session_xPreview”: “<?php if ($_SERVER[‘HTTP_X_PURPOSE’] == ‘preview’ {‘preview’} else {”} ?>”, // Safari loading page in preview mode

 

 

 

// Ecommerce payment page variables

“ecommerce”: {

“currencyCode”                    : “USD”, // LOCAL currency profile

“purchase”: { // promo_click > detail > add | remove > checkout | checkout_option >>> purchase | refund

“actionField”: {

“step”                      : “6”, // 1-6

“option”                    : “complete”, // checkout > login > delivery > billing > payments > complete

“id”                        : “T000012345”,

“affiliation”  : “AFF123”, // optional

“revenue”                   : “250.00”, // 120*1quantity + 120*1quantity + 10shipping

“tax”                       : “75.00”, // 250 * (1-(100%/120%))

“shipping”                  : “10.00”, // Includes Tax: 8.33 + tax = 10.00

“shippingMethod”            : “UPS Ground”, // optional

“date”                      : “2014-01-01”, // optional

“coupon”                    : “VOUCHER1234”, // optional – aka transactionPromoCode or transactionVoucher

“couponDiscount”            : “0.00”, // optional how much reduced by, not percentage

“paymentType”  : “Direct Debit”, // optional – can also be used for CreditCard, Paypal, etc

“type”                      : “Monthly Subscription”, // optional

“subTotalIncludeTax”        : “true” // Indicates whether TransactionTotal includes tax

},

“products”: [{

“id”             : “BS-123”, // sku

“name”           : “BLUE Shoes”,

“category”       : “Shoes”,

“brand”          : “Nike”,

“variant”        : “Blue”,

“coupon”         : “SHOESALE”,

“price”          : “120.00”, // Includes Tax: 100+tax = 120.00

“quantity”       : “1”

},{

“id”             : “RS-123”, // sku

“name”           : “RED Shoes”,

“category”       : “Shoes”,

“brand”          : “Nike”,

“variant”        : “Red”,

“coupon”         : “SHOESALE”,

“price”          : “120.00”, // Includes Tax: 100+tax = 120.00

“quantity”       : “1”

}],

}

},

 

// CustomDimensions persistence can be userScope=6months, sessionScope=30mins or hitScope=pageScope

“user.id”            : “12345”, // cd001: userScope -auth.user.getId

“cart.id”            : dataLayer.ecommerce.checkout.actionField.id, // cd014: sessionScope

//,”containerVersion” : “”, // cd005: reserved slot for userScope {{containerVersion}}

 

// CustomMetrics type can be integerType, currencyType (decimals), timeType

“cart.total”: dataLayer.ecommerce.checkout.actionField.revenue, // cm002: currencyType – ecomm_totalvalue

“visitorLifetimeValue”: “250.00”, // cm001: currencyType – Includes Tax: ($100*2+$10)+tax = $250.00

“firstPurchaseDate”: new Date(“January 01 2014 23:59:59”), // cd007: userScope customer lifetime

 

// Adwords Dynamic Remarketing dimensions for product image IDs

// support.google.com/adwords/answer/2476691?hl=en & support.google.com/adwords/answer/3103357?hl=en

// & support.google.com/tagmanager/answer/3002580?hl=en

“google_tag_params”: {

“ecomm_pagetype”: “purchase”, // cd015:home|category|product|cart|purchase|other {{page.category.pageType}}

“ecomm_paymentstep”: dataLayer.ecommerce.purchase.actionField.option,//cd016: checkout > login > delivery > billing > payments > complete

“ecomm_prodid”                    : [“”], // cd017: e.g. [“sku_111″,”sku_222”] {{ecommerce.products[n].id}}

“ecomm_totalvalue”         : dataLayer.ecommerce.purchase.actionField.revenue, // cm002: £100

“ecomm_pname”                     : [“”], // cd018: optional {{ecommerce.products[n].name}}

“ecomm_pcat”                      : [“”], // cd019: optional {{ecommerce.products[n].category}}

“ecomm_rec_prodid”         : [“”], // cd020: e.g. shoe shine {{ecommerce.recommendation[n].id}}

// Auth logged-in variables

//”user.id”                : “”, // cd001:WARNING never use userId, cartId or sessionId for remarketing

“user_isRegistered”        : “true”, // cd002: y|n users has an account?

“user_isLoggedIn”          : “true”, // cd003: y|n users is signed-in?

“user_isReturnCustomer”           : “true”, // cd004: y|n users has transacted already?

“user_memberType”          : “free member”, // cd006: Free Member, Premium Member or Enterprise Member

“user_memberTypeClass”            : “international member”, // cd007: sub-types of memberClass

“user_ageRange”                   : “20-25”, // cd008: Age range

“user_gender”                     : “male”, // cd009: Gender

“user_customerQualityScore”       : “high”, // cd010: Customer Quality Score – High, Med, Low

“user_highSpenderScore”           : “high”, // cd011: High Spender Score – High, Med, Low

“user_loyaltyScore”        : “high”, // cd012: Loyalty Score – High, Med, Low

“session_testVariant”             : “version a – offer x” // cd013: combine A/B testing offer with remarketing

//, “session_type”         : “returning”,//cd000: new|returning 30min session native GA field UserType },

 

// Trigger transaction submission to GA via GTM

“event”                           : “header_datalayer_loaded”, // Used to trigger dataLayer dependencies

“event”                          : “transaction”

});

</script>

<!– End Google Tag Manager Data Layer –>

</HEAD>

 

 

<BODY>

<!– Google Tag Manager –>

<noscript><iframe src=”//www.googletagmanager.com/ns.html?id=GTM-xxxx” height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>

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

‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);

})(window,document,’script’,’dataLayer’,’GTM-xxxx’);

</script>

<!– VERSION: GTM_October_v1 –>

<!– WEBSITE: clientdomain.com –>

<!– CATEGORY: ecommerce –>

<!– MARKET: UK –>

<!– GTM-LIVE:UA-00000-1 | GTM-DEV:UA-00000-2 :: rolledupTracker     –>

<!– GTM-LIVE:UA-111111-1 | GTM-DEV:UA-111111-2 :: localCountryTracker –>

<!– Replace GTM-xxxx with GTM-LIVE for live, or GTM-DEV for dev –>

<!– End Google Tag Manager –>

 

***

IMPORTANT: Do not use commas in number (e.g. 1,000 change to 1000)

***

“transactionTotal”: “1,000.00″, // comma error

Should be:

“transactionTotal”: “1000.00″,
Note1: Do NOT use null for empty text values

“transactionAffiliation”: null, // value error
Instead use undefined instead:
“transactionAffiliation”: undefined,

 

Note2: For empty numbers, ensure these are in Quotation marks to avoid a JS error:

“transactionTotal”: , // JS error

These are fine:

“transactionTotal”: undefined,

 

Note3: Both these methods are valid for numbers, but due to JS errrors with null numbers – it is safer to standardise use quotation marks on populated number values e.g. “100.00”:

“transactionTotal”: 100.00,
“transactionTotal”: “100.00“, // safer, but not JSON compliant

 

Tip: JS trick – you can convert a string to number by simply subtracting 0 e.g:

var myNum = dataLayer.transactionTotal – 0;

 

Help page:

0117 3361103