Implement tracking in a Shoporama theme
Developer guide to implement tracking code in a Shoporama theme with Google Tag Manager and data layers.
This guide is for theme developers who want to implement e-commerce tracking in a Shoporama theme. We recommend using Google Tag Manager (GTM) with Shoporama's default data layer.
Recommendation
The easiest solution for merchants is to use Shoporama's built-in tracking, which sends data automatically without code changes. This guide is for those who want manual control.
1. enable default data layer
Shoporama can automatically generate a default data layer with e-commerce data. Enable it under Settings → Tracking → Enable standard data layer.
The data layer follows the GA4 e-commerce standard and includes events such as view_item, add_to_cart and purchase.
2. Add GTM code in your theme
Insert the GTM snippet in your theme's header. Either via Settings → Code in head/body or directly in your theme's header.html:
<!-- 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 -->
3. Set up tags in GTM
In Google Tag Manager, you create tags for the events you want to track. With Shoporama's default data tag enabled, you can use the built-in GA4 event tags:
- GA4 Configuration Tag - with your Measurement ID
- GA4 Event Tags - for each e-commerce event you want to track
- Triggers - based on dataLayer events
Manual data layer implementation
If you need full control, you can build your own data layer with Smarty variables. For example, on the order confirmation page(receipt.html) you can add:
<script> dataLayer.push({ event: 'purchase', ecommerce: { transaction_id: '<{$order->getOrderId()}>', value: <{$order->getTotal()}>, currency: '<{$order->getCurrencyCode()}>' } }); </script>
Read more in our complete tracking guide. Do you need help? Contact us at support@shoporama.dk.