Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Page counter fix #670

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export const pageViewTrackingPlugin: CreatePageViewTrackingPlugin = (options: Op
const globalScope = getGlobalScope();
let loggerProvider: Logger | undefined = undefined;
let pushState: undefined | ((data: any, unused: string, url?: string | URL | null) => void);
let pageCounter: number;
let localConfig: BrowserConfig;

const createPageViewEvent = async (): Promise<Event> => {
localConfig.pageCounter = !localConfig.pageCounter ? 1 : localConfig.pageCounter + 1;
return {
event_type: options.eventType ?? '[Amplitude] Page Viewed',
event_properties: {
Expand All @@ -33,7 +34,7 @@ export const pageViewTrackingPlugin: CreatePageViewTrackingPlugin = (options: Op
'[Amplitude] Page Title': /* istanbul ignore next */ (typeof document !== 'undefined' && document.title) || '',
'[Amplitude] Page URL':
/* istanbul ignore next */ (typeof location !== 'undefined' && location.href.split('?')[0]) || '',
'[Amplitude] Page Counter': pageCounter,
'[Amplitude] Page Counter': localConfig.pageCounter,
},
};
};
Expand Down Expand Up @@ -72,13 +73,11 @@ export const pageViewTrackingPlugin: CreatePageViewTrackingPlugin = (options: Op

setup: async (config: BrowserConfig, client: BrowserClient) => {
amplitude = client;
localConfig = config;

loggerProvider = config.loggerProvider;
loggerProvider.log('Installing @amplitude/plugin-page-view-tracking-browser');

config.pageCounter = !config.pageCounter ? 1 : config.pageCounter + 1;
pageCounter = config.pageCounter;

if (globalScope) {
globalScope.addEventListener('popstate', trackHistoryPageViewWrapper);

Expand Down
Loading