-
Notifications
You must be signed in to change notification settings - Fork 10.4k
fix: Remove global GTM container on private booking page. #21490
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
fix: Remove global GTM container on private booking page. #21490
Conversation
@vijayraghav-io is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
Graphite Automations"Add community label" took an action on this PR • (05/23/25)1 label was added to this PR based on Keith Williams's automation. "Add ready-for-e2e label" took an action on this PR • (05/25/25)1 label was added to this PR based on Keith Williams's automation. |
@hariombalhara , Kindly review. |
Allowing catch all paths in existing middleware requires to whitelist certain paths. So, switched to other method of moving |
Added e2e tests : test - "global GTM should not be loaded on private booking link" - verifies the script with id= test - "global GTM should be loaded on non-booking pages" - verifies that the current PR changes will not affected the GTM script being loaded on Non-booking pages. Given the script is injected through env. Verified both tests |
…_on_privatelinks
}); | ||
|
||
test("global GTM should be loaded on non-booking pages", async ({ page, users }) => { | ||
test.skip(!process.env.NEXT_PUBLIC_BODY_SCRIPTS, "Skipping test as NEXT_PUBLIC_BODY_SCRIPTS is not set"); |
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.
This test can be best tested if envNEXT_PUBLIC_BODY_SCRIPTS=
is assigned with a value as described in the PR description.
By permanently assigning a value for testing purpose inside .env.example, for the above variable, has some implications -
- All Non-Booking routes will have
gtm.js
loaded , all these related test executions will be impacted as an additional external API call will be made always. This may result in increasing the test execution time.
Locally this test alone can be tested with .only and appending the value for the above env variable, for verification without skipping test.
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.
Great fix @vijayraghav-io 🙏
Thank you! @hariombalhara 🙏 |
E2E results are ready! |
@hariombalhara , all tests are passing 🙏 |
What does this PR do?
Root cause
Layout -
apps/web/app/(use-page-wrapper)/layout.tsx
where global GTM container scripts are injected through env.This layout also wraps the
apps/web/app/(use-page-wrapper)/d/[link]/[slug]/page.tsx
(private booking page)Hence the gtm.js is loaded for private booking page.
Implemented solution
Move the
d/[link]/[slug]/page.tsx
to under(booking-page-wrapper)
Alternate solution
Apply a route/path based filter in (use-page-wrapper)/layout.tsx , to not inject scripts for /d/[link]/[slug]/page.tsx
For this the exact pathname has to be detected.
h.get('Referer) will not work all the time.
So we need to append a header like
x-pathname
in middleware. This requires to allowall paths
to middleware.We can create a parallel middleware without modifying existing middleware.
The new middleware allows all paths and only appends the
x-pathname
fromreq.nextUrl.pathname
.The performance implications of all requests or paths reaching middleware has to be considered.
Visual Demo (For contributors especially)
Video Demo (if applicable):
Before Changes - https://www.loom.com/share/93edfb9104fb445bb329946631e7df87?sid=95f1ce78-7133-43f8-8b7c-98fa9b74a9a8
After Changes - https://www.loom.com/share/a89aefbf16f94ecb8cf17be798a7515c?sid=a0ef0fc8-8cce-4e70-8a35-38e50d9f53f9
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
In .env
Set NEXT_PUBLIC_BODY_SCRIPTS=(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-PV22BDLZ');
Create a private booking link for any event. (Edit -> EventType -> Advanced Tab -> Private links)
Visit this link, gtm.js should not be loaded when checked in network tab
Also check the script with id =
injected-body-script
should not be loaded inside the html bodyVisit any other page (except booking pages), the gtm.js should be loaded.
Summary by cubic
Stopped the Google Tag Manager script from loading on private booking links to protect user privacy.