Passing Customers’ Data to Google Analytics from Shopify

20 July 2020

Author Image
Alex is a senior analytics expert @Viden, delivering value for brands through vast technical proficiency in data science. With years of experience in the field, he specializes in providing efficient analytics solutions to nuanced data collection and reporting challenges.

Hey, world of analytics experts and enthusiasts!
We want to share with you a quick ‘how to’ guide on passing customer identifier 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.
Business impact of this data being collected:
1. Ability to measure/analyze customer LTV (by customer Id) and retention.
2. Viewability into what drives (channels, sources, campaigns, landing pages, etc.) new customer acquisition vs. repeat customers.
Step 1: Add ‘Customer ID’ and ‘Customer Type’ custom dimensions in Google Analytics:

Step 2: Make sure you have installed GTM snippet in your Shopify account. You can use the following guide.
Step 3: 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 %}
         var customerType = {{customer.orders_count}};
         customerType == 1 ? customerType = "new" : customerType = "repeat";
         window.dataLayer = window.dataLayer || [];
             'event': 'GTMevent',
             'eventCategory' : 'purchase',
             'eventAction' : 'complete',
             'eventLabel' : '{{}} | ' + customerType,
             'customerId': '{{}}',
             'customerType': customerType
   {% endif %}   
{% endif %}

The code should look like:

Save the changes.
Step 4: Add the following dataLayer variables in the GTM:
1) Customer Type variable:

2) Customer Id variable:

3) Event Category variable (as we will be passing the data via event hit into GA):

4) Event Action variable:

5) Event Label variable:

Step 5: Add the custom event trigger to fire on ‘purchase’ event:

Step 6: Add Google Analytics Event tag to push the data into analytics:

That’s it! Publish GTM container and start collecting your data in Google Analytics.

Related Insights

How Much Do Google Ads Cost: 2021 vs. 2022

3 January 2022

Google Ads is one of the largest advertising platforms that allows brands to reach potential customers through a great variety of ad formats, including search, shopping, video and display. It’s a popular choice for brands that are looking to start advertising their business online, and many of them have a lot of questions about Google Ads. […]
Learn more

Amazon Ads: The Ultimate Guide For Beginners

29 December 2021

Contents What Is Amazon Advertising Is Amazon Worth It: Pros & Cons How Amazon Advertising Works Before You Begin Amazon Ad Types Create Your First Campaign Amazon Ads Campaign Optimization Tips Conclusion What is Amazon Advertising? After launching in 2018, Amazon Advertising (previously known as Amazon Marketing Services) has become one of the largest digital […]
Learn more

How To Structure Your Google Ads Search Campaigns: Google Ads Account Structure Templates

20 December 2021

Having a solid account structure is the backbone of a successful account on any advertising platform. It allows you to control when, where, and for which searches you want your ads to appear, and how much you spend on different streams of traffic, incoming from your marketing campaigns. With a well-built account structure, you’ll have: […]
Learn more