Passing Customers’ Data to Google Analytics from Shopify

20 July 2020

Share:

share_icon_fb share_icon_ln
post_image

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 %}
      <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.
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.

Author: Alex Zakharych, analyst and data scientist at Viden.

Share:

share_icon_fb share_icon_ln

Related Insights

Google Analytics 4. Implementation Guide for GTM

2 April 2021

Updates of digital tools and services from larger businesses always raise many questions and concerns regarding future functionality. Even product updates of a mid-size company can create quite a bustle if businesses rely on the company service. Thus, it is easy to imagine the anticipation and excitement marketers had while waiting for the Google Analytics 4 release. And now it is there. Announced earlier in 2019, Google Analytics 4 was released in October 2020. You can often find marketers referring to it using the acronym GA4. What does the GA 4 version represent for marketers, and how does one get started with it? This article will briefly walk you through the main steps one needs to know, beginning with GA4.
Learn more

Learn with Google: 5-Step Guide to Make Better Marketing Measurements

23 March 2021

In 2021, when the digital marketing industry is evolving according to customer expectations, privacy becomes a crucial factor for digital marketers. In fact, according to a data security survey conducted by RSA, as many as 78% of respondents said that they valued their data privacy the most. It means that new practices are required for marketing measurements to respect consumers' privacy and improve their journey. Teaming up with Google, we've prepared a Guide with 5 Recommendations that can help your business make marketing measurements in a better and smarter way to ensure a seamless customer experience.
Learn more

How to Expand Your Target Market and Lift The Business with Dashing Growth

23 February 2021

Your business might have a loyal customer base, however, it is always a good idea to look for ways to attract new clients. One of the solutions to tackle that is to extend your target market. How? Let’s dig deeper. The tactic is to understand motivations and triggers that can work for different buyers’ segments and use them for developing persuasive creatives when placing the ads.
Learn more