Passing Customers’ Data to Google Analytics from Shopify

Published: 20 July 2020

Updated: 13 February 2023

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

  1. Add ‘Customer ID’ and ‘Customer Type’ custom dimensions in Google Analytics:
  2. Make sure you have installed GTM snippet in your Shopify account. You can use the following guide.
  3. Go to the ‘Settings’ -> ‘Checkout’ in Shopify:
  4. 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:
  5. Add the custom event trigger to fire on the ‘purchase’ event:
  6. Add a Google Analytics Event tag to push the data into analytics:

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.

How to Use Google Analytics App + Web Tracking Feature

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

    1 September 2023

    How Marketing Teams Can Take Advantage of Generative AI

    Generative AI is a game-changer for marketing. Discover how you can use this technology to create more personalized customer experiences and drive more conversions.

    Learn more

    31 July 2023

    10 Tips for Marketing Male Supplements with Social Media

    Discover the best way to promote your male supplement company with our comprehensive guide. Learn how to use social media to promote your products and generate leads.

    Learn more

    20 July 2023

    How Marketers Can Use GA4 to Improve Campaign Performance

    Study our guide to GA4 for marketers and learn how to track your marketing performance, measure your ROI, and make better decisions.

    Learn more

    14 July 2023

    Understanding Data Filters in Google Analytics 4

    Want to get more out of your Google Analytics 4 data? Learn how to use GA4 filters to see the data that matters most to you.

    Learn more

    5 July 2023

    How to Set up Event Tracking in Google Analytics 4

    Learn how to set up event tracking in Google Analytics 4, track user behavior on your website or app, and use this data to improve your marketing campaigns and website performance.

    Learn more

    30 June 2023

    The Ultimate GA4 Handbook: Your Complete Guide to Understanding GA4

    Discover the ultimate guide to Google Analytics 4. Seamlessly transition from Universal Analytics to GA4 and unlock its full potential. Download the free handbook now!

    Learn more

    23 June 2023

    How to Use Google Analytics 4 to Grow Your Small Business

    Want to know how to use Google Analytics 4 to grow your small business? This article will show you how to set up GA4, track your key metrics, and use the data to make informed decisions.

    Learn more

    13 June 2023

    Understanding Enhanced Measurement in GA4

    Learn how to use Enhanced Measurement in Google Analytics 4 to collect more data about your users and improve your marketing and business decisions.

    Learn more