Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Augment a shared global (like dataLayer) instead of overwriting it
Push onto an existing global array and guard its existence rather than reassigning it, which would clobber data other code set.
Bad example
| 1 | window.dataLayer = { event: 'pageview' }; |
Explanation (EN)
Replacing the queue discards events another script already recorded.
Objašnjenje (HR)
Good example
| 1 | window.dataLayer = window.dataLayer || []; |
| 2 | window.dataLayer.push({ event: 'pageview' }); |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For a documented shared global queue, preserve the existing valid queue and append through its supported interface. Check initialization order and the expected value shape.
Exceptions / Tradeoffs (EN)
Do not silently treat an arbitrary truthy object as an array; follow the owner's contract for invalid or preinitialized values. Do not expose secrets in analytics events.