-
Notifications
You must be signed in to change notification settings - Fork 58
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
feat(gtm): update GTM snippet #2209
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@dewen is attempting to deploy a commit to the JNJ Demo Account Team on Vercel. A member of the Team first needs to authorize it. |
Thank you for creating a pull request on GitHub! We appreciate your contribution to our repository. In order to enable our tests to run on your changes, we kindly ask that you wait until one of our repository members adds the ready-to-test label to your pull request. (Please request on the GitHub issue you are addressing.) This will ensure that our testing process runs smoothly and we can quickly verify the changes you've made. Thank you for your understanding and we look forward to reviewing your changes soon! |
…S into feat/update-gtm-snippet
sites/vital-demo-next/.env.site
Outdated
@@ -77,3 +77,6 @@ BODILESS_GENERATED_DESTINATION_PATH='generated' | |||
BODILESS_STATS_PATH='./public/generated' | |||
BODILESS_BUILD_STATS=1 | |||
# BODILESS_OPEN_STATS=1 | |||
|
|||
GTM_ID='GTM-WSPHT2V' | |||
GTM_DATA_LAYER='dataLayer' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NextJS strip the environment variables from frontend unless prefixed by NEXT_ or added to the public environment variables in nextJS config, @bodiless/next preconfigure the public env variables here https://github.com/johnsonandjohnson/Bodiless-JS/blob/main/packages/bodiless-next/src/NextConfig/getPublicEnv.ts#L34
I suggest to add those two variables to the list
); | ||
const id = process.env.GTM_ID || 'GTM-XXXXXX'; | ||
const dataLayerName = process.env.GTM_DATA_LAYER || 'dataLayer'; | ||
documentProps.PostHead = generateGTMScript(id, dataLayerName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of adding the script in this way, why not create an HOC in @bodiless/next which check if the env variable exists, generates the script and add it to the page using React Helmet, like we do for Canonical URL? https://github.com/johnsonandjohnson/Bodiless-JS/blob/main/packages/bodiless-next/src/Page.static.tsx#L50
In this way the setup at site level would be simplest, just define the env variables and optionally add the no script tag when required
sites/vital-demo-next/package.json
Outdated
@@ -22,6 +22,7 @@ | |||
"@bodiless/fclasses": "^1.0.0-rc.42", | |||
"@bodiless/ga4": "^1.0.0-rc.42", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dewen why readd the @bodiless/ga4 ? its at line 23 & line 25
Changes
Test Instructions
Related Issues