Orphaned variables (not used by any tag or trigger)
Variables not referenced by any tag or trigger. Special public-scan handling: when ALL variables look orphaned from a public scan, emits a different finding suggesting JSON upload.
Summary
- rule_id —
orphaned-variables - purpose — Detect variables not referenced by any tag or trigger in the container
- effect — Orphaned variables add noise to the variable list and inflate published container size
- layer — container
- reversibility — non-destructive
What fires this
The rule filters data.variables for entries where both referencedByTags.length === 0 and referencedByTriggers.length === 0. A special case applies to public-endpoint scans: if all variables appear unreferenced and the container has more than five variables total, the rule assumes the public scan lacks sufficient data to trace usage. It emits a softer finding recommending a JSON export upload rather than treating every variable as orphaned. For JSON container exports, reference detection is accurate.
Why it matters
Variables accumulate when tags or trigger conditions are deleted without removing the variables they depended on. Over time, the variable list fills with entries that serve no active purpose. In containers using prefix-based naming conventions, orphaned variables with matching prefixes can mislead reviewers about which platforms or features are currently tracked. Variables also contribute to GTM's published container payload — removing unused ones keeps the container leaner and the variable list legible.
Before / after
Variable DLV - userId exists in the container but no tag references
it in its fields, and no trigger condition uses it. It was created for
a tag deleted six months ago and never cleaned up.
Variable deleted. Container variable list reflects only variables in active use. If the variable may return, add a description field documenting the intended purpose before archiving.
Remediation
- Review the orphaned variable list in the finding output.
- For each variable, check for indirect references: Custom JavaScript variables that call it by name, or Additional Consent configurations that reference it as a string.
- Delete variables confirmed to be unused.
- For variables kept for future use, add a description to the variable configuration explaining its intended purpose.
- Publish the updated container.
Metadata
- Severity
- medium
- Tier
- info
- Category
- organization
- Layer
- container
- Version
- 1
- Effort
15min(about 15 minutes)- Reversibility
- non-destructive
See also
- Organization 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":"orphaned-variables","url":"https://example.com"}'
User: Run orphaned-variables on https://example.com
# Tool call
{
"tool": "evaluate_rule",
"arguments": {
"rule_id": "orphaned-variables",
"url": "https://example.com"
}
}