@@ -2,6 +2,7 @@ import { expect } from "@playwright/test";
22import { JSDOM } from "jsdom" ;
33
44import { WEBAPP_URL } from "@calcom/lib/constants" ;
5+ import { generateHashedLink } from "@calcom/lib/generateHashedLink" ;
56import { randomString } from "@calcom/lib/random" ;
67import { SchedulingType } from "@calcom/prisma/client" ;
78import 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