Choose your tracking method
Shopify
Google Tag Manager
Server-side tracking
Google Tag Manager setup
GTM tracking uses Dema’s V2 event API: every event is a Custom HTML tag that calls a singledema.event() method with data from your data layer. This section gives you the full picture of a setup; the Google Tag Manager guide has the tag code for every event.
Before you start
GTM on your site
Ecommerce data layer
Your Dema ID
DV-XXXXXXXXXXXXXXXXXXXXXXXXSetup steps
Create the GTM variables
{{Dema > ID}}, that holds your Dema ID. If your site is a single-page application and you don’t already have a referrer variable, also create the {{JS > Referrer}} Custom JavaScript variable, which keeps the referrer consistent across all events on the same page view. See GTM variables.Set up cookie consent
{{Consent - Statistics}} variable for your consent management platform (CMP) and one shared flush tag. See Cookie consent.Add the core event tags
page_view, view_item and purchase tags. page_view fires on All Pages; the others fire on their data layer events. Keep the stub initializer that every tag includes — it stops events from being lost when a tag fires before the library has loaded, for example when a visitor lands on the order confirmation page straight from an email. See Core event tags.Add the optional event tags
add_to_cart and begin_checkout. See Optional event tags.Preview, verify and publish
Events to send
Send at least the three core events. The optional events aren’t required, but are recommended.Cookie consent
Dema events must be gated by cookie consent. There are two strategies:- Stage + flush (recommended)
- GTM native per-tag consent
{{Consent - Statistics}} variable. When consent is granted, the tag sends the event with dema.event(); when it isn’t, the tag queues it with dema.addToQueue(). A shared flush tag calls dema.emitPendingEvents() to send the queue once consent is granted.- Trigger the flush tag on your CMP’s consent data layer event, for example
cookie_consent_updatefor Cookiebot orOneTrustGroupsUpdatedfor OneTrust. - The flush must also run on returning visits, when the CMP reads its existing cookie and pushes the same consent event — otherwise events queued earlier on that page load stay in the queue.
- Don’t attach the event triggers (
view_item_list,purchase, …) to the flush tag. Its only job is to drain the queue.
{{Consent - Statistics}} variables for Cookiebot, OneTrust, Usercentrics, Iubenda and Google Consent Mode v2. See Cookie consent.Good to know
Overriding the visitor's country
Overriding the visitor's country
country to the event payload. See Overriding the country.Single-page applications
Single-page applications
document.referrer also doesn’t update on client-side navigation — the {{JS > Referrer}} variable from the GTM variables step bridges that gap.If your tags call dema.pageview, see Set up tracking with single page applications.Custom events
Custom events
event_name field is open-ended. You can send your own events, such as quiz_completed or search_performed, and Dema can build custom metrics on top of them. Use snake_case and avoid the names of the built-in events. The available fields are listed in the event data schema.Verifying events
Once the Dema pixel is implemented, verify that events are being tracked correctly:Check the tags in GTM Preview
Check the browser's network tab
https://tracker.dema.ai).Check the Dema dashboard
Test different scenarios
utm_source=google).Verifying Stage + flush consent
Verifying Stage + flush consent
sessionStorage under the key dema_pending_events instead of being sent — you can inspect it in your browser’s developer tools. Once you accept, the flush tag fires on the CMP’s consent event, the queued events are sent and the queue is cleared.The queue persists across pages in the same tab and holds up to 100 events; the oldest are dropped first.Troubleshooting
No events or no data in the dashboard
No events or no data in the dashboard
- Script loading: use your browser’s developer tools to confirm the tracking script loads and requests reach Dema’s endpoint.
- GTM triggers: make sure triggers are configured correctly and fire under the expected conditions.
- Stub initializer: every tag that calls
dema.*needs the stub. Without it, an event that fires before the library is initialized is lost. - Ad blockers: confirm that ad blockers or privacy settings aren’t preventing the script from running.
Events missing before or after consent
Events missing before or after consent
- Tags blocked by GTM: with Stage + flush, GTM’s per-tag consent setting must be Not set on the event tags and the flush tag. Otherwise the tag never runs and nothing is queued.
- Flush tag not firing: it must fire on the CMP’s consent data layer event — both when a visitor first accepts and when a returning visitor’s consent is read on page load.
- Consent event name: confirm in GTM Preview that the event name matches what your CMP actually pushes.
Queued events report the wrong page
Queued events report the wrong page
page_location: location.href and page_referrer explicitly on every queued event. The library only captures these when dema.event() actually runs — for queued events, that’s when the flush tag fires, which can be on a different page.Duplicate or inflated session counts
Duplicate or inflated session counts
- Multiple scripts: make sure the Dema script isn’t implemented in more than one place (for example, both in GTM and directly in the site code).
- Duplicate tags: review your GTM container to confirm tags aren’t firing more than once.
Numbers differ from GA4 or Shopify
Numbers differ from GA4 or Shopify

