Google Tag Manager has three building blocks: tags (what to do), triggers (when to do it), and variables (what data to use). If you understand tags but find variables and triggers confusing, this guide clarifies how they work and how they relate to each other in the context of Shopify ecommerce tracking.
What GTM Variables Are
Variables are named references to dynamic values that change based on the current page, user action, or dataLayer content. They are the mechanism GTM uses to pass specific data into tags.
When you set up a GA4 Purchase event tag, you need to tell GTM where to find the purchase value, the transaction ID, and the items array. You do this by creating variables that read those values from the page.
The Main Types of GTM Variables
Built-in variables (always available):
- Page URL: the current page’s full URL
- Page Path: the URL path (e.g. /products/t-shirt)
- Referrer: the previous page URL
- Click URL, Click Text, Click ID: values from elements users click
DataLayer Variables (most important for ecommerce):
Read values that Shopify or your GTM tags push to window.dataLayer. For example, if the dataLayer contains {'ecommerce': {'value': 149.99}}, you create a DataLayer Variable with the path “ecommerce.value” to read 149.99 into your GA4 tag.
JavaScript Variables:
Execute a small JavaScript function and use the return value. Useful for reading data that exists in the page’s global JavaScript scope but is not in the dataLayer.
Constant Variables:
Store a fixed value (like your GA4 Measurement ID) that can be referenced across multiple tags. Change the value once in the variable, and all tags update automatically.
Lookup Tables:
Map one value to another. For example, map URL path patterns to page categories: “/products/” → “Product Page”, “/collections/” → “Collection Page.”
What GTM Triggers Are
Triggers are conditions that control when a tag fires. Every tag in GTM must have at least one trigger. The trigger defines what event or state must occur for the tag to activate.
The Main Types of GTM Triggers
Page View triggers:
- All Pages: fires on every page load
- Window Loaded: fires after all page resources finish loading (including scripts)
- DOM Ready: fires when the page DOM is built but before images/scripts finish loading
Click triggers:
- All Elements: fires on any click anywhere on the page
- Just Links: fires only on link clicks (A tags)
- {{dlv – ecommerce.value}}: DataLayer Variable reading the order total
- {{dlv – ecommerce.transaction_id}}: DataLayer Variable reading the order ID
- {{dlv – ecommerce.currency}}: DataLayer Variable reading the currency code
Both can be filtered to fire only when specific conditions are met (element ID, CSS class, text content).
Custom Event triggers:
Fire when a specific custom event is pushed to the dataLayer. This is the most important trigger type for ecommerce. Your Shopify dataLayer pushes events like “dl_purchase” or “purchase” to the dataLayer — a Custom Event trigger listening for that event name fires the GA4 purchase tag when the event occurs.
Form submission triggers:
Fire when an HTML form is submitted. Can be filtered to fire only on specific form IDs or pages.
Scroll Depth triggers:
Fire when users scroll to a specified percentage of page length. Used for tracking content engagement.
How Tags, Triggers, and Variables Work Together
A GA4 Purchase event tag on Shopify:
Tag: GA4 Event tag, event name: “purchase”, parameters include value, transaction_id, items.
Trigger: Custom Event, event name: “purchase” (fires when the Shopify dataLayer pushes a purchase event).
Variables:
When a customer completes a purchase, Shopify pushes a purchase event to the dataLayer with all the order data. The Custom Event trigger detects this push. It activates the GA4 Event tag. The tag reads the order values via the DataLayer Variables and sends them to GA4.
Common Variable and Trigger Mistakes in Shopify GTM
Wrong dataLayer path
Shopify’s dataLayer may nest values differently than your variable expects. Always verify the path by checking the dataLayer tab in GTM Preview mode before publishing.
Trigger fires too broadly
A “Page View – All Pages” trigger on a purchase tag will fire on every page, sending duplicate purchase events constantly. Add a URL condition or use a Custom Event trigger instead.
Variables returning undefined
A DataLayer Variable returns undefined if the key does not exist in the dataLayer. Check the exact case and nesting of the key in the dataLayer tab in Preview mode.
Get Your GTM Tags Configured Correctly
Incorrect variables and triggers are the most common cause of tracking data being wrong or missing. A tag that fires with the right trigger but reads a wrong variable value silently corrupts your GA4 data without any obvious error message.
Book your free Shopify tracking audit here and we will review your complete GTM setup including all tags, triggers, and variables to confirm everything is correctly configured.