Skip to content

GTM: gtag function pushes a plain Array to dataLayer; Consent Mode misread by GTM #770

@buffalom

Description

@buffalom

🐛 The bug

useScriptGoogleTagManager defines a small gtag helper that forwards calls to dataLayer.push. In @nuxt/scripts v1.x that helper uses rest parameters and pushes args – a real Array.

Google’s install snippet (and what GTM expects) is dataLayer.push(arguments) inside a non-arrow function gtag() { … }, i.e. the Arguments object.

So consent (and other gtag-shaped commands) can look correct in the console (["consent", "default", …]) but do not behave like real gtag traffic in tooling:

  • Google Analytics Debugger (Chrome extension) shows generic (message) instead of consent → default / consent → update.
  • Tag Assistant reports “Consent not configured” even when you see consent-like rows in dataLayer.

This describes the bug experienced in discussion #745. The regression is 9efc16f (GTM gtag switched from pushing arguments to pushing the spread array).

🛠️ To reproduce

https://stackblitz.com/edit/nuxt-starter-ikfzuls3?file=EXPLANATION.md

🌈 Expected behavior

  • Any gtag('consent', 'default', …) (and other calls through the window.gtag) should enqueue the same shape as the official snippet: dataLayer.push(arguments), not a spread-created Array.
  • In DevTools, those rows should appear as Arguments(3) […] (or equivalent), not (3) […] as a normal array.
  • Google Analytics Debugger (and Tag Assistant when used) should show structured consent → default / consent → update for those rows, consistent with native GTM.

Literal dataLayer.push(['consent', 'update', state]) from consent.update() may remain a real array; that documented form is separate from the gtag() function.

ℹ️ Additional context

  • Discussion #745 – describing the initial experience of this bug.
  • Screenshot: side-by-side @nuxt/scripts@1.0.6 (left) vs a branch that restores push(arguments) – console shows (3) vs Arguments(3), GA Debugger shows (message) vs consent → default / consent → update.
    Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions