dataLayer.push race condition
Multiple Custom HTML tags push to dataLayer on the same trigger without priority ordering, creating timing-dependent behavior.
Summary
- rule_id —
tag-datalayer-race - purpose — Detect Custom HTML tags that push to the dataLayer on the same trigger with no firing priority set
- effect — Execution order is undefined; tags depending on each other's dataLayer entries may read stale or missing data
- layer — container
- reversibility — non-destructive
What fires this
The rule collects all active Custom HTML tags where codeAnalysis.hasDataLayerPush is true. Tags that install event listeners are skipped — their dataLayer.push runs inside a callback, not synchronously at tag fire, so sibling-ordering is not the issue. The remaining tags are grouped by firingTriggerIds. Any trigger where two or more tags in that group have no priority value set is flagged as a race. Paused tags are excluded.
Why it matters
GTM does not guarantee execution order when multiple tags share a trigger. If Tag A pushes user context and Tag B reads that context to populate an analytics event, Tag B may execute first — sending the event with empty or stale fields. The failure is silent: both tags show a green tick in GTM Preview, but the downstream analytics row is missing data. GTM's tag firing priority field (higher numbers fire first) exists to fix this, but it requires explicit configuration.
Before / after
Trigger: "All Pages"
└── Tag A — "DL - Set User Context" priority: (none)
└── Tag B — "DL - Enrich Event Data" priority: (none)
Tag B may read user context before Tag A has pushed it.
Trigger: "All Pages"
└── Tag A — "DL - Set User Context" priority: 10
└── Tag B — "DL - Enrich Event Data" priority: 0
Tag A always fires first; Tag B reads a populated dataLayer.
Remediation
- Review the flagged trigger groups in the finding — each group lists the tags sharing a trigger.
- Determine which tag must push first. A tag that writes context others read should fire earlier.
- Open each tag in GTM and go to Advanced Settings → Tag Firing Priority.
- Assign a higher priority number to the tag that must fire first (e.g.,
10). Leave dependent tags at0. - For tags whose pushes are genuinely independent, confirm they do not read each other's keys. No priority change is needed; add a comment in the tag notes documenting this.
- Verify order in GTM Preview by checking the Summary panel tag sequence.
Metadata
- Severity
- medium
- Tier
- optimization
- Category
- quality
- Layer
- container
- Version
- 1
- Effort
15min(about 15 minutes)- Reversibility
- non-destructive
See also
- Quality rules — other rules in this category
- Health score — how this rule contributes to the score
- Rules catalog — browse all rules
Examples
curl https://developer.tagmanifest.com/v1/evaluate-rule \
-H "Authorization: Bearer $TM_API_KEY" \
-H "Content-Type: application/json" \
-d '{"rule_id":"tag-datalayer-race","url":"https://example.com"}'
User: Run tag-datalayer-race on https://example.com
# Tool call
{
"tool": "evaluate_rule",
"arguments": {
"rule_id": "tag-datalayer-race",
"url": "https://example.com"
}
}