Skip to content

Wrong type on GoogleTagManager component's dataLayer prop #64364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dsosborn opened this issue Apr 11, 2024 · 1 comment · Fixed by #66339
Closed

Wrong type on GoogleTagManager component's dataLayer prop #64364

dsosborn opened this issue Apr 11, 2024 · 1 comment · Fixed by #66339
Labels
bug Issue was opened via the bug report template. locked Script (next/script) Related to Next.js Script Optimization.

Comments

@dsosborn
Copy link

dsosborn commented Apr 11, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/zealous-chebyshev-5xchpd?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522cls64pckf00063b6haq462fij%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522cls64pckf00023b6hrn38v72w%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522cls64pckf00043b6hmkzrlp5v%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522cls64pckf00053b6hnzqzhs7v%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522cls64pckf00023b6hrn38v72w%2522%253A%257B%2522id%2522%253A%2522cls64pckf00023b6hrn38v72w%2522%252C%2522activeTabId%2522%253A%2522cluvmkz7200e83b6i7zccgfg1%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cls64pcke00013b6h9kjaax4k%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252F.codesandbox%252Ftasks.json%2522%252C%2522id%2522%253A%2522cluvmkz7200e83b6i7zccgfg1%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%257D%252C%2522cls64pckf00053b6hnzqzhs7v%2522%253A%257B%2522id%2522%253A%2522cls64pckf00053b6hnzqzhs7v%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_PORT%2522%252C%2522port%2522%253A3000%252C%2522taskId%2522%253A%2522dev%2522%252C%2522id%2522%253A%2522cluvll7nt006j3b6ixzkiilwk%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522activeTabId%2522%253A%2522cluvll7nt006j3b6ixzkiilwk%2522%257D%252C%2522cls64pckf00043b6hmkzrlp5v%2522%253A%257B%2522id%2522%253A%2522cls64pckf00043b6hmkzrlp5v%2522%252C%2522activeTabId%2522%253A%2522cluvmjvp800c93b6i0iq6y9t2%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522id%2522%253A%2522cluvmjvp800c93b6i0iq6y9t2%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

To Reproduce

Use GoogleTagManager component with dataLayer prop:

<GoogleTagManager dataLayer={{ websiteEnv: environment }}  gtmId="12345" />

Current vs. Expected behavior

In order to populate a variable to the dataLayer, it has to have an object pushed to it. Putting an array of strings into this prop doesn't do anything in GTM. Adding dataLayer={{websiteEnv:"dev"}} successfully populates the GTM variable, but is flagged by Typescript, because the props are typed as:

export type GTMParams = {
    gtmId: string;
    dataLayer?: string[];
    dataLayerName?: string;
    auth?: string;
    preview?: string;
};

I would expect GTMParams dataLayer prop type to be something like {[key: string]: string}

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:31 PST 2024; root:xnu-10063.101.15~2/RELEASE_X86_64
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.1.1
  eslint-config-next: 14.1.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

App Router, Script optimization (next/script)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

Tested with @next/[email protected]

@dsosborn dsosborn added the bug Issue was opened via the bug report template. label Apr 11, 2024
@github-actions github-actions bot added the Script (next/script) Related to Next.js Script Optimization. label Apr 11, 2024
@samcx samcx closed this as completed in 510ddbe Jul 25, 2024
Copy link
Contributor

github-actions bot commented Aug 9, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Aug 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2024
lubieowoce pushed a commit that referenced this issue Aug 22, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
lubieowoce pushed a commit that referenced this issue Aug 22, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
lubieowoce pushed a commit that referenced this issue Aug 22, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
lubieowoce pushed a commit that referenced this issue Aug 22, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
lubieowoce pushed a commit that referenced this issue Aug 22, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
lubieowoce pushed a commit that referenced this issue Aug 22, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
lubieowoce pushed a commit that referenced this issue Aug 23, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
ztanner pushed a commit that referenced this issue Aug 26, 2024
#66339)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

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 <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked Script (next/script) Related to Next.js Script Optimization.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant