Home Blog Area Analytics

Passing Customers’ Data to Google Analytics from Shopify

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:

  • Add the custom event trigger to fire on the ‘purchase’ event:
  • 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

      13 June 2024

      Prevent Data Loss: Set Up BigQuery Error Notifications

      BigQuery has gained significant popularity and is increasingly utilized in numerous projects. Google’s cloud-based data warehouse solution is known for its scalability, speed, and ability to handle large datasets efficiently. As more organizations integrate BigQuery into their data processing and analytics workflows, robust monitoring and alerting mechanisms are essential. Implementing alerts for jobs that encounter […]

      Learn more

      30 May 2024

      How To Create A Meaningful Ecommerce Analytics Dashboard: A Step-by-step Guide

      Are you drowning in a huge amount of e-commerce data? There’s no other way to escape it if you want your e-commerce store to succeed. However, you can make analyzing your data much more enjoyable and effective. The key is to present e-commerce data analytics visually. Data visualization plays a big role in data-driven decision-making. […]

      Learn more

      28 March 2024

      Navigating the Data Deluge: Prioritizing Key Metrics in the Age of Google Analytics 4

      With the advent of Google Analytics 4 (GA4), the key business challenge becomes not collecting data but discerning what truly matters in the sea of data. 64% of marketing executives believe data-driven marketing is crucial to success in a hyper-competitive global economy. By prioritizing key metrics and avoiding the trap of tracking everything, businesses can […]

      Learn more

      3 January 2024

      How to Create a Viable First-Party Data Strategy in 2024?

      Discover the 9 key steps to build a first-party data strategy that maximizes customer data and enhances your marketing efforts.

      Learn more

      27 December 2023

      How To Create a Seamless Customer Experience to Win More Returning Clients

      Want customers hitting a repeat button? Learn the secrets to building a seamless customer experience that keeps them coming back for more.

      Learn more

      30 November 2023

      Maximize Your Data Retention in Google Analytics 4 (GA4) 

      Learn how to manage data storage and protect privacy with GA4 data retention settings.

      Learn more

      24 November 2023

      How to Read and Interpret Google Analytics 4 Reports to Drive Business Success

      Get to know how to read Google Analytics 4 reports to uncover customer insights, optimize marketing strategies, and drive business growth.

      Learn more

      11 November 2023

      How to Preserve Google Analytics Historical Data

      Fearing to lose your Google Analytics’ historical data? Don't worry! This guide will show you four ways to save data during the UA-to-GA4 migration.

      Learn more