Skip to content

Commit b8ffcef

Browse files
fix: Remove global GTM container on private booking page. (calcom#21490)
* add route filter to inject script * update middleware for pathname as Referer might not work all time * move d to (booking-page-wrapper) instead of route filter and change in middleware * add e2e tests
1 parent 999882b commit b8ffcef

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

apps/web/app/(use-page-wrapper)/d/[link]/[slug]/page.tsx renamed to apps/web/app/(booking-page-wrapper)/d/[link]/[slug]/page.tsx

File renamed without changes.

apps/web/playwright/booking-pages.e2e.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from "@playwright/test";
22
import { JSDOM } from "jsdom";
33

44
import { WEBAPP_URL } from "@calcom/lib/constants";
5+
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
56
import { randomString } from "@calcom/lib/random";
67
import { SchedulingType } from "@calcom/prisma/client";
78
import type { Schedule, TimeRange } from "@calcom/types/schedule";
@@ -694,3 +695,63 @@ test("Should throw error when both seatsPerTimeSlot and recurringEvent are set",
694695
"Could not book the meeting. Recurring event doesn't support seats feature. Disable seats feature or make the event non-recurring."
695696
);
696697
});
698+
699+
test.describe("GTM container", () => {
700+
test.beforeEach(async ({ page, users }) => {
701+
await users.create();
702+
});
703+
704+
test("global GTM should not be loaded on private booking link", async ({ page, users, emails, prisma }) => {
705+
const [user] = users.get();
706+
const eventType = await user.getFirstEventAsOwner();
707+
708+
const eventWithPrivateLink = await prisma.eventType.update({
709+
where: {
710+
id: eventType.id,
711+
},
712+
data: {
713+
hashedLink: {
714+
create: [
715+
{
716+
link: generateHashedLink(eventType.id),
717+
},
718+
],
719+
},
720+
},
721+
include: {
722+
hashedLink: true,
723+
},
724+
});
725+
726+
const getScheduleRespPromise = page.waitForResponse(
727+
(response) => response.url().includes("getSchedule") && response.status() === 200
728+
);
729+
await page.goto(`/d/${eventWithPrivateLink.hashedLink[0]?.link}/${eventWithPrivateLink.slug}`);
730+
await page.waitForLoadState("domcontentloaded");
731+
await getScheduleRespPromise;
732+
733+
const injectedScript = page.locator('script[id="injected-body-script"]');
734+
await expect(injectedScript).not.toBeAttached();
735+
});
736+
737+
test("global GTM should be loaded on non-booking pages", async ({ page, users }) => {
738+
test.skip(!process.env.NEXT_PUBLIC_BODY_SCRIPTS, "Skipping test as NEXT_PUBLIC_BODY_SCRIPTS is not set");
739+
740+
const [user] = users.get();
741+
await user.apiLogin();
742+
743+
// Go to /insights page and wait for one of the common API call to complete
744+
const eventsByStatusRespPromise = page.waitForResponse(
745+
(response) => response.url().includes("getEventTypesFromGroup") && response.status() === 200
746+
);
747+
await page.goto(`/insights`);
748+
await page.waitForLoadState("domcontentloaded");
749+
await eventsByStatusRespPromise;
750+
751+
const injectedScript = page.locator('script[id="injected-body-script"]');
752+
await expect(injectedScript).toBeAttached();
753+
754+
const scriptContent = await injectedScript.textContent();
755+
expect(scriptContent).toContain("googletagmanager");
756+
});
757+
});

0 commit comments

Comments
 (0)