How to install Google Tag Manager (GTM) on Shopify properly
Updated Nov 23, 2026
If you’re adding GTM to Shopify by only pasting the snippet into your theme, you're only getting half the picture. Because Shopify restricts checkout edits and runs scripts inside a sandboxed custom pixel, critical events like begin_checkout and purchase can easily be lost. The Stape Conversion Tracking app solves this by adding GTM to all pages and tracking checkout events through a custom pixel.
This step-by-step guide shows how to install GTM on Shopify to ensure correct tracking across your entire store. You'll learn:
- How to set up web and Stape-hosted server GTM containers
- Install the Stape Conversion Tracking app to deploy GTM and the Shopify dataLayer across all pages
- Configure GA4 tags in GTM
- Verify everything with thorough testing
You can set it up in two ways:
- Setup Wizard – this is the quickest way to add GTM containers for Shopify. Stape generates and imports your web and server GTM containers with tags already configured. For full instructions read the How to use Setup Wizard article. When setting up the Stape app, see the Step 3. Install and configure the Stape Conversion Tracking app chapter.
- Manual setup – you create the containers and GA4 tags yourself. The instructions are provided in this article.
Before you begin
Ensure you have the following:
- A Shopify store with admin access.
- A Google Tag Manager account.
- A GA4 property with a web data stream. You'll need its Measurement ID.
- No other GA4 installations on the store. Disconnect GA4 in the Google & YouTube app, and remove any hardcoded
gtag.jsor old GTM snippets from your theme. Otherwise, you'll get duplicated data.
Step 1. Create a web GTM container
- 1.Open Google Tag Manager, click three dots on the account name, and select Create container.

2. Enter a container name, choose Web as the target platform, and click Create.

