[Shopify] Set up purchase webhooks
By implementing webhooks to your Shopify store, you can efficiently track and process key events, such as purchases and user interactions, in real-time. Webhooks allow for seamless data collection by sending event information directly to GTM, where it can be processed, organized, and transmitted to analytics tools. This setup ensures accurate tracking, enhances data reliability, and provides better insights into customer behavior and store performance.
In this document you will learn:
Install Tagging Pixel in your Shopify Website
Google Tag Manager Web Container setup
Google Tag Manager Server Container setup
Test webhook via the sGTM
Parameters and their Values
Let’s get started 🚀
To start, you need to install a tagging pixel on your Shopify website. The pixel is the foundation for collecting accurate and actionable data about user behavior and purchases.
Once installed, it’s essential to verify that the pixel is working correctly to ensure reliable data collection. This verification step helps avoid any tracking errors and ensures the smooth functioning of your analytics setup.
The GTM Web Container helps manage your website tracking in one place. In this section, you’ll configure data variables, GA4 tags, and triggers.
To track user activity effectively on your site, you need to add DataLayer variables from the “trytagging_user_data” event to your Google Tag Manager (GTM) web container. These variables allow you to capture key data points that are essential for analyzing user interactions and behavior.
Create variable for user_id
Create variable for session_id
Create variable for session_count
After adding the DataLayer variables to your GTM container, the next step is to create a GA4 tag. This tag is crucial for sending user data to Google Analytics 4
When creating the GA4 Tag, it is essential to include specific parameters to ensure accurate tracking and smooth functionality. The key parameters to include are send_page_view, first_party_collection, and server_container_url. These parameters optimize the tag for accurate tracking, efficient data processing, and server-side operations.
For more information on how to create GA4 tag, and what parameters are required for GA4 tag, refer to the documentation on Create GA4 tag
After adding the required parameters, add the parameters to your GA4 Tag based on the type of data you want to track in your shopify store. For detailed information about the parameters and their values, refer to the tables Parameters and their Values
For this demonstration we have added the below 3 parameters to our GA4 tag

Triggers control when a tag fires. Instead of firing the tag on every page, set it to fire only on a specific event, such as trytagging_user_data. This prevents unnecessary data from being collected.
For more information on how to create trigger that fire only with the custom events, refer to the documentation for setup up trigger

