Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dewen
Copy link
Collaborator

@dewen dewen commented Aug 21, 2023

Changes

Test Instructions

Related Issues

@vercel
Copy link

vercel bot commented Aug 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bodiless-js ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 22, 2023 6:33pm
bodiless-js-examples ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 22, 2023 6:33pm
bodiless-js-gatsby ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 22, 2023 6:33pm
bodiless-js-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 22, 2023 6:33pm
bodiless-js-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 22, 2023 6:33pm

@vercel
Copy link

vercel bot commented Aug 21, 2023

@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.

@github-actions
Copy link

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!

@@ -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'
Copy link
Collaborator

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);
Copy link
Collaborator

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

@@ -22,6 +22,7 @@
"@bodiless/fclasses": "^1.0.0-rc.42",
"@bodiless/ga4": "^1.0.0-rc.42",
Copy link
Collaborator

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

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.

None yet

4 participants