diff --git a/packages/analytics-js-integrations/rollup.config.mjs b/packages/analytics-js-integrations/rollup.config.mjs index 787207ecf..1714bafe9 100644 --- a/packages/analytics-js-integrations/rollup.config.mjs +++ b/packages/analytics-js-integrations/rollup.config.mjs @@ -1,4 +1,5 @@ /* eslint-disable import/no-extraneous-dependencies */ +import path from "path"; import babel from '@rollup/plugin-babel'; import commonjs from '@rollup/plugin-commonjs'; import resolve from '@rollup/plugin-node-resolve'; @@ -10,6 +11,7 @@ import filesize from 'rollup-plugin-filesize'; import typescript from 'rollup-plugin-typescript2'; import nodePolyfills from 'rollup-plugin-polyfill-node'; import { DEFAULT_EXTENSIONS } from '@babel/core'; +import alias from '@rollup/plugin-alias'; import * as dotenv from 'dotenv'; import pkg from './package.json' assert { type: 'json' }; @@ -68,6 +70,14 @@ export function getDefaultConfig(distName, moduleType = 'cdn') { __PACKAGE_VERSION__: version, __MODULE_TYPE__: moduleType, }), + alias({ + entries: [ + { + find: '@rudderstack/analytics-js-common', + replacement: path.resolve('../analytics-js-common/src'), + } + ] + }), nodePolyfills(), resolve({ jsnext: true, diff --git a/packages/analytics-js/src/components/capabilitiesManager/CapabilitiesManager.ts b/packages/analytics-js/src/components/capabilitiesManager/CapabilitiesManager.ts index 76e6d213d..d686480a6 100644 --- a/packages/analytics-js/src/components/capabilitiesManager/CapabilitiesManager.ts +++ b/packages/analytics-js/src/components/capabilitiesManager/CapabilitiesManager.ts @@ -94,14 +94,7 @@ class CapabilitiesManager implements ICapabilitiesManager { } // Get page properties details - const pageProperties = getDefaultPageProperties(); - state.page.path.value = pageProperties.path; - state.page.referrer.value = pageProperties.referrer; - state.page.referring_domain.value = pageProperties.referring_domain; - state.page.search.value = pageProperties.search; - state.page.title.value = pageProperties.title; - state.page.url.value = pageProperties.url; - state.page.tab_url.value = pageProperties.tab_url; + this.getPageProperties(); }); // Ad blocker detection @@ -115,6 +108,24 @@ class CapabilitiesManager implements ICapabilitiesManager { }); } + /** + * Get page properties details to use in event context + */ + // eslint-disable-next-line class-methods-use-this + getPageProperties() { + const pageProperties = getDefaultPageProperties(); + + batch(() => { + state.page.path.value = pageProperties.path; + state.page.referrer.value = pageProperties.referrer; + state.page.referring_domain.value = pageProperties.referring_domain; + state.page.search.value = pageProperties.search; + state.page.title.value = pageProperties.title; + state.page.url.value = pageProperties.url; + state.page.tab_url.value = pageProperties.tab_url; + }); + } + /** * Detect if polyfills are required and then load script from polyfill URL */ @@ -155,6 +166,10 @@ class CapabilitiesManager implements ICapabilitiesManager { state.capabilities.isOnline.value = true; }); + globalThis.addEventListener('popstate', () => { + this.getPageProperties(); + }); + // TODO: add debounced listener for globalThis.onResize event and update state.context.screen.value } diff --git a/packages/analytics-js/src/components/capabilitiesManager/types.ts b/packages/analytics-js/src/components/capabilitiesManager/types.ts index 49a7db4a4..c3d1e79bb 100644 --- a/packages/analytics-js/src/components/capabilitiesManager/types.ts +++ b/packages/analytics-js/src/components/capabilitiesManager/types.ts @@ -8,6 +8,7 @@ export interface ICapabilitiesManager { externalSrcLoader?: IExternalSrcLoader; init(): void; detectBrowserCapabilities(): void; + getPageProperties(): void; prepareBrowserCapabilities(): void; attachWindowListeners(): void; onReady(): void;