Passing Customers’ Data to Google Analytics from Shopify
Hey, the world of analytics experts and enthusiasts!
We want to share with you a quick how-to guide on passing customer identifiers and customer type (new vs. repeat) into Google Analytics from Shopify using Google Tag Manager.
Note: the same logic could be used to track purchases by new vs. repeats customers within ad platforms – Facebook Ads, Google Ads, etc.
The business impact of the data collected:
1. Ability to measure/analyze customer LTV (by customer Id) and retention.
2. Viewability of what drives (channels, sources, campaigns, landing pages, etc.) new customer acquisition vs. repeat customers.
Passing Customers’ Data to Google Analytics from Shopify
- Add ‘Customer ID’ and ‘Customer Type’ custom dimensions in Google Analytics:
- Make sure you have installed GTM snippet in your Shopify account. You can use the following guide.
- Go to the ‘Settings’ -> ‘Checkout’ in Shopify:
Find ‘Additional scripts’ field under ‘Order processing’ section:
And add the following script to this field:
{% if first_time_accessed %}
{% if order_number %}
<script>
var customerType = {{customer.orders_count}};
customerType == 1 ? customerType = "new" : customerType = "repeat";
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'GTMevent',
'eventCategory' : 'purchase',
'eventAction' : 'complete',
'eventLabel' : '{{customer.id}} | ' + customerType,
'customerId': '{{customer.id}}',
'customerType': customerType
});
</script>
{% endif %}
{% endif %}
The code should look like:
Save the changes.
Add the following dataLayer variables in the GTM:
- Customer Type variable:
- Customer Id variable:
- Event Category variable (as we will be passing the data via event hit into GA):
- Event Action variable:
- Event Label variable:
- Add the custom event trigger to fire on the ‘purchase’ event:
- Add a Google Analytics Event tag to push the data into analytics:
Find ‘Additional scripts’ field under ‘Order processing’ section:
And add the following script to this field:
{% if first_time_accessed %}
{% if order_number %}
<script>
var customerType = {{customer.orders_count}};
customerType == 1 ? customerType = "new" : customerType = "repeat";
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'GTMevent',
'eventCategory' : 'purchase',
'eventAction' : 'complete',
'eventLabel' : '{{customer.id}} | ' + customerType,
'customerId': '{{customer.id}}',
'customerType': customerType
});
</script>
{% endif %}
{% endif %}
The code should look like:
Save the changes.
Add the following dataLayer variables in the GTM:
- Customer Type variable:
- Customer Id variable:
- Event Category variable (as we will be passing the data via event hit into GA):
- Event Action variable:
- Event Label variable:
That’s it! Publish the GTM container and start collecting your data in Google Analytics. If you need help with converting data from GA from Shopify, our team of experts can help you. Use the contact form below to discuss potential collaboration opportunities.
Get in touch
Got a question? We'd love to hear from you. Send us a message and we'll respond as soon as possible.
By clicking submit, you agree to our Privacy Policy
Latest Insights
Get the tips from our experts to optimize and scale your campaigns