diff --git a/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts b/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts index bd5bc8746..6458474ff 100644 --- a/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts +++ b/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts @@ -48,7 +48,7 @@ describe(matchHostname, () => { setLocation({ hostname: 'api.example.com' }) expect(matchHostname('https://api.example.com/foo')).toBe(true) expect(matchHostname('https://foo.com/foo')).toBe(false) - expect(matchHostname('https://example.com/foo')).toBe(false) + expect(matchHostname('https://example.com/foo')).toBe(true) }) it('should always allow relative domains', () => { @@ -56,6 +56,15 @@ describe(matchHostname, () => { expect(matchHostname('foo/bar')).toBe(true) expect(matchHostname('foo')).toBe(true) }) + + it('should handle www differences', () => { + setLocation({ hostname: 'foo.previews.console.stage.twilio.com' }) + expect( + matchHostname( + 'https://www.stage.twilio.com/console/billing/api/v3/add-funds' + ) + ).toBe(true) + }) }) describe(addFetchInterceptor, () => { diff --git a/packages/signals/signals/src/core/signal-generators/network-gen.ts b/packages/signals/signals/src/core/signal-generators/network-gen.ts index e387e8ca6..967bd8298 100644 --- a/packages/signals/signals/src/core/signal-generators/network-gen.ts +++ b/packages/signals/signals/src/core/signal-generators/network-gen.ts @@ -33,7 +33,10 @@ export const matchHostname = (url: string): boolean => { // Relative URL will go to this host return true } - return new URL(url).hostname.includes(window.location.hostname) + + const clean = new URL(url).hostname.replace('www.', '') + const current = window.location.hostname.replace('www.', '') + return clean.includes(current) || current.includes(clean) } const normalizeHeaders = (headers: HeadersInit): Headers => { diff --git a/packages/signals/signals/webpack.config.js b/packages/signals/signals/webpack.config.js index 0fc128c40..0c3cd92a7 100644 --- a/packages/signals/signals/webpack.config.js +++ b/packages/signals/signals/webpack.config.js @@ -14,6 +14,12 @@ module.exports = merge(common, { type: 'umd', }, }, + 'analytics-signals.global': { + import: path.resolve(__dirname, 'src/index.ts'), + library: { + type: 'window', + }, + }, }, output: { filename: isProd ? '[name].js' : '[name].development.js',