Once you have created the trigger for your GA4 tag in the Google Tag Manager (GTM) web container, the next step is to set up the GTM server container.
The GTM Server Container processes data on the server instead of the browser. This helps reduce errors and keeps data secure.
In the server container, set up variables to capture key data points similar to those in the web container. These variables ensure that the data collected on the server aligns with the data from the web container, maintaining consistency.
This setup helps in accurate data processing and avoids discrepancies between client-side and server-side tracking.
Create variable for user_id
Create variable for session_id
Create variable for session_count
Set up a GA4 tag to handle server-side data. This tag processes the data and sends it to Google Analytics, ensuring accurate tracking even when browser-based tracking fails.
Configure a trigger to fire the GA4 tag only when specific conditions are met. Exclude the purchase event from this trigger since purchases will be tracked using webhooks. This prevents duplicate tracking.
Before setup GA4 Trigger you need to create a transformation and attach your GA4 tag to the transformation. For more information how to create a transformation, refer to the documentation on Create a Transformation
Ensure the purchase event is excluded from the GA4 trigger, as purchase events are now sent via Webhooks. Failing to exclude it may result in duplicate data being recorded.
A transformation is used to organize raw data into a structure that can be processed by the GA4 tag. This ensures that the data is formatted properly and integrates smoothly into your analytics system. Without a transformation, raw data might not align with the expectations of your GA4 tag, leading to inconsistencies in your tracking.
A Data Client is a key component that connects your GTM server container to your analytics setup. It acts as a bridge, ensuring that the data collected on the server flows correctly into your analytics tools. Setting this up is essential for handling server-side data efficiently.
To create a Data Client, we first need to download it and add the data client template to your server container. After that we can create a client. To create the Dataclient we use the Stape Data Client. You can download it here. https://github.com/stape-io/data-client
To begin, download the Data Client template and add it to your GTM server container. The template simplifies the process of managing server-side data by providing predefined configurations.
After adding the Data Client template, create a Data Client in your server container. This step ensures that your server container is ready to process incoming data and send it to your analytics platform. The Data Client manages the flow of data from the server to your GA4 tags or other destinations.
Webhooks are used to capture specific events, such as purchases. To make the most of webhook data, you need to create variables that extract and store important details. For example, in the demonstration below, a variable for “Facebook Ads” is created. You can follow a similar process to create variables for other data points based on your needs.
For more details on the variables you can create, refer to the section “Parameters and their Values.”
Set up a variable to specify the source of your data, which in this case should be set to web. This variable helps identify that the data is coming from the web container, ensuring accurate tracking. It is particularly important when setting up the Webhook Purchase Trigger, as it ensures the trigger activates only for events originating from the web.
The GA4 Purchase Tag is used to send purchase data to Google Analytics. It includes variables like user_id, session_id, and session_count to associate purchases with specific users and sessions. The tag is configured to process webhook data using the event variables set up earlier, ensuring accurate tracking of purchase events.
For information about event variables, refer to the section “Parameters and their Values”
To ensure that the GA4 Purchase Tag fires at the right time, set up a trigger. Configure this trigger to activate only when a purchase webhook event is received. This step ensures that purchase data is tracked accurately without any unnecessary or duplicate tracking.
Alright, now that we've set up the Shopify webhook in the sGTM container, it's time to test it. You can either process live orders or place an order yourself to ensure everything is working correctly. This helps verify that the webhook is capturing and transmitting data as expected.
For more information, refer to this document Testing webhooks and live preview mode via your sGTM
Here’s a detailed list of parameters you can add to your Google Tag based on the type of data you want to track.
In this document you will learn:
Install Tagging Pixel in your Shopify Website
Google Tag Manager Web Container setup
Google Tag Manager Server Container setup
Test webhook via the sGTM
Parameters and their Values
Let’s get started 🚀
Install Tagging Pixel in your Shopify Website
To start, you need to install a tagging pixel on your Shopify website. The pixel is the foundation for collecting accurate and actionable data about user behavior and purchases.
Once installed, it’s essential to verify that the pixel is working correctly to ensure reliable data collection. This verification step helps avoid any tracking errors and ensures the smooth functioning of your analytics setup.
Google Tag Manager Web Container setup
The GTM Web Container helps manage your website tracking in one place. In this section, you’ll configure data variables, GA4 tags, and triggers.
Create Data Variables
To track user activity effectively on your site, you need to add DataLayer variables from the “trytagging_user_data” event to your Google Tag Manager (GTM) web container. These variables allow you to capture key data points that are essential for analyzing user interactions and behavior.
Create variable for user_id
Create variable for session_id
Create variable for session_count
Create GA4 Tag in Web Container
After adding the DataLayer variables to your GTM container, the next step is to create a GA4 tag. This tag is crucial for sending user data to Google Analytics 4
When creating the GA4 Tag, it is essential to include specific parameters to ensure accurate tracking and smooth functionality. The key parameters to include are send_page_view, first_party_collection, and server_container_url. These parameters optimize the tag for accurate tracking, efficient data processing, and server-side operations.
Sr.no | Parameter | Value |
---|---|---|
1 | first_party_collection | true |
2 | send_page_view | true |
3 | server_container_url | tagging.mydomain.com |
For more information on how to create GA4 tag, and what parameters are required for GA4 tag, refer to the documentation on Create GA4 tag
After adding the required parameters, add the parameters to your GA4 Tag based on the type of data you want to track in your shopify store. For detailed information about the parameters and their values, refer to the tables Parameters and their Values
For this demonstration we have added the below 3 parameters to our GA4 tag
S.no | Parameter | Value | Explantation |
---|---|---|---|
1 | user_id | {{marketing.user_id}} | Unique user identifier for the user. |
2 | session_id | {{marketing.session_id}} | Unique identifier for the current user session. |
3 | session_count | {{Marketing.session_count}} | Counts the number of sessions for a specific user |

Setup Trigger for Google Analytics Tag
Triggers control when a tag fires. Instead of firing the tag on every page, set it to fire only on a specific event, such as trytagging_user_data. This prevents unnecessary data from being collected.
For more information on how to create trigger that fire only with the custom events, refer to the documentation for setup up trigger

