Skip to content

fix(gtm): Fix cookie parsing from getCookieValues()#27

Open
gido wants to merge 1 commit intomainfrom
fix/gtm-cookie-parsing
Open

fix(gtm): Fix cookie parsing from getCookieValues()#27
gido wants to merge 1 commit intomainfrom
fix/gtm-cookie-parsing

Conversation

@gido
Copy link
Copy Markdown
Member

@gido gido commented Feb 27, 2026

Description

getCookieValues() returns an array of matching cookie values, but the code was passing the entire array directly to JSON.parse(). This caused consent state not to be restored from the cookie on page load.

The fix checks the array length and parses only the first element (cookieValues[0]).

No more Unexpected end of JSON input error.

- Why: getCookieValues() returns an array, but the old code passed it directly to JSON.parse(), causing parsing failures when reading existing consent
- What: Check array length before parsing, and parse only the first element (cookieValues[0])
- Context: Fix applied to both gtm-tag-template.js and gtm-tag-template.tpl
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
leckerli Building Building Preview, Comment Feb 27, 2026 8:55am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant