Implement ecommerce tracking in a Shoporama theme
Developer guide to ecommerce tracking in a Shoporama theme: the data layer, Google Tag Manager, custom events, and correct product IDs with getTrackingId().
This guide is for theme developers and freelancers who want to implement ecommerce tracking in a Shoporama theme. We cover the theme's data layer, setting up Google Tag Manager, correct product IDs with getTrackingId(), and how to fire custom events from your own theme.
Important to know before you code
Shoporama's built-in tracking is injected server-side, independently of the theme. It works in all themes, including fully custom themes, and requires no theme code. As a theme developer, you don't need to do anything to make it work. This article is for stores that build their own tracking setup on top of or instead of the built-in tracking. Read more about the built-in tracking in Tracking in your Shoporama store.
1. Shoporama's built-in tracking requires no theme code
Before you write any code yourself, consider Shoporama's tracking module. You find it in the left sidebar under Webshop (the gear icon) → Tracking. Check Enable tracking, choose the platforms you want to send data to, and enter your IDs and access tokens.
The tracking module inserts its own scripts and fires its own events. This happens server-side, independently of the theme files, so you don't have to include partials, insert scripts, or change a single line in the theme. The module supports:
- Facebook Pixel and Conversions API
- Google Ads (including offline conversions)
- Microsoft Ads
- Google GA4
- Pinterest, Snapchat, TikTok, and LinkedIn
- Server-side tracking through your own subdomain (avoids ad blockers)
- Consent Mode v2
If the store only needs standard ecommerce tracking, your work as a theme developer is done here. The rest of the article is about stores that want to run their own setup, typically through Google Tag Manager, on top of or instead of the built-in tracking.
2. The theme's data layer
The standard themes Delaware, DelawareDK, Montana, and MontanaB2B include a partial called partials/datalayer.html. It pushes GA4-compatible ecommerce events to window.dataLayer when the theme's own tracking is turned on. This is what you build on if the store needs its own GTM setup.
How to turn on the theme's dataLayer: The theme's dataLayer and your own Google Tag Manager ID belong to the older theme tracking. It is not turned on with Enable tracking under Tracking, because that is the built-in tracking. Email support@shoporama.dk, and we will turn on the theme tracking for the store and insert your GTM ID. Don't use it together with the built-in tracking: both send the purchase to the same dataLayer, so every purchase is counted twice.

The theme fires the following events automatically:
| Event | When |
|---|---|
| view_item | A product page is shown |
| view_item_list | A category or landing page is shown |
| select_item | A product card is clicked |
| add_to_cart | A product is added to the cart |
| remove_from_cart | A product is removed from the cart |
| view_cart | The cart page is shown |
| begin_checkout | The address page is shown (checkout starts) |
| add_shipping_info | The customer continues from the shipping and payment page. The name of the selected shipping method is sent as shipping_tier |
| add_payment_info | At the same time as add_shipping_info, when the customer continues from the shipping and payment page. The name of the selected payment method is sent as payment_type |
| purchase | The thank-you page (receipt) is shown after a completed purchase |
| search | The search results page is shown |
| customerInfo | Logged-in customer with email |
| ShopOramaSettings | Settings are pushed on page load (pixel ID, currency, GA4 ID, and more) |
The table applies to the theme's own dataLayer. In Delaware and Montana (and DelawareDK and MontanaB2B), add_shipping_info and add_payment_info are sent when the customer submits the form on the shipping and payment page. Shoporama's built-in tracking (Tracking in the admin) sends its own events independently of the theme, and the timing is not always the same. For example, it sends add_shipping_info when the shipping and payment page is shown, and add_payment_info on the next page. See the overview in Tracking in your Shoporama store.
A view_item push on the product page should look like this in the template:
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
event: 'view_item',
ecommerce: {
currency: '<{$webshop->getCurrency()}>',
items: [{
item_id: '<{$product->getTrackingId()}>',
item_name: '<{$product->getName()|escape:"javascript"}>',
price: <{$product->getRealPrice()|number_format:2:".":""}>,
quantity: 1
}]
}
});
</script>
Note item_id: it comes from $product->getTrackingId() and not from an ID you build yourself. We explain why this matters in the next section.
If you build your own theme from scratch, you can copy templates/partials/datalayer.html from the Delaware theme and include it in your global.html:
<{include file="partials/datalayer.html"}>
add_shipping_info and add_payment_info require the form on the shipping and payment page to have id="shipping_form", and the radio buttons for shipping and payment to have the method's name in data-shipping_name and data-payment_name. This is how it looks in Montana:
<form action="" method="post" id="shipping_form">
<input type="radio" name="shipping_id" value="<{$shippings[i]->getShippingId()}>" data-shipping_name="<{$shippings[i]->getName()|escape}>">
<input type="radio" name="payment_gateway_id" value="<{$gateways[i]->getPaymentGatewayId()}>" data-payment_name="<{$gateways[i]->getName()|escape}>">
If they are missing, the two events are not sent. This also applies if the store runs on its own copy of Delaware or Montana. In that case, you need to add the ID and the two data attributes yourself.
3. The product ID: always use getTrackingId()
Ad platforms like Meta and Google match your events against the product catalog using the product ID. This means that item_id in your events must be identical to the ID (g:id) in the store's product feed. If the two are different, the platform can't connect the event to the product in the catalog, and catalog matching, dynamic remarketing, and product reports fail.
That's why you should never build product IDs yourself in your templates. Use getTrackingId() instead, which always returns exactly the ID the store's feed uses:
item_id: '<{$product->getTrackingId()}>'
The format depends on the store's setup:
- Standard: the numeric product ID, for example 154585.
- Variants: the product ID and the variant value's ID separated by a colon, for example 154585:45789.
- Stores with language or country feeds: the SKU instead, since it is the stable key across country stores. The variant's SKU is used if it is filled in, otherwise the product's. If the product has no SKU at all, the ID falls back to the numeric format.
getTrackingId() handles all of this automatically per store. If you know the variant value's ID, for example in the cart, checkout, or receipt, pass it as the second parameter:
item_id: '<{$product->getTrackingId(null, $attribute_value_id)}>'
The first parameter is the attribute's ID. You can set it to null, and it is then looked up automatically from the variant value.
Warning: older datalayer partials reverse the variant ID
If you work from an older version of the themes' datalayer partial, be aware of a known inconsistency: on product views, some older partials build the variant ID in reverse order (variant value ID:product ID), while the checkout and purchase parts use the correct order (product ID:variant value ID). The reversed ID matches neither the feed nor the purchase event, so the platforms see it as an unknown product. The solution is to replace all hand-built IDs with getTrackingId().
Read more about the ID scheme and how to troubleshoot the match rate in Product IDs and catalog matching in Meta and Google.
4. Set up Google Tag Manager with HTML fields
When the theme's own tracking is turned on and your Google Tag Manager ID has been inserted, Shoporama automatically adds the GTM snippet for you. It is at the bottom of partials/datalayer.html.
If you would rather manage GTM (or other scripts such as Cookiebot, Hotjar, or Klaviyo) manually, use HTML fields. Go to Webshop → HTML fields. Here you can create named fields and choose whether they are inserted automatically in the head or body, or used manually in your theme through a tag name.
A typical GTM snippet in an HTML field set to be added automatically to the head looks like this:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
Also remember the <noscript> fallback in the body field:
<!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) -->
Read more about how HTML fields work in HTML fields: add Cookiebot, GTM, and other scripts.
5. Tags and triggers in GTM
With the standard data layer active, you can use GA4's built-in tags and custom event triggers. A typical setup looks like this:
- GA4 Configuration Tag with your Measurement ID, fired on All Pages
- GA4 Event Tag for each ecommerce event, set to read the ecommerce object from the data layer
- Custom Event triggers with the names view_item, add_to_cart, begin_checkout, purchase, and so on
- Use Preview mode in GTM to verify that events fire with the correct data
For Google Ads conversions, you link your Google Ads Conversion ID/Label to the purchase event. See also Google Analytics tracking for your store.
6. Custom events from your own theme
If you need to fire events that the standard data layer doesn't cover, for example a video play, a tab click, a chat opening, or a custom CTA, push directly to window.dataLayer from your theme:
<button onclick="trackVideoPlay()">Play video</button>
<script>
function trackVideoPlay() {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'video_play',
video_title: 'Product demo',
video_id: 'demo-123'
});
}
</script>
On the receipt page, you can fire your own purchase event with the order object and Smarty. Use getTrackingId() for item_id, and wrap everything in the duplicate protection getTrackingCalled() / setTrackingCalled(), so the event only fires once per order, even if the customer reloads the receipt page:
<{if $order && !$order->getTrackingCalled()}>
<{assign var="orderproducts" value=$order->getOrderProducts()}>
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: '<{$order->getWebshopOrderId()}>',
value: <{$order->getTotalPrice()|number_format:2:".":""}>,
currency: '<{$webshop->getCurrency()}>',
coupon: '<{$order->getVoucherCode()|escape:"javascript"}>',
items: [
<{foreach from=$orderproducts item=op}>
<{assign var="p" value=$op->getProduct()}>
<{assign var="attributes" value=$op->getAttributes()}>
{
<{if $attributes|@count == 1}>
<{foreach from=$attributes item=attr}>
item_id: '<{$p->getTrackingId(null, $attr.attribute_value_id)}>',
item_variant: '<{$attr.val|escape:"javascript"}>',
<{/foreach}>
<{else}>
item_id: '<{$p->getTrackingId()}>',
<{/if}>
item_name: '<{$op->getName()|escape:"javascript"}>',
price: <{$op->getPrice()|number_format:2:".":""}>,
quantity: <{$op->getAmount()}>
},
<{/foreach}>
]
}
});
</script>
<{$order->setTrackingCalled()}>
<{/if}>
The flag is shared by all tracking snippets on the order, including the theme's standard data layer. If you have several conversion snippets on the receipt page (for example a Pricerunner pixel plus your own purchase event), check the flag with getTrackingCalled() in each snippet, but call setTrackingCalled() in only one place, as the very last step, when all snippets have fired. The same pattern is used in the guide Implement Pricerunner tracking.
7. Testing and troubleshooting
- Use the Chrome extension GTM/GA Debugger or Tag Assistant to see which events fire
- Type window.dataLayer in the browser console to see the full dataLayer history
- Use GTM's Preview mode to see tags fire in real time
- Verify purchase events in GA4 DebugView
- Check catalog matching in Meta under Events Manager → Test Events or with the browser extension Meta Pixel Helper. A message saying that no content IDs were received usually means that item_id is missing or doesn't match the feed. See the section about getTrackingId() above
- If the theme's data layer doesn't fire, the theme's own tracking is probably not turned on. This is not the same as Enable tracking under Tracking. Email support@shoporama.dk, and we will turn it on
Frequently asked questions
Do I have to choose between Shoporama's built-in tracking and my own GTM setup?
Yes, choose one. The built-in tracking and the theme's own dataLayer both send ecommerce events, including the purchase, to the same dataLayer. If you turn on both, every purchase is counted twice. For most stores, the built-in tracking is enough and requires no code. If you need your own setup, email support@shoporama.dk, and we will help you turn off the built-in tracking and turn on the theme's.
What format should item_id have in my events?
The same format as the ID in the store's product feed: the numeric product ID by default, product ID:variant value ID for variants, and the SKU in stores with language or country feeds. You don't need to keep track of this yourself. Use $product->getTrackingId(), and the ID always matches the feed. See the details in Product IDs and catalog matching.
Why is the match rate on my Meta catalog low even though my events fire?
Almost always because the event's item_id is not identical to the feed's ID. Typical culprits are hand-built IDs, variants in the wrong order, or the SKU in one place and the numeric ID in another. Switch to getTrackingId() everywhere, and verify with Test Events in Meta Events Manager.
Where should I put the GTM snippet if I don't want to use HTML fields?
Directly in your theme's templates/global.html or in a custom header partial. We do recommend HTML fields, though, since they survive theme updates and can be changed without deploying a new theme.
Can I override or disable the standard events Shoporama fires?
Yes, for the theme's data layer. If you have a fully custom theme, just don't include partials/datalayer.html. If you build on Delaware or Montana and only want to change individual events, create your own partial and include it instead of the standard version. The built-in server-side tracking, on the other hand, is managed under Webshop → Tracking and is not affected by the theme.
Which variables do I have access to in the dataLayer template?
The typical ones: $webshop, $product, $category, $order, $basket, $customer, $voucher, and $inc, which tells you which template is being rendered (for example basket.html or thanks.html).
How do I avoid firing the purchase event twice if the customer refreshes the receipt page?
Check $order->getTrackingCalled() before you fire, and call $order->setTrackingCalled() when all your conversion snippets have fired. The flag is saved on the order, so it also holds on refresh. See the full example in the section about custom events above.
Do I need to account for Consent Mode in my own theme?
Yes. If the customer hasn't given consent, you must not fire tracking events that use cookies. Use a cookie consent manager (Cookiebot, CookieInformation, or your own solution) and make your GTM tags depend on the consent state. Shoporama's server-side tracking handles Consent Mode automatically when you turn on Use Consent Mode in the tracking module.
Can I send my own dataLayer events to platforms other than Google?
Yes. The dataLayer is platform-agnostic. You can set up tags in GTM for Meta CAPI, TikTok Events API, or anything else that supports the dataLayer as a source. Alternatively, you can fire directly to the platforms' own SDKs (for example fbq() or ttq.track()) from your theme. Remember to use getTrackingId() as the product ID, whatever the platform.
Need help with the implementation? Email support@shoporama.dk.
Related articles
Set up PriceRunner conversion tracking in Shoporama
How to add the PriceRunner conversion pixel to your Shoporama store with the correct Smarty code, so PriceRunner receives the order total incl. VAT...
Set up Daisycon tracking in your online store
How to implement Daisycon conversion tracking in your Shoporama store with the correct Smarty code, so each order is only counted once.
SEO in Shoporama: a complete guide to the SEO features
A complete guide to the SEO features in Shoporama, from meta titles, meta descriptions, and the XML sitemap to keyword analysis, Google Shopping,...
Related features
dataLayer
The dataLayer connects your online store to Google Tag Manager. Learn how ecommerce data such as product views and purchases is passed on to your...
Pixel swapping
Pixel swapping is a fraud technique where tracking pixels are manipulated to hijack conversions. Learn how it works and how to protect your online...
Server-side tracking
Server-side tracking collects data through your server instead of the browser. Learn why it gives you better data and how it works in your online...
Server-side tracking: more accurate data for your ads
Server-side tracking for Google, Meta, Pinterest, TikTok, and Snapchat. Less affected by ad blockers. Available as an add-on on Pro and Flex.