Once you have created the trigger for your GA4 tag in the Google Tag Manager (GTM) web container, the next step is to set up the GTM server container.
Google Tag Manager Server Container setup
The GTM Server Container processes data on the server instead of the browser. This helps reduce errors and keeps data secure.
Create Data variables in GTM Server Container
In the server container, set up variables to capture key data points similar to those in the web container. These variables ensure that the data collected on the server aligns with the data from the web container, maintaining consistency.
This setup helps in accurate data processing and avoids discrepancies between client-side and server-side tracking.
Create variable for user_id
Create variable for session_id
Create variable for session_count
Create GA4 tag in Server Container
Set up a GA4 tag to handle server-side data. This tag processes the data and sends it to Google Analytics, ensuring accurate tracking even when browser-based tracking fails.
Setup GA4 Trigger
Configure a trigger to fire the GA4 tag only when specific conditions are met. Exclude the purchase event from this trigger since purchases will be tracked using webhooks. This prevents duplicate tracking.
Before setup GA4 Trigger you need to create a transformation and attach your GA4 tag to the transformation. For more information how to create a transformation, refer to the documentation on Create a Transformation
Ensure the purchase event is excluded from the GA4 trigger, as purchase events are now sent via Webhooks. Failing to exclude it may result in duplicate data being recorded.
Create a Transformation
A transformation is used to organize raw data into a structure that can be processed by the GA4 tag. This ensures that the data is formatted properly and integrates smoothly into your analytics system. Without a transformation, raw data might not align with the expectations of your GA4 tag, leading to inconsistencies in your tracking.
Set up Data Client
A Data Client is a key component that connects your GTM server container to your analytics setup. It acts as a bridge, ensuring that the data collected on the server flows correctly into your analytics tools. Setting this up is essential for handling server-side data efficiently.
To create a Data Client, we first need to download it and add the data client template to your server container. After that we can create a client. To create the Dataclient we use the Stape Data Client. You can download it here. https://github.com/stape-io/data-client
Add “Data Client” Template
To begin, download the Data Client template and add it to your GTM server container. The template simplifies the process of managing server-side data by providing predefined configurations.
Create Data Client
After adding the Data Client template, create a Data Client in your server container. This step ensures that your server container is ready to process incoming data and send it to your analytics platform. The Data Client manages the flow of data from the server to your GA4 tags or other destinations.
Create Event Data Variable for Purchase Webhook data
Webhooks are used to capture specific events, such as purchases. To make the most of webhook data, you need to create variables that extract and store important details. For example, in the demonstration below, a variable for “Facebook Ads” is created. You can follow a similar process to create variables for other data points based on your needs.
For more details on the variables you can create, refer to the section “Parameters and their Values.”
Create Source name Data Variable
Set up a variable to specify the source of your data, which in this case should be set to web. This variable helps identify that the data is coming from the web container, ensuring accurate tracking. It is particularly important when setting up the Webhook Purchase Trigger, as it ensures the trigger activates only for events originating from the web.
Create a GA4 Purchase Tag
The GA4 Purchase Tag is used to send purchase data to Google Analytics. It includes variables like user_id, session_id, and session_count to associate purchases with specific users and sessions. The tag is configured to process webhook data using the event variables set up earlier, ensuring accurate tracking of purchase events.
For information about event variables, refer to the section “Parameters and their Values”
Create GA4 Purchase Trigger
To ensure that the GA4 Purchase Tag fires at the right time, set up a trigger. Configure this trigger to activate only when a purchase webhook event is received. This step ensures that purchase data is tracked accurately without any unnecessary or duplicate tracking.
Test webhook via the sGTM
Alright, now that we've set up the Shopify webhook in the sGTM container, it's time to test it. You can either process live orders or place an order yourself to ensure everything is working correctly. This helps verify that the webhook is capturing and transmitting data as expected.
For more information, refer to this document Testing webhooks and live preview mode via your sGTM
Parameters and their Values
Here’s a detailed list of parameters you can add to your Google Tag based on the type of data you want to track.
S.no | Parameter | Value | Type | Explanation |
---|---|---|---|---|
1 | ga | {{marketing.ga}} | Event Data | Google Analytics client ID used for tracking users. |
2 | fbc | {{marketing.fbc}} | Event Data | Facebook Click ID for Facebook Ads tracking. |
3 | fbp | {{marketing.fbp}} | Event Data | Facebook Pixel ID for tracking user events. |
4 | ttp | {{marketing.ttp}} | Event Data | TikTok Pixel ID for tracking user events. |
5 | gclid | {{marketing.gclid}} | Event Data | Google Ads Click ID used to attribute ad clicks. |
6 | gbraid | {{marketing.gclid}} | Event Data | Google Ads ID for app campaigns. |
7 | ttclid | {{marketing.ttclid}} | Event Data | TikTok Click ID for ad campaigns. |
8 | wbraid | {{marketing.wbraid}} | Event Data | Google Ads Click ID for web campaigns |
9 | user_id | {{marketing.user_id}} | Event Data | Unique user identifier for the user. |
10 | hostname | {{marketing.hostname}} | Event Data | Domain name of the user's current session |
11 | referrer | {{marketing.referrer}} | Event Data | The referring URL from which the user arrived. |
12 | client_id | {{marketing.client_id}} | Event Data | Google Analytics client ID for identifying users. |
13 | session_id | {{marketing.session_id}} | Event Data | Unique identifier for the current user session. |
14 | user_agent | {{marketing.user_agent}} | Event Data | Details about the user's browser and device. |
15 | utm_medium | {{marketing.utm_medium}} | Event Data | The medium used in UTM tracking (e.g., email, CPC). |
16 | utm_source | {{marketing.utm_source} | Event Data | The source used in UTM tracking (e.g., Google, newsletter). |
17 | session_count | {{Marketing.session_count}} | Event Data | Counts the number of sessions for a specific user. |
Updated on: 06/02/2025
Thank you!