From 26c80eeb16bb4f47784b168cb25fb0095a2d1259 Mon Sep 17 00:00:00 2001 From: Ian Marlier Date: Thu, 25 Jul 2024 16:37:13 -0400 Subject: [PATCH] GTM dataLayer parameter should take an object, not an array of strings (#66339) fixes #64364 As noted in the bug, the `dataLayer` parameter to the GoogleTagManager third-party component should be an object (which gets passed to `JSON.stringify()` at https://github.com/vercel/next.js/blob/canary/packages/third-parties/src/google/gtm.tsx#L43), and not an array of strings. (I'm speculating a bit, but assuming that the original intent was that an object could be serialized and passed to the component, but then the call to stringify was added to the component as well.) I'm not thrilled about duplicating the JSONValue type, which also exists in `packages/next/src/server/config-shared.ts`, but wasn't sure whether it would be preferred to export from there -- this doesn't feel like it's likely to be an issue, but I'm perfectly happy to change --------- Co-authored-by: Sam Ko --- packages/third-parties/src/types/google.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/third-parties/src/types/google.ts b/packages/third-parties/src/types/google.ts index 30a4e9f28a464..aaae926d2a5c6 100644 --- a/packages/third-parties/src/types/google.ts +++ b/packages/third-parties/src/types/google.ts @@ -5,9 +5,16 @@ declare global { } } +type JSONValue = + | string + | number + | boolean + | JSONValue[] + | { [key: string]: JSONValue } + export type GTMParams = { gtmId: string - dataLayer?: string[] + dataLayer?: { [key: string]: JSONValue } dataLayerName?: string auth?: string preview?: string