Skip to content

Instantly share code, notes, and snippets.

@elephantsneverforget
Created May 24, 2023 17:36
Show Gist options
  • Save elephantsneverforget/a6bd6b36dbb8dc9c415ca7f8d433b2d6 to your computer and use it in GitHub Desktop.
Save elephantsneverforget/a6bd6b36dbb8dc9c415ca7f8d433b2d6 to your computer and use it in GitHub Desktop.
{ % if first_time_load % }
<script> window.dataLayer = window.dataLayer || [];
</ script><script> window.dataLayer.push({
'event' : 'dl_subscription_purchase',
"event_id" : '{{ order_name }}',
"user_properties" : {
"customer_id" : "{{ customer.shopify_customer_id }}",
"customer_email" : "{{ email }}",
"customer_first_name" : "{{ first_name }}",
"customer_phone" : "{{ shipping_address.phone }}",
"customer_last_name" : "{{ last_name }}",
"customer_city" : "{{ shipping_address.city }}",
"customer_zip" : "{{ shipping_address.zip }}",
"customer_address_1" : "{{ shipping_address.address1 }}",
"customer_address_2" : "{{ shipping_address.address2 }}",
"customer_country" : "{{ shipping_address.country }}",
"customer_province" : "{{ shipping_address.province }}"
},
'ecommerce' : {
'currencyCode' :'',
'purchase' : {
'actionField' : {
'id' : '{{ id }}',
'order_name' : '{{ order_name }}',
'affiliation' : 'ReCharge',
'revenue' : {{total_price}},
'discount_amount' : {{total_discounts}},
'tax' : {{total_tax}},
'shipping' : {{total_shipping}},
'sub_total' : {{subtotal_price}},
'coupon' : '{{ discount_code }}'
},
'products' : [
{ % for item in line_items % } {
'name' : '{{ item.name }}',
'product_id' : '{{ item.product_id }}',
'id' : '{{ item.sku }}',
'variant_id' : '{{ item.variant_id }}',
'price' : {{item.price}},
'brand' : '',
'category' : '',
'variant' : '{{ item.variant_title }}',
'quantity' : {{item.quantity}}
},
{ % endfor % }
]
}
}
});
</ script>{ % endif % }<!--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-1111111');
</script>
<!-- End Google Tag Manager -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment