GTM destination: add "Load GTM" option to skip script injection - #1362
Merged
Conversation
The GTM device destination injects the GTM script lazily, only on the first event sent to it. For events fired right before a navigation (e.g. link clicks) this loses a race: the script hasn't loaded its tags/pixels yet by the time the browser navigates away. Add a `loadGtm` credential (default true, backward-compatible). When set to false, the client loads GTM itself (e.g. on page load) and Jitsu skips injecting the GTM script — it only ensures the data layer exists and pushes events to it, which the client-loaded container then processes. This keeps the official GTM destination usable without reimplementing it as a generic Tag destination. Requested by customer in Slack (C08UVQMET16). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Reviewed the GTM device-destination changes in:
- libs/jitsu-js/src/destination-plugins/gtm.ts
- webapps/console/lib/schema/destinations.tsx
I focused on runtime behavior around loadGtm, data layer initialization, and schema/default compatibility. I did not find actionable correctness or security issues in this range.
absorbb
added a commit
that referenced
this pull request
Jun 19, 2026
When `loadGtm` is enabled (default), Jitsu owns the data layer and keeps resetting the whole GTM data model between events via `this.reset()`. When `loadGtm === false` the client loads GTM itself and may keep its own persistent data-layer values that `reset()` would clobber. In that case, instead of resetting the entire model, push back only the keys Jitsu set this event with `null` values. This still prevents Jitsu event data from accumulating across events, but leaves data set outside Jitsu untouched. `event` is excluded from the clear (already consumed by the trigger), keeping the clearing push data-only so it doesn't fire event-based triggers. Builds on #1362 (the loadGtm option). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
absorbb
added a commit
that referenced
this pull request
Jun 19, 2026
When `loadGtm` is enabled (default), Jitsu owns the data layer and keeps resetting the whole GTM data model between events via `this.reset()`. When `loadGtm === false` the client loads GTM itself and may keep its own persistent data-layer values that `reset()` would clobber. In that case, instead of resetting the entire model, push back only the keys Jitsu set this event with `null` values. This still prevents Jitsu event data from accumulating across events, but leaves data set outside Jitsu untouched. `event` is excluded from the clear (already consumed by the trigger), keeping the clearing push data-only so it doesn't fire event-based triggers. Builds on #1362 (the loadGtm option). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
loadGtmoption to the Google Tag Manager device destination so customers can take over loading GTM themselves while still using the official destination.The GTM destination currently injects the GTM script lazily — only on the first event sent to it. For events fired right before a navigation (e.g. link clicks), this loses a race: the script hasn't loaded its tags/pixels by the time the browser navigates away, so the pixel never fires.
With this change, customers can load GTM on page load themselves (so tags are ready early) and set Load GTM = off. Jitsu then skips injecting the GTM script but still pushes
page_view/ track / identify events to the data layer, which the client-loaded container processes. This avoids having to reimplement the GTM destination as a generic Tag destination.Changes
libs/jitsu-js/src/destination-plugins/gtm.ts— addloadGtm?: booleantoGtmDestinationCredentials. IninitGtmIfNeeded, whenloadGtm === false, ensure the data layer exists and return early (skip script injection). Event-pushing logic is unchanged.webapps/console/lib/schema/destinations.tsx— expose a "Load GTM" toggle in the GTM destination config (z.boolean().default(true)).Compatibility
default(true)keeps this fully backward-compatible — existing destinations behave exactly as before. Only customers who load GTM themselves flip it off.Context
Requested by a customer in Slack (private channel C08UVQMET16). Tracked in the Notion task.
Testing notes
Follow-ups
🤖 Generated with Claude Code