diff --git a/packages/browser-destinations/destinations/hubspot-web/src/__tests__/index.test.ts b/packages/browser-destinations/destinations/hubspot-web/src/__tests__/index.test.ts index fdcb5c06e07..f5985aa8985 100644 --- a/packages/browser-destinations/destinations/hubspot-web/src/__tests__/index.test.ts +++ b/packages/browser-destinations/destinations/hubspot-web/src/__tests__/index.test.ts @@ -37,6 +37,19 @@ describe('Hubspot Web (Actions)', () => { expect(window.hbspt).toBeUndefined() }) + test('loads hubspot script with id=hs-script-loader to prevent duplicate script injection', async () => { + const [event] = await hubspotDestination({ + portalId: '12345', + subscriptions + }) + + await event.load(Context.system(), {} as Analytics) + + const loaderScripts = Array.from(document.querySelectorAll('script#hs-script-loader')) + expect(loaderScripts).toHaveLength(1) + expect(loaderScripts[0].getAttribute('src')).toBe('https://js.hs-scripts.com/12345.js') + }) + test('loads hubspot analytics with EU script', async () => { const [event] = await hubspotDestination({ portalId: '12345', diff --git a/packages/browser-destinations/destinations/hubspot-web/src/index.ts b/packages/browser-destinations/destinations/hubspot-web/src/index.ts index d327613318e..def10b6440c 100644 --- a/packages/browser-destinations/destinations/hubspot-web/src/index.ts +++ b/packages/browser-destinations/destinations/hubspot-web/src/index.ts @@ -92,7 +92,7 @@ export const destination: BrowserDestinationDefinition = { ? 'https://js-eu1.hsforms.net/forms/v2.js' : 'https://js.hsforms.net/forms/v2.js' - await deps.loadScript(scriptPath) + await deps.loadScript(scriptPath, { id: 'hs-script-loader' }) if (settings.loadFormsSDK) { await deps.loadScript(formsScriptPath) }