3. Copy and save the web GTM ID.
Step 2. Create a server GTM container and host it on Stape
- 1.Create a new sGTM container. Open the collapsed element to see the instructions.
2. Create a container in Stape. Open the collapsed element to see the instructions.
3. Add a custom domain. Open the collapsed element to see the instructions.
4. Copy your server container URL (for example, https://sst.yourstore.com). For the instructions on how to find one, read How to find server container URL for sGTM container?
Step 3. Install and configure the Stape Conversion Tracking app
The Stape Conversion Tracking app injects the GTM snippet on every page of your store and pushes ecommerce events to the dataLayer, including checkout events that Shopify runs in a sandboxed custom pixel. This is a complete GTM app for Shopify: no theme code edits, and the app generates the Shopify GTM custom pixel code for you.
Follow How to set up the Stape Shopify app to install and configure it. Make sure that:
- In the Inject GTM tab: Insert GTM snippet is enabled, your web GTM ID from Step 1 is added, and your custom domain from Step 2 is set. Also, we highly recommend you enable Custom Loader and Cookie Keeper.

- In the Data Layer tab: Add ecommerce Data Layer events and Append '_stape' to event names are enabled. Also, check that the custom pixel is added and connected in Shopify admin → Settings → Customer events. Without it, checkout and purchase events won't be tracked.

- The Stape app embed is enabled in Online Store → Edit Theme → App embeds. Without it, the GTM snippet won't be added to your store.

Step 4. Set up Shopify GA4 tags in the web GTM container
Create the Google tag
- 1.In your web container, go to Variables → under User-Defined Variables click Create variable.

2. Click Variable configuration → Google tag: Configuration settings.

3. Click Add parameter.

4. Fill in:
- Config parameter – enter
server_container_url. - Value – enter your server container URL that you copied in Step 2.
Click Save.

5. Go to Tags → Add tag.

6. Click Tag Configuration → Other Google.

7. Click Google tag.

8. Enter your GA4 Measurement ID as the Tag ID.
9. Under Configuration settings, select the variable you've just created. Keep the trigger as is. Click Save.

Create the event name variable
The Stape app adds the _stape suffix to event names, and some of them (view_collection, search_submitted) differ from GA4’s recommended events, so you need to map them with a lookup table. Or, if you don't need to track everything and want to use a couple of events, create a separate GA4 tag for each event.
| Input | Output |
| view_collection_stape | view_item_list |
| select_item_stape | select_item |
| view_item_stape | view_item |
| search_submitted_stape | search |
| add_to_cart_stape | add_to_cart |
| remove_from_cart_stape | remove_from_cart |
| view_cart_stape | view_cart |
| begin_checkout_stape | begin_checkout |
| add_contact_info_stape | add_contact_info |
| add_shipping_info_stape | add_shipping_info |
| add_payment_info_stape | add_payment_info |
| purchase_stape | purchase |
- 1.Go to Variables → New.

2. Click Variable configuration → Lookup table.

3. Set Input Variable to {{Event}}.
4. Add the rows from the table above.
5. Enable Set Default Value and leave it empty. Name the variable GA4 Event Name and save.

Create the trigger
- 1.Go to Triggers → Add trigger.

2. Click Trigger Configuration → Custom Event.

3. Paste the following into Event name and enable Use regex matching:
^(view_collection|select_item|view_item|search_submitted|add_to_cart|remove_from_cart|view_cart|begin_checkout|add_contact_info|add_shipping_info|add_payment_info|purchase)_stape$
4. Keep All Custom Events selected, name the trigger Shopify ecommerce events, and save.

Create the GA4 event tag
1. Go to Tags → New.

2. Click Tag Configuration → Google Analytics.

3. Select Google Analytics: GA4 Event.

4. Enter your GA4 Measurement ID.
5. Set Event Name to {{GA4 Event Name}}.
6. Under More Settings → Ecommerce, enable Send Ecommerce data, and leave Data Layer as the data source. This sends currency, value, and items from the Stape app's ecommerce object.
7. (Optional) Add event parameters you need for other platforms, such as user data. Create Data Layer Variables for the fields you need (for example, user_data.email) and add them as event parameters. Forwarding these fields inside the GA4 event makes them available in the sGTM Event Data, where server-side tags (like Meta Conversions API or Google Ads) can use them for user matching.
8. Set the trigger to Shopify ecommerce events and save the tag.

Important:
If you use a consent banner, make sure consent is set up in GTM before the tags fire. For more information see Shopify Cookie Banner: Guide to CMP Setup and Debugging.
Step 5. Set up GA4 in the server GTM container
- 1.Open your server container and go to Clients. Check that the GA4 client is there. It's added by default. If it's missing, click New → Google Analytics: GA4 (Web) and save.

2. Go to Tags → Add tag.

3. Click Tag Configuration → Google Analytics.

4. Select Google Analytics: GA4.

5. Leave Measurement ID empty to use the one from the incoming request.
6. Click Triggering → then + at the top-right of the page.

7. Click Trigger Configuration → Custom.

8. Select Some Events. In the Select variable field select Choose Built-in Variable… and then select Client Name. In the next field select equals, in the last one type in GA4.

9. Save the tag.

Testing
- 1.Open your Shopify store, go to DevTools → Network. Reload the page, filter by your custom domain, and check that status is 200. For same-origin setups, filter by the path. If you use the Custom Loader, the file has a random name (for example,
0jcpuarkm.js) instead ofgtm.js.

2. Open Preview mode in both web and server containers. You’ll get the Tag Assistant, enter your shop’s address there. Browse products, add an item to the cart, and check that the GA4 event tag fires in the web container and the GA4 tag fires in the server container.


3. Check checkout events. Shopify blocks GTM Preview on checkout pages, so use the Stape GTM Helper extension. For the instructions go to the Stape Shopify app setup guide.
4. Place a test order and check that purchase shows up with the correct value and items. Go to your server container preview, click purchase, and then the Event Data tab.

5. Check GA4. Open Admin → DebugView, and check that events arrive without duplicates.

6. When everything works, publish both web and server containers.
Was this article helpful?
🍽 Table of content:
Comments