Skip to content

Instantly share code, notes, and snippets.

@edmeehan-tcg
Last active January 5, 2018 01:46
Show Gist options
  • Save edmeehan-tcg/4dc4eda4ef05fec82fbd05de7b4f9e35 to your computer and use it in GitHub Desktop.
Save edmeehan-tcg/4dc4eda4ef05fec82fbd05de7b4f9e35 to your computer and use it in GitHub Desktop.
Marketing Data Layer
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
/*
* Transaction property should be hit scoped
* - fires one time per event and only for a single request
*/
transaction : {
vertical : 'phone|background|email',
type : 'acquisition|upsell|cross-sell',
is_trial : true|false,
// GA enhanced ecom - required properties
purchased: {
actionField : {
id : ${transaction_id},
affiliation : 'manual:BRAND',
revenue : ${transaction_value}
// tax : null, // dont use but just here for reference as an option
// shipping : null, // dont use but just here for reference as an option
// coupon : null // we dont use coupon codes so can skip this property
},
products : [
{
id : ${sku},
name : ${name},
category : 'phone|background|email',
brand : ${brand},
variant : ${items}, // array to string
quantity : ${qty},
price : ${value}
// coupon : null, // we dont use coupon codes so can skip this property
// position : null, // since a transaction only has one product we can skip this property
}
]
}
},
/*
* User property should be user scoped
* - fires on each request from user
*/
user : {
id : ${uid},
email : {
md5 : ${email_md5},
sha1 : ${email_sha1},
sha256 : ${email_sha256}
},
plans : [ // need some ideas on how to handle current products/plans by user
${sku}, // list of skus?? maybe.
${sku}
]
},
/*
* UTM campaign or referrer info
* - fires on each request in session, should sync GA and app session rules/timeout
*/
traffic : {
source : ${utm_source},
medium : ${utm_medium},
name : ${utm_campaign},
term : ${utm_term},
content : ${utm_content}
},
/*
* Site tracking - can use callables and app
* - fires on each request, some values are session and hit scoped
*/
site : {
name : ${content_grouping_name},
environment : 'dev|stage|prod',
// could use the site json to set these values
post_category : ${blog_post_category},
post_author : ${blog_post_author}
},
/*
* Split testing data
* - fires on each request with a running test
*/
optimization : [
{
id : ${split_test_id},
vid : ${split_test_variation_id}
},
{
id : ${split_test_id},
vid : ${split_test_variation_id}
}
],
catalog : {} // list of avalible skus to user and details - does not need to be in dataLayer but should be client side accessable.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment