UNPKG

@unifygtm/intent-client

Version:

JavaScript client for interacting with the Unify Intent API in the browser.

37 lines (30 loc) 1 kB
import { AnalyticsEventType, PageEventData, PageEventOptions, UnifyIntentContext, } from '../../types'; import { UNIFY_INTENT_V1_URL } from '../constants'; import { getCurrentPageProperties } from '../utils/helpers'; import Activity from './activity'; export const UNIFY_INTENT_PAGE_URL = `${UNIFY_INTENT_V1_URL}/page`; /** * Activity for logging a `page` event via the Unify Intent Client. */ export class PageActivity extends Activity<PageEventData> { private readonly _options?: PageEventOptions; constructor(intentContext: UnifyIntentContext, options?: PageEventOptions) { super(intentContext); this._options = options; } protected getActivityType(): AnalyticsEventType { return 'page' as PageEventData['type']; } protected getActivityURL(): string { return UNIFY_INTENT_PAGE_URL; } protected getActivityData = (): PageEventData => ({ type: 'page' as PageEventData['type'], properties: getCurrentPageProperties(this._options?.pathname), }); }