|
8 | 8 | trackGoogleEvent, |
9 | 9 | trackGooglePageView, |
10 | 10 | } from '@/lib/analytics/google' |
11 | | -import { getGooglePageLocation } from '@/lib/consent/google-context' |
| 11 | +import { getGooglePageLocation, updateGooglePageContext } from '@/lib/consent/google-context' |
12 | 12 | import { |
13 | 13 | type ConsentScriptCallbackInfo, |
14 | 14 | GOOGLE_ADS_ID, |
@@ -101,6 +101,53 @@ describe('consent scripts', () => { |
101 | 101 | expect(getGooglePageLocation('https://www.sim.ai/library')).toBeUndefined() |
102 | 102 | }) |
103 | 103 |
|
| 104 | + it.each(['/extension', '/extension/o/org-id', '/%65xtension/workspace-id'])( |
| 105 | + 'does not register third-party tracking scripts for %s', |
| 106 | + (path) => { |
| 107 | + window.history.replaceState({}, '', path) |
| 108 | + |
| 109 | + expect(getGlobalConsentScripts()).toEqual([]) |
| 110 | + expect(getGooglePageLocation(window.location.href)).toBeUndefined() |
| 111 | + } |
| 112 | + ) |
| 113 | + |
| 114 | + it('stops Google events when navigating into the extension and resumes on public pages', () => { |
| 115 | + window.history.replaceState({}, '', '/library') |
| 116 | + getGlobalConsentScripts()[0]?.onBeforeLoad?.(CALLBACK_INFO) |
| 117 | + window.dataLayer = [] |
| 118 | + window.history.pushState({}, '', '/extension/o/private-org?utm_source=google') |
| 119 | + |
| 120 | + trackGooglePageView('/extension/o/private-org') |
| 121 | + trackGoogleEvent('sign_up', { method: 'email' }) |
| 122 | + trackGoogleAdsConversion('demo_booked') |
| 123 | + |
| 124 | + expect(window.dataLayer).toEqual([]) |
| 125 | + |
| 126 | + window.history.pushState({}, '', '/extension-guide') |
| 127 | + trackGooglePageView('/extension-guide') |
| 128 | + expect(window.dataLayer).toContainEqual([ |
| 129 | + 'event', |
| 130 | + 'page_view', |
| 131 | + { |
| 132 | + page_path: '/extension-guide', |
| 133 | + page_location: 'https://www.sim.ai/extension-guide', |
| 134 | + send_to: GOOGLE_ANALYTICS_ID, |
| 135 | + }, |
| 136 | + ]) |
| 137 | + }) |
| 138 | + |
| 139 | + it('removes extension scope IDs from referrals to public pages', () => { |
| 140 | + window.history.replaceState({}, '', '/library') |
| 141 | + getGlobalConsentScripts()[0]?.onBeforeLoad?.(CALLBACK_INFO) |
| 142 | + |
| 143 | + updateGooglePageContext(window.location.href, 'https://www.sim.ai/extension/o/private-org') |
| 144 | + |
| 145 | + expect(window.dataLayer.at(-1)).toEqual([ |
| 146 | + 'set', |
| 147 | + expect.objectContaining({ page_referrer: 'https://www.sim.ai/extension' }), |
| 148 | + ]) |
| 149 | + }) |
| 150 | + |
104 | 151 | it('keeps supported campaign parameters and removes unknown parameters and fragments', () => { |
105 | 152 | expect( |
106 | 153 | getGooglePageLocation( |
|
0 commit comments