Skip to content

GTM destination: configurable data layer reset (resetDataLayer + per-key clear for self-loaded GTM) - #1363

Merged
absorbb merged 3 commits into
newjitsufrom
feat/newjitsu/gtm-self-load-clear
Jun 19, 2026
Merged

GTM destination: configurable data layer reset (resetDataLayer + per-key clear for self-loaded GTM)#1363
absorbb merged 3 commits into
newjitsufrom
feat/newjitsu/gtm-self-load-clear

Conversation

@absorbb

@absorbb absorbb commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes the GTM destination's between-event data-layer clearing configurable, and makes it safer when the client loads GTM itself.

GTM keeps a single merged data model for the page; every push deep-merges its keys in and they persist until overwritten or cleared. The plugin previously always cleared this with this.reset() (wiping the entire model). This PR adds control over that.

New option: resetDataLayer (default true)

  • true (default): Jitsu clears the data it pushed after each event so values don't leak into later, unrelated events. Backward-compatible.
  • false: Jitsu does no clearing — values persist across events. For integrators who rely on persistence or manage clearing themselves.

How clearing happens when enabled

  • Jitsu loads GTM (loadGtm default): unchanged — this.reset() (Jitsu owns the data layer).
  • Client loads GTM (loadGtm === false): instead of resetting everything, push back only the keys Jitsu set this event with null values (Google's documented per-key clearing pattern). Jitsu event data still doesn't accumulate, but data the client set outside Jitsu is left intact. event is excluded (already consumed by the trigger), keeping the push data-only so it won't fire event-based triggers.

Changes

  • libs/jitsu-js/src/destination-plugins/gtm.ts — add resetDataLayer to credentials; gate clearing on it; per-key null-clear vs full reset() based on loadGtm.
  • webapps/console/lib/schema/destinations.tsx — expose the resetDataLayer toggle in the GTM destination config with a description of when to disable it.

Testing notes

  • Not yet run locally (fresh worktree without workspace deps). Changes are small and self-contained.

🤖 Generated with Claude Code

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>
jitsu-code-review[bot]
jitsu-code-review Bot previously approved these changes Jun 19, 2026

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed libs/jitsu-js/src/destination-plugins/gtm.ts for correctness/regression risk around loadGtm behavior and dataLayer state handling.

I did not find actionable bugs or security issues in this change set. The branch between full reset() (Jitsu-managed GTM) and per-key null clearing (client-managed GTM) is coherent with the intended behavior, and key tracking is scoped to the event payload push.

Add an explicit `resetDataLayer` credential (default true) that controls
whether Jitsu clears the data it pushed after each event. GTM merges every
push into a single persistent data model, so without clearing, properties from
one event leak into subsequent, unrelated events.

When enabled (default), clearing behaves as before: a full `this.reset()` when
Jitsu loads GTM, or a per-key null-clear of just Jitsu's keys when the client
loads GTM (loadGtm === false). When disabled, Jitsu does no clearing and values
persist across events — for integrators who rely on that or manage clearing
themselves.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@absorbb absorbb changed the title GTM destination: clear only Jitsu keys (not reset) when client loads GTM GTM destination: configurable data layer reset (resetDataLayer + per-key clear for self-loaded GTM) Jun 19, 2026

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the GTM destination plugin changes and the matching console schema update for resetDataLayer. The overall direction looks good; I left two inline questions on behavior changes in the loadGtm=false cleanup path (null-clearing semantics and leaving event uncleared) to make sure they are intentional and won’t cause downstream tag regressions.

Comment thread libs/jitsu-js/src/destination-plugins/gtm.ts Outdated
Comment thread libs/jitsu-js/src/destination-plugins/gtm.ts Outdated

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the GTM destination changes in and the corresponding console schema update in .

I focused on behavior around and defaulting/branching, plus the user-facing config wiring. I did not find additional correctness, security, or regression issues beyond the existing open inline threads already on this PR.

jitsu-code-review[bot]
jitsu-code-review Bot previously approved these changes Jun 19, 2026

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the GTM destination plugin changes in libs/jitsu-js/src/destination-plugins/gtm.ts and the matching schema changes in webapps/console/lib/schema/destinations.tsx.

Focus areas: correctness and regressions in loadGtm=false behavior, resetDataLayer default/branching, and user-facing config wiring. No additional actionable bugs or security issues were found beyond the existing open inline threads already on this PR.

Address review feedback on the loadGtm=false clear path:

- Clear keys to `undefined` instead of `null`, so data-layer variables read
  them as "missing" — matching the reset() path the previous behavior used
  (avoids a visible missing-vs-null difference for tags/variables).
- Also clear `event` (previously skipped) so a stale event name doesn't linger
  in the model until the next push. Since the value becomes undefined, GTM
  still treats this as a data-only push and won't re-fire event-based triggers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and , with focus on the new GTM data-layer reset behavior for self-loaded GTM and the added destination credential surface.

I didn’t find additional actionable bugs, security issues, or correctness regressions in this range.

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed libs/jitsu-js/src/destination-plugins/gtm.ts and webapps/console/lib/schema/destinations.tsx, with focus on the new GTM data-layer reset behavior for self-loaded GTM and the added destination credential surface.

I didn’t find additional actionable bugs, security issues, or correctness regressions in this range.

@absorbb
absorbb merged commit 078aa23 into newjitsu Jun 19, 2026
5 checks passed
@absorbb
absorbb deleted the feat/newjitsu/gtm-self-load-clear branch June 19, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant