@metamask-previews/analytics-controller 2.0.0-preview-fe4b3be11 → 2.1.0-preview-2f57247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -1
- package/README.md +46 -5
- package/dist/AnalyticsController-method-action-types.cjs.map +1 -1
- package/dist/AnalyticsController-method-action-types.d.cts +106 -2
- package/dist/AnalyticsController-method-action-types.d.cts.map +1 -1
- package/dist/AnalyticsController-method-action-types.d.mts +106 -2
- package/dist/AnalyticsController-method-action-types.d.mts.map +1 -1
- package/dist/AnalyticsController-method-action-types.mjs.map +1 -1
- package/dist/AnalyticsController.cjs +364 -14
- package/dist/AnalyticsController.cjs.map +1 -1
- package/dist/AnalyticsController.d.cts +121 -2
- package/dist/AnalyticsController.d.cts.map +1 -1
- package/dist/AnalyticsController.d.mts +121 -2
- package/dist/AnalyticsController.d.mts.map +1 -1
- package/dist/AnalyticsController.mjs +363 -13
- package/dist/AnalyticsController.mjs.map +1 -1
- package/dist/EventFragment.types.cjs +3 -0
- package/dist/EventFragment.types.cjs.map +1 -0
- package/dist/EventFragment.types.d.cts +111 -0
- package/dist/EventFragment.types.d.cts.map +1 -0
- package/dist/EventFragment.types.d.mts +111 -0
- package/dist/EventFragment.types.d.mts.map +1 -0
- package/dist/EventFragment.types.mjs +2 -0
- package/dist/EventFragment.types.mjs.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +19 -0
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +3 -0
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +3 -0
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +19 -0
- package/dist/selectors.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsController.mjs","sourceRoot":"","sources":["../src/AnalyticsController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;;;AAQ3D,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAGlC,OAAO,EAAE,gCAAgC,EAAE,gDAA+C;AAC1F,OAAO,EAAE,aAAa,IAAI,GAAG,EAAE,8BAA6B;AAU5D,OAAO,EAAE,4BAA4B,EAAE,wBAAuB;AAE9D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAqHpD;;;;;;;GAOG;AACH,MAAM,UAAU,kCAAkC;IAIhD,OAAO;QACL,OAAO,EAAE,KAAK;QACd,mBAAmB,EAAE,KAAK;KAC3B,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,2BAA2B,GAAG;IAClC,OAAO,EAAE;QACP,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,WAAW,EAAE;QACX,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,UAAU,EAAE;QACV,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;IACD,mBAAmB,EAAE;QACnB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,Q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CAAC;IAeC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAE9C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO;IACT,CAAC;IAED,IAAI,CAAC,uBAAA,IAAI,qDAA0B,EAAE,CAAC;QACpC,uBAAA,IAAI,kFAAuB,MAA3B,IAAI,CAAyB,CAAC;QAC9B,OAAO;IACT,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACvB,uBAAA,IAAI,mFAAwB,MAA5B,IAAI,EAAyB,KAAK,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC;QAC1C,uBAAA,IAAI,kFAAuB,MAA3B,IAAI,CAAyB,CAAC;IAChC,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n GeolocationControllerGetGeolocationDataAction,\n GeolocationData,\n} from '@metamask/geolocation-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\nimport { cloneDeep } from 'lodash';\nimport { v4 as uuid } from 'uuid';\n\nimport type { AnalyticsControllerMethodActions } from './AnalyticsController-method-action-types.js';\nimport { validateAnalyticsControllerState } from './analyticsControllerStateValidator.js';\nimport { projectLogger as log } from './AnalyticsLogger.js';\nimport type {\n AnalyticsPlatformAdapter,\n AnalyticsDeliveryOptions,\n AnalyticsContext,\n AnalyticsEventProperties,\n AnalyticsLocationContext,\n AnalyticsUserTraits,\n AnalyticsTrackingEvent,\n} from './AnalyticsPlatformAdapter.types';\nimport { analyticsControllerSelectors } from './selectors.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link AnalyticsController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'AnalyticsController';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link AnalyticsController}.\n */\nexport type AnalyticsControllerState = {\n /**\n * Whether the user has opted in to analytics.\n */\n optedIn: boolean;\n\n /**\n * User's UUIDv4 analytics identifier.\n * This is an identity (unique per user), not a preference.\n * Must be provided by the platform - the controller does not generate it.\n */\n analyticsId: string;\n\n /**\n * Persisted queue of analytics events waiting for delivery acknowledgement.\n * This is only used when event queue persistence is enabled.\n */\n eventQueue?: Record<string, Json>;\n\n /**\n * Whether the user has made a consent decision (opted in or opted out).\n *\n * This distinguishes the \"undecided\" state (e.g. during onboarding, before\n * the user has answered the analytics prompt) from an explicit opt-out.\n * Defaults to `false` and is set to `true` by {@link AnalyticsController.optIn}\n * or {@link AnalyticsController.optOut}, and back to `false` by\n * {@link AnalyticsController.resetConsentDecision}. Optional for backward\n * compatibility with persisted state that predates this field.\n */\n consentDecisionMade?: boolean;\n\n /**\n * Persisted queue of track events ({@link AnalyticsQueuedTrackEvent}) captured\n * while the user is undecided (no consent decision made yet). Replayed on\n * opt-in and cleared on opt-out.\n * Preserved across {@link AnalyticsController.resetConsentDecision} so onboarding\n * restarts do not drop install-time events.\n * This is only used when the pre-consent queue is enabled.\n */\n preConsentEventQueue?: Record<string, Json>;\n};\n\n/**\n * Event types supported by the persisted analytics event queue.\n */\nexport type AnalyticsQueuedEventType = 'track' | 'identify' | 'view';\n\n/**\n * Base persisted event queue entry.\n */\nexport type AnalyticsQueuedEventBase = {\n /**\n * Event type used to replay the payload with the platform adapter.\n */\n type: AnalyticsQueuedEventType;\n\n /**\n * Stable identifier for the analytics payload.\n */\n messageId: string;\n\n /**\n * Original payload timestamp serialized for persistence.\n */\n timestamp: string;\n};\n\n/**\n * Persisted track event queue entry.\n */\nexport type AnalyticsQueuedTrackEvent = AnalyticsQueuedEventBase & {\n type: 'track';\n eventName: string;\n properties?: AnalyticsEventProperties;\n context?: AnalyticsContext;\n};\n\n/**\n * Persisted identify event queue entry.\n */\nexport type AnalyticsQueuedIdentifyEvent = AnalyticsQueuedEventBase & {\n type: 'identify';\n userId: string;\n traits?: AnalyticsUserTraits;\n context?: AnalyticsContext;\n};\n\n/**\n * Persisted view event queue entry.\n */\nexport type AnalyticsQueuedViewEvent = AnalyticsQueuedEventBase & {\n type: 'view';\n name: string;\n properties?: AnalyticsEventProperties;\n context?: AnalyticsContext;\n};\n\n/**\n * Persisted analytics event queue entry.\n */\nexport type AnalyticsQueuedEvent =\n | AnalyticsQueuedTrackEvent\n | AnalyticsQueuedIdentifyEvent\n | AnalyticsQueuedViewEvent;\n\n/**\n * Persisted analytics event queue keyed by message ID.\n */\nexport type AnalyticsEventQueue = Record<string, AnalyticsQueuedEvent>;\n\n/**\n * Returns default values for AnalyticsController state.\n *\n * Note: analyticsId is NOT included - it's an identity that must be\n * provided by the platform (generated once on first run, then persisted).\n *\n * @returns Default state without analyticsId\n */\nexport function getDefaultAnalyticsControllerState(): Omit<\n AnalyticsControllerState,\n 'analyticsId'\n> {\n return {\n optedIn: false,\n consentDecisionMade: false,\n };\n}\n\n/**\n * The metadata for each property in {@link AnalyticsControllerState}.\n *\n * Both `optedIn` and `analyticsId` are persisted (`persist: true`).\n * The platform must supply a valid UUIDv4 `analyticsId` on first run.\n */\nconst analyticsControllerMetadata = {\n optedIn: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n analyticsId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n eventQueue: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n consentDecisionMade: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n preConsentEventQueue: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n} satisfies StateMetadata<AnalyticsControllerState>;\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'trackEvent',\n 'identify',\n 'trackView',\n 'optIn',\n 'optOut',\n 'resetConsentDecision',\n] as const;\n\n/**\n * Returns the state of the {@link AnalyticsController}.\n */\nexport type AnalyticsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AnalyticsControllerState\n>;\n\n/**\n * Actions that {@link AnalyticsControllerMessenger} exposes to other consumers.\n */\nexport type AnalyticsControllerActions =\n | AnalyticsControllerGetStateAction\n | AnalyticsControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link AnalyticsControllerMessenger} calls.\n */\ntype AllowedActions = GeolocationControllerGetGeolocationDataAction;\n\n/**\n * Event emitted when the state of the {@link AnalyticsController} changes.\n */\nexport type AnalyticsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AnalyticsControllerState\n>;\n\n/**\n * Events that {@link AnalyticsControllerMessenger} exposes to other consumers.\n */\nexport type AnalyticsControllerEvents = AnalyticsControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link AnalyticsControllerMessenger} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link AnalyticsController}.\n */\nexport type AnalyticsControllerMessenger = Messenger<\n typeof controllerName,\n AnalyticsControllerActions | AllowedActions,\n AnalyticsControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * The options that AnalyticsController takes.\n */\nexport type AnalyticsControllerOptions = {\n /**\n * Initial controller state. Must include a valid UUIDv4 `analyticsId`.\n * The platform is responsible for generating the ID on first run.\n * It is then persisted with controller state when using a persisted store.\n */\n state: AnalyticsControllerState;\n /**\n * Messenger used to communicate with BaseController and other controllers.\n */\n messenger: AnalyticsControllerMessenger;\n /**\n * Platform adapter implementation for tracking events.\n */\n platformAdapter: AnalyticsPlatformAdapter;\n\n /**\n * Whether the anonymous events feature is enabled.\n *\n * @default false\n */\n isAnonymousEventsFeatureEnabled?: boolean;\n\n /**\n * Whether analytics event queue persistence is enabled.\n *\n * When enabled, AnalyticsController persists each platform adapter payload\n * until the adapter reports successful delivery.\n *\n * @default false\n */\n isEventQueuePersistenceEnabled?: boolean;\n\n /**\n * Whether the pre-consent event queue is enabled.\n *\n * When enabled, track events received while the user is undecided\n * (no consent decision made yet) are persisted and replayed on opt-in,\n * or dropped on opt-out. When disabled, such events are dropped immediately,\n * preserving the legacy behavior.\n *\n * @default false\n */\n isPreConsentQueueEnabled?: boolean;\n\n /**\n * Whether geolocation enrichment is enabled.\n *\n * When enabled, {@link AnalyticsController.init} resolves the user's\n * country, region, and timezone via `GeolocationController:getGeolocationData`\n * and attaches them to `context.location` on non-anonymous payloads.\n * Compositions must register that action when this is enabled. When disabled,\n * the controller never calls the geolocation action and events are delivered\n * without location.\n *\n * @default false\n */\n isGeolocationEnabled?: boolean;\n};\n\n/**\n * Returns whether a value is a non-array object.\n *\n * @param value - The value to check.\n * @returns True if the value is a record.\n */\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Returns whether a JSON value is a non-array object.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSON record.\n */\nfunction isJsonRecord(value: Json | undefined): value is Record<string, Json> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Builds the analytics location context from geolocation data, keeping only\n * the fields the geolocation API was able to determine.\n *\n * @param geolocation - The geolocation data to convert.\n * @returns The location context, or `undefined` when no field is known.\n */\nfunction buildLocationContext(\n geolocation: GeolocationData,\n): AnalyticsLocationContext | undefined {\n const locationContext: AnalyticsLocationContext = {\n ...(geolocation.country === null\n ? {}\n : { country_code: geolocation.country }),\n ...(geolocation.region === null ? {} : { region: geolocation.region }),\n ...(geolocation.timezone === null\n ? {}\n : { timezone: geolocation.timezone }),\n };\n\n return Object.keys(locationContext).length === 0\n ? undefined\n : locationContext;\n}\n\n/**\n * Returns whether a value is a valid persisted analytics event.\n *\n * @param value - The value to check.\n * @returns True if the value is a queued analytics event.\n */\nfunction isAnalyticsQueuedEvent(value: unknown): value is AnalyticsQueuedEvent {\n if (!isRecord(value)) {\n return false;\n }\n\n if (\n typeof value.messageId !== 'string' ||\n typeof value.timestamp !== 'string'\n ) {\n return false;\n }\n\n if (value.type === 'track') {\n return (\n typeof value.eventName === 'string' &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.context === undefined || isRecord(value.context))\n );\n }\n\n if (value.type === 'identify') {\n return (\n typeof value.userId === 'string' &&\n (value.traits === undefined || isRecord(value.traits)) &&\n (value.context === undefined || isRecord(value.context))\n );\n }\n\n if (value.type === 'view') {\n return (\n typeof value.name === 'string' &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.context === undefined || isRecord(value.context))\n );\n }\n\n return false;\n}\n\n/**\n * The AnalyticsController manages analytics tracking across platforms (Mobile/Extension).\n * It provides a unified interface for tracking events, identifying users, and managing\n * analytics preferences while delegating platform-specific implementation to an\n * {@link AnalyticsPlatformAdapter}.\n *\n * This controller follows the MetaMask controller pattern and integrates with the\n * messenger system to allow other controllers and components to track analytics events.\n * It delegates platform-specific implementation to an {@link AnalyticsPlatformAdapter}.\n *\n * The controller persists `optedIn` and `analyticsId` when composed with a persisted\n * store. The platform must supply a valid `analyticsId` on first launch.\n */\nexport class AnalyticsController extends BaseController<\n 'AnalyticsController',\n AnalyticsControllerState,\n AnalyticsControllerMessenger\n> {\n readonly #platformAdapter: AnalyticsPlatformAdapter;\n\n readonly #isAnonymousEventsFeatureEnabled: boolean;\n\n readonly #isEventQueuePersistenceEnabled: boolean;\n\n readonly #isPreConsentQueueEnabled: boolean;\n\n readonly #isGeolocationEnabled: boolean;\n\n /**\n * The in-flight (or settled) initialization promise. Set on the first\n * {@link init} call and returned by subsequent calls so overlapping callers\n * await the same work rather than observing a premature completion.\n */\n #initPromise: Promise<void> | undefined;\n\n /**\n * The in-flight (or settled) geolocation resolution, if any. Its presence\n * marks that resolution has been started, so it runs at most once.\n */\n #locationResolvePromise: Promise<void> | undefined;\n\n #locationContext: AnalyticsLocationContext | undefined;\n\n /**\n * Constructs an AnalyticsController instance.\n *\n * @param options - Controller options\n * @param options.state - Initial controller state. Must include a valid UUIDv4 `analyticsId`.\n * Use `getDefaultAnalyticsControllerState()` for default opt-in preferences.\n * @param options.messenger - Messenger used to communicate with BaseController\n * @param options.platformAdapter - Platform adapter implementation for tracking\n * @param options.isAnonymousEventsFeatureEnabled - Whether the anonymous events feature is enabled\n * @param options.isEventQueuePersistenceEnabled - Whether analytics event queue persistence is enabled\n * @param options.isPreConsentQueueEnabled - Whether the pre-consent event queue is enabled\n * @param options.isGeolocationEnabled - Whether geolocation enrichment is enabled\n * @throws Error if state.analyticsId is missing or not a valid UUIDv4\n * @remarks After construction, call {@link AnalyticsController.init} to complete initialization.\n */\n constructor({\n state,\n messenger,\n platformAdapter,\n isAnonymousEventsFeatureEnabled = false,\n isEventQueuePersistenceEnabled = false,\n isPreConsentQueueEnabled = false,\n isGeolocationEnabled = false,\n }: AnalyticsControllerOptions) {\n const initialState: AnalyticsControllerState = {\n ...getDefaultAnalyticsControllerState(),\n ...state,\n };\n\n validateAnalyticsControllerState(\n initialState,\n platformAdapter.skipUUIDv4Check === true,\n );\n\n super({\n name: controllerName,\n metadata: analyticsControllerMetadata,\n state: initialState,\n messenger,\n });\n\n this.#isAnonymousEventsFeatureEnabled = isAnonymousEventsFeatureEnabled;\n this.#isEventQueuePersistenceEnabled = isEventQueuePersistenceEnabled;\n this.#isPreConsentQueueEnabled = isPreConsentQueueEnabled;\n this.#isGeolocationEnabled = isGeolocationEnabled;\n this.#platformAdapter = platformAdapter;\n this.#initPromise = undefined;\n this.#locationResolvePromise = undefined;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n log('AnalyticsController initialized and ready', {\n enabled: analyticsControllerSelectors.selectEnabled(this.state),\n optedIn: this.state.optedIn,\n consentDecisionMade: this.state.consentDecisionMade,\n analyticsId: this.state.analyticsId,\n eventQueuePersistenceEnabled: this.#isEventQueuePersistenceEnabled,\n preConsentQueueEnabled: this.#isPreConsentQueueEnabled,\n geolocationEnabled: this.#isGeolocationEnabled,\n });\n }\n\n /**\n * Initialize the controller by calling the platform adapter's\n * onSetupCompleted lifecycle hook and replaying any queued events. This\n * method must be called after construction to complete the setup process.\n *\n * When geolocation enrichment is enabled (`isGeolocationEnabled`), geolocation\n * is resolved only for a user who is already opted in; for undecided or\n * opted-out users it is deferred until they opt in (see {@link optIn}), so a\n * user's location is never requested before they consent to analytics. In\n * either case the `GeolocationController` and its\n * `GeolocationController:getGeolocationData` action must be registered before\n * resolution occurs, or enrichment is skipped for the session (a message is\n * logged, see {@link #resolveLocationContext}).\n *\n * Safe to call more than once: the first call performs initialization and\n * subsequent calls return the same in-flight (or settled) promise.\n *\n * @returns A promise that resolves once initialization has completed.\n */\n init(): Promise<void> {\n // Cache the in-flight promise so repeated or overlapping calls share a\n // single initialization and all await the same completion (rather than an\n // early call observing a finished init while work is still pending).\n this.#initPromise ??= this.#performInit();\n return this.#initPromise;\n }\n\n /**\n * Performs the one-time initialization work: resolve geolocation, run the\n * platform adapter's onSetupCompleted lifecycle hook, then replay any queued\n * and pre-consent events.\n */\n async #performInit(): Promise<void> {\n // Resolve geolocation only when the user is already opted in; for undecided\n // or opted-out users it is deferred to {@link optIn}. Awaited so that an\n // already-opted-in session has location available before events replay.\n await this.#maybeResolveLocation();\n\n // Call onSetupCompleted lifecycle hook after initialization\n // State is already validated, so analyticsId is guaranteed to be a valid UUIDv4\n try {\n this.#platformAdapter.onSetupCompleted(this.state.analyticsId);\n } catch (error) {\n // Log error but don't throw - adapter setup failure shouldn't break controller\n log('Error calling platformAdapter.onSetupCompleted', error);\n }\n\n this.#replayQueuedEvents();\n this.#reconcilePreConsentEvents();\n }\n\n /**\n * Start resolving the geolocation context if warranted, and return the\n * in-flight (or settled) resolution so callers can await it. No-op unless\n * enrichment is enabled, the user is opted in, and a resolution has not\n * already been started. Deferring resolution until opt-in ensures a user's\n * location is never requested before they consent to analytics (for example,\n * during onboarding).\n *\n * Resolution runs at most once per controller session: the settled promise\n * is retained, so the outcome — including a failure (see\n * {@link #resolveLocationContext}) — is not retried, and events are delivered\n * without location for the rest of the session.\n *\n * @returns The geolocation resolution promise, or `undefined` when no\n * resolution is warranted.\n */\n #maybeResolveLocation(): Promise<void> | undefined {\n if (\n this.#isGeolocationEnabled &&\n this.#locationResolvePromise === undefined &&\n analyticsControllerSelectors.selectEnabled(this.state)\n ) {\n this.#locationResolvePromise = this.#resolveLocationContext();\n }\n\n return this.#locationResolvePromise;\n }\n\n async #resolveLocationContext(): Promise<void> {\n try {\n const geolocation = await this.messenger.call(\n 'GeolocationController:getGeolocationData',\n );\n\n this.#locationContext = buildLocationContext(geolocation);\n } catch (error) {\n // A common cause is the GeolocationController not being registered before\n // resolution runs (at init for an opted-in user, otherwise at opt-in).\n // Name it here so the failure is diagnosable, since enrichment is\n // otherwise skipped silently for the session.\n log(\n 'Failed to resolve geolocation for analytics enrichment; events will be sent without location. Ensure the GeolocationController is registered and initialized before the user opts in when geolocation is enabled.',\n error,\n );\n }\n }\n\n /**\n * Merge the resolved location context into a caller-provided context.\n *\n * Caller-provided `location` fields are preserved, but the fields the\n * controller resolves take precedence over them.\n *\n * @param context - Optional caller-provided context.\n * @returns The context enriched with location, or the original context when\n * no location is known.\n */\n #withLocationContext(\n context?: AnalyticsContext,\n ): AnalyticsContext | undefined {\n if (!this.#locationContext) {\n return context;\n }\n\n const callerLocation = context?.location;\n\n return {\n ...context,\n location: {\n ...(isJsonRecord(callerLocation) ? callerLocation : {}),\n ...this.#locationContext,\n },\n };\n }\n\n /**\n * Send final track payload through the platform adapter or queue it if persistence is enabled.\n *\n * @param eventName - The name of the event.\n * @param properties - Optional event properties.\n * @param context - Optional platform-specific context.\n */\n #sendOrQueueTrackEvent(\n eventName: string,\n properties?: AnalyticsEventProperties,\n context?: AnalyticsContext,\n ): void {\n // Direct delivery: enabled and not persisting.\n if (\n analyticsControllerSelectors.selectEnabled(this.state) &&\n !this.#isEventQueuePersistenceEnabled\n ) {\n this.#platformAdapter.track(eventName, properties, context);\n return;\n }\n\n const queuedEvent: AnalyticsQueuedTrackEvent = {\n type: 'track',\n eventName,\n messageId: uuid(),\n timestamp: new Date().toISOString(),\n ...(properties === undefined ? {} : { properties }),\n ...(context === undefined ? {} : { context }),\n };\n\n // Not yet enabled (reached only while undecided with the pre-consent queue\n // enabled): hold the event until the user opts in.\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n this.#enqueuePreConsentEvent(queuedEvent);\n return;\n }\n\n this.#enqueueEvent(queuedEvent);\n }\n\n /**\n * Send final identify payload through the platform adapter or queue it if persistence is enabled.\n *\n * @param userId - The user ID.\n * @param traits - Optional user traits.\n * @param context - Optional platform-specific context.\n */\n #sendOrQueueIdentifyEvent(\n userId: string,\n traits?: AnalyticsUserTraits,\n context?: AnalyticsContext,\n ): void {\n if (!this.#isEventQueuePersistenceEnabled) {\n this.#platformAdapter.identify(userId, traits, context);\n return;\n }\n\n const queuedEvent: AnalyticsQueuedIdentifyEvent = {\n type: 'identify',\n userId,\n messageId: uuid(),\n timestamp: new Date().toISOString(),\n ...(traits === undefined ? {} : { traits }),\n ...(context === undefined ? {} : { context }),\n };\n\n this.#enqueueEvent(queuedEvent);\n }\n\n /**\n * Send final view payload through the platform adapter or queue it if persistence is enabled.\n *\n * @param name - The view name.\n * @param properties - Optional view properties.\n * @param context - Optional platform-specific context.\n */\n #sendOrQueueViewEvent(\n name: string,\n properties?: AnalyticsEventProperties,\n context?: AnalyticsContext,\n ): void {\n if (!this.#isEventQueuePersistenceEnabled) {\n this.#platformAdapter.view(name, properties, context);\n return;\n }\n\n const queuedEvent: AnalyticsQueuedViewEvent = {\n type: 'view',\n name,\n messageId: uuid(),\n timestamp: new Date().toISOString(),\n ...(properties === undefined ? {} : { properties }),\n ...(context === undefined ? {} : { context }),\n };\n\n this.#enqueueEvent(queuedEvent);\n }\n\n /**\n * Add an analytics event to the queue and send it.\n *\n * @param queuedEvent - The event to enqueue and deliver.\n */\n #enqueueEvent(queuedEvent: AnalyticsQueuedEvent): void {\n const eventQueue: Record<string, Json> = {\n ...(this.state.eventQueue ?? {}),\n [queuedEvent.messageId]: queuedEvent as unknown as Json,\n };\n\n this.update((state) => {\n state.eventQueue = eventQueue as never;\n });\n\n this.#sendQueuedEvent(queuedEvent);\n }\n\n /**\n * Send a queued event through the platform adapter.\n *\n * @param queuedEvent - The queued event to deliver.\n */\n #sendQueuedEvent(queuedEvent: AnalyticsQueuedEvent): void {\n const timestamp = new Date(queuedEvent.timestamp);\n\n if (Number.isNaN(timestamp.getTime())) {\n log('Dropping queued analytics event with invalid timestamp', {\n messageId: queuedEvent.messageId,\n });\n this.#removeQueuedEvent(queuedEvent.messageId);\n return;\n }\n\n const options: AnalyticsDeliveryOptions = {\n messageId: queuedEvent.messageId,\n timestamp,\n callback: (error?: unknown) => {\n if (error) {\n log('Queued analytics event delivery failed', {\n messageId: queuedEvent.messageId,\n error,\n });\n }\n\n this.#removeQueuedEvent(queuedEvent.messageId);\n },\n };\n\n try {\n if (queuedEvent.type === 'track') {\n this.#platformAdapter.track(\n queuedEvent.eventName,\n cloneDeep(queuedEvent.properties),\n cloneDeep(queuedEvent.context),\n options,\n );\n } else if (queuedEvent.type === 'identify') {\n this.#platformAdapter.identify(\n queuedEvent.userId,\n cloneDeep(queuedEvent.traits),\n cloneDeep(queuedEvent.context),\n options,\n );\n } else {\n this.#platformAdapter.view(\n queuedEvent.name,\n cloneDeep(queuedEvent.properties),\n cloneDeep(queuedEvent.context),\n options,\n );\n }\n } catch (error) {\n log('Error sending queued analytics event', {\n messageId: queuedEvent.messageId,\n error,\n });\n }\n }\n\n /**\n * Replay persisted analytics events.\n */\n #replayQueuedEvents(): void {\n if (!this.#isEventQueuePersistenceEnabled || !this.state.eventQueue) {\n return;\n }\n\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n this.#clearQueuedEvents();\n return;\n }\n\n for (const [messageId, queuedEvent] of Object.entries(\n this.state.eventQueue,\n )) {\n if (\n !isAnalyticsQueuedEvent(queuedEvent) ||\n queuedEvent.messageId !== messageId\n ) {\n log('Dropping invalid queued analytics event', { messageId });\n this.#removeQueuedEvent(messageId);\n continue;\n }\n\n this.#sendQueuedEvent(queuedEvent);\n }\n }\n\n /**\n * Remove a queued analytics event.\n *\n * @param messageId - The queued event message ID.\n */\n #removeQueuedEvent(messageId: string): void {\n const currentEventQueue = this.state.eventQueue;\n\n if (\n !currentEventQueue ||\n !Object.prototype.hasOwnProperty.call(currentEventQueue, messageId)\n ) {\n return;\n }\n\n const { [messageId]: _deletedEvent, ...eventQueue } = currentEventQueue;\n\n this.update((state) => {\n state.eventQueue = eventQueue as never;\n });\n }\n\n /**\n * Clear all queued analytics events.\n */\n #clearQueuedEvents(): void {\n if (\n !this.state.eventQueue ||\n Object.keys(this.state.eventQueue).length === 0\n ) {\n return;\n }\n\n this.update((state) => {\n state.eventQueue = {} as never;\n });\n }\n\n /**\n * Add an event to the pre-consent queue without delivering it.\n *\n * @param queuedEvent - The event to hold until the user opts in.\n */\n #enqueuePreConsentEvent(queuedEvent: AnalyticsQueuedEvent): void {\n const preConsentEventQueue: Record<string, Json> = {\n ...(this.state.preConsentEventQueue ?? {}),\n [queuedEvent.messageId]: queuedEvent as unknown as Json,\n };\n\n this.update((state) => {\n state.preConsentEventQueue = preConsentEventQueue as never;\n });\n }\n\n /**\n * Replay queued pre-consent events through the delivery path.\n *\n * Only called by {@link #reconcilePreConsentEvents}, which guarantees the\n * pre-consent queue is enabled and that the user is opted in. The queue is\n * cleared before replaying so events cannot be re-queued or replayed twice.\n *\n * @param queue - The pre-consent event queue to replay.\n */\n #replayPreConsentEvents(queue: Record<string, Json>): void {\n this.#clearPreConsentEvents();\n\n for (const [messageId, queuedEvent] of Object.entries(queue)) {\n if (\n !isAnalyticsQueuedEvent(queuedEvent) ||\n queuedEvent.messageId !== messageId\n ) {\n log('Dropping invalid queued pre-consent analytics event', {\n messageId,\n });\n continue;\n }\n\n const eventToReplay = this.#enrichPreConsentEvent(queuedEvent);\n\n if (this.#isEventQueuePersistenceEnabled) {\n this.#enqueueEvent(eventToReplay);\n } else {\n this.#sendQueuedEvent(eventToReplay);\n }\n }\n }\n\n /**\n * Enrich a pre-consent event with the geolocation resolved on opt-in.\n *\n * Pre-consent events are captured while geolocation is not yet resolved, so\n * they are re-enriched here as they replay. Anonymous track payloads are left\n * untouched, since they must never carry location.\n *\n * @param queuedEvent - The queued pre-consent event.\n * @returns The event with its context enriched, or the event unchanged when\n * enrichment does not apply.\n */\n #enrichPreConsentEvent(\n queuedEvent: AnalyticsQueuedEvent,\n ): AnalyticsQueuedEvent {\n if (\n queuedEvent.type === 'track' &&\n queuedEvent.properties?.anonymous === true\n ) {\n return queuedEvent;\n }\n\n const context = this.#withLocationContext(queuedEvent.context);\n\n return {\n ...queuedEvent,\n ...(context === undefined ? {} : { context }),\n };\n }\n\n /**\n * Clear all queued pre-consent events.\n */\n #clearPreConsentEvents(): void {\n if (!this.state.preConsentEventQueue) {\n return;\n }\n\n this.update((state) => {\n state.preConsentEventQueue = {} as never;\n });\n }\n\n /**\n * Reconcile the pre-consent queue on initialization.\n *\n * The queue should normally be empty unless the user is still undecided. This\n * handles the rare cases where a consent decision was persisted but the queue\n * was not flushed/cleared (e.g. an interrupted shutdown): replay it if the\n * user is opted in, or clear it if they opted out.\n *\n * If the pre-consent queue is disabled, any stale persisted entries (e.g. from\n * a previous session where it was enabled) are dropped so they can never be\n * replayed.\n */\n #reconcilePreConsentEvents(): void {\n const queue = this.state.preConsentEventQueue;\n\n if (!queue) {\n return;\n }\n\n if (!this.#isPreConsentQueueEnabled) {\n this.#clearPreConsentEvents();\n return;\n }\n\n if (this.state.optedIn) {\n this.#replayPreConsentEvents(queue);\n } else if (this.state.consentDecisionMade) {\n this.#clearPreConsentEvents();\n }\n }\n\n /**\n * Track an analytics event.\n *\n * Events are only tracked if analytics is enabled.\n *\n * @param event - Analytics event with properties and sensitive properties\n * @param context - Optional platform-specific context forwarded to the platform adapter.\n */\n trackEvent(event: AnalyticsTrackingEvent, context?: AnalyticsContext): void {\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n // While the user is undecided, fall through so the event is processed and\n // captured in the pre-consent queue (see #sendOrQueueTrackEvent) to be\n // replayed if they later opt in. Otherwise (opted out, or pre-consent\n // queue disabled) drop it.\n const shouldQueuePreConsent =\n this.#isPreConsentQueueEnabled && !this.state.consentDecisionMade;\n if (!shouldQueuePreConsent) {\n return;\n }\n }\n\n // if event does not have properties, send event without properties\n // and return to prevent any additional processing\n if (!event.hasProperties) {\n this.#sendOrQueueTrackEvent(\n event.name,\n undefined,\n this.#withLocationContext(context),\n );\n return;\n }\n\n // Track regular properties first if anonymous events feature is enabled\n if (this.#isAnonymousEventsFeatureEnabled) {\n // Note: Even if regular properties object is empty, we still send it to ensure\n // an event with user ID is tracked.\n this.#sendOrQueueTrackEvent(\n event.name,\n {\n ...event.properties,\n },\n this.#withLocationContext(context),\n );\n }\n\n const hasSensitiveProperties =\n Object.keys(event.sensitiveProperties).length > 0;\n\n if (!this.#isAnonymousEventsFeatureEnabled || hasSensitiveProperties) {\n this.#sendOrQueueTrackEvent(\n event.name,\n {\n ...event.properties,\n ...event.sensitiveProperties,\n ...(hasSensitiveProperties && { anonymous: true }),\n },\n // When the anonymous events feature is enabled, this payload is the\n // anonymous one and must carry no geolocation. When the feature is\n // disabled, this is the single identified payload, so it is enriched.\n this.#isAnonymousEventsFeatureEnabled\n ? context\n : this.#withLocationContext(context),\n );\n }\n }\n\n /**\n * Identify a user for analytics.\n *\n * @param traits - User traits/properties\n * @param context - Optional platform-specific context forwarded to the platform adapter.\n */\n identify(traits?: AnalyticsUserTraits, context?: AnalyticsContext): void {\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n return;\n }\n\n // Delegate to platform adapter using the current analytics ID\n this.#sendOrQueueIdentifyEvent(\n this.state.analyticsId,\n traits,\n this.#withLocationContext(context),\n );\n }\n\n /**\n * Track a page or screen view.\n *\n * @param name - The identifier/name of the page or screen being viewed (e.g., \"home\", \"settings\", \"wallet\")\n * @param properties - Optional properties associated with the view\n * @param context - Optional platform-specific context forwarded to the platform adapter.\n */\n trackView(\n name: string,\n properties?: AnalyticsEventProperties,\n context?: AnalyticsContext,\n ): void {\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n return;\n }\n\n // Delegate to platform adapter\n this.#sendOrQueueViewEvent(\n name,\n properties,\n this.#withLocationContext(context),\n );\n }\n\n /**\n * Opt in to analytics.\n *\n * Records that a consent decision has been made and replays any events that\n * were queued while the user was undecided.\n *\n * When geolocation enrichment is enabled, geolocation is resolved here (once\n * the user has consented) and awaited before the queued events are replayed,\n * so those events are enriched with the resolved location as they are sent.\n *\n * @returns A promise that resolves once opt-in processing has completed.\n */\n async optIn(): Promise<void> {\n this.update((state) => {\n state.optedIn = true;\n state.consentDecisionMade = true;\n });\n\n // Now that the user has consented, resolve geolocation (once) and wait for\n // it so the queued pre-consent events can be enriched as they replay.\n await this.#maybeResolveLocation();\n\n // Reconcile against the current state rather than replaying blindly: the\n // consent decision may have changed while geolocation was resolving (e.g.\n // resetConsentDecision ran during the await), and preserved pre-consent\n // events must not be delivered once the user is no longer opted in.\n this.#reconcilePreConsentEvents();\n }\n\n /**\n * Opt out of analytics.\n *\n * Records that a consent decision has been made and discards any persisted\n * events so nothing captured before the decision is ever delivered.\n */\n optOut(): void {\n this.update((state) => {\n state.optedIn = false;\n state.consentDecisionMade = true;\n });\n\n this.#clearQueuedEvents();\n this.#clearPreConsentEvents();\n }\n\n /**\n * Reset the consent decision back to undecided.\n *\n * Intended for client flows that restart onboarding. Clears the opt-in\n * preference and discards the delivery queue, but preserves any pre-consent\n * events so they can still be replayed if the user opts in again. The user is\n * treated as undecided again.\n */\n resetConsentDecision(): void {\n this.update((state) => {\n state.optedIn = false;\n state.consentDecisionMade = false;\n });\n\n this.#clearQueuedEvents();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AnalyticsController.mj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EAAE,CACX,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,uBAAA,IAAI,sFAA2B,MAA/B,IAAI,CAA6B,EAAE,CAAC;QACvC,GAAG,CACD,2FAA2F,EAC3F,EAAE,MAAM,EAAE,CACX,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,2FAcC,QAAgC,EAChC,IAAY,EACZ,OAAqC;IAErC,MAAM,UAAU,GAAG,EAAE,GAAG,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC9C,MAAM,mBAAmB,GAAG,EAAE,GAAG,QAAQ,CAAC,mBAAmB,EAAE,CAAC;IAEhE,IAAI,CAAC,UAAU,CACb;QACE,IAAI;QACJ,UAAU;QACV,mBAAmB;QACnB,iBAAiB,EAAE,KAAK;QACxB,aAAa,EACX,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,CAAC;KAC9C,EACD,OAAO,CACR,CAAC;AACJ,CAAC;IAeC,IAAI,4BAA4B,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,uBAAA,IAAI,qDAA0B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC;AAC3E,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n GeolocationControllerGetGeolocationDataAction,\n GeolocationData,\n} from '@metamask/geolocation-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\nimport { cloneDeep } from 'lodash';\nimport { v4 as uuid } from 'uuid';\n\nimport type { AnalyticsControllerMethodActions } from './AnalyticsController-method-action-types.js';\nimport { validateAnalyticsControllerState } from './analyticsControllerStateValidator.js';\nimport { projectLogger as log } from './AnalyticsLogger.js';\nimport type {\n AnalyticsPlatformAdapter,\n AnalyticsDeliveryOptions,\n AnalyticsContext,\n AnalyticsEventProperties,\n AnalyticsLocationContext,\n AnalyticsUserTraits,\n AnalyticsTrackingEvent,\n} from './AnalyticsPlatformAdapter.types';\nimport type {\n AnalyticsEventFragment,\n AnalyticsEventFragmentFinalizeOptions,\n AnalyticsEventFragmentOptions,\n AnalyticsEventFragmentPayload,\n AnalyticsEventFragments,\n ReadonlyAnalyticsEventFragment,\n} from './EventFragment.types.js';\nimport { analyticsControllerSelectors } from './selectors.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link AnalyticsController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'AnalyticsController';\n\n/**\n * Maximum age of a persisted event fragment, measured from\n * {@link AnalyticsEventFragment.lastUpdated}.\n *\n * Fragments older than this are discarded during {@link AnalyticsController.init}\n * without emitting a success or failure event. Confirmation journeys that span a\n * restart are expected to resume within this window; abandoned ones must not keep\n * `properties` or `sensitiveProperties` in storage indefinitely.\n */\nexport const EVENT_FRAGMENT_MAX_AGE = 24 * 60 * 60 * 1000;\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link AnalyticsController}.\n */\nexport type AnalyticsControllerState = {\n /**\n * Whether the user has opted in to analytics.\n */\n optedIn: boolean;\n\n /**\n * User's UUIDv4 analytics identifier.\n * This is an identity (unique per user), not a preference.\n * Must be provided by the platform - the controller does not generate it.\n */\n analyticsId: string;\n\n /**\n * Persisted queue of analytics events waiting for delivery acknowledgement.\n * This is only used when event queue persistence is enabled.\n */\n eventQueue?: Record<string, Json>;\n\n /**\n * Whether the user has made a consent decision (opted in or opted out).\n *\n * This distinguishes the \"undecided\" state (e.g. during onboarding, before\n * the user has answered the analytics prompt) from an explicit opt-out.\n * Defaults to `false` and is set to `true` by {@link AnalyticsController.optIn}\n * or {@link AnalyticsController.optOut}, and back to `false` by\n * {@link AnalyticsController.resetConsentDecision}. Optional for backward\n * compatibility with persisted state that predates this field.\n */\n consentDecisionMade?: boolean;\n\n /**\n * Persisted queue of track events ({@link AnalyticsQueuedTrackEvent}) captured\n * while the user is undecided (no consent decision made yet). Replayed on\n * opt-in and cleared on opt-out.\n * Preserved across {@link AnalyticsController.resetConsentDecision} so onboarding\n * restarts do not drop install-time events.\n * This is only used when the pre-consent queue is enabled.\n */\n preConsentEventQueue?: Record<string, Json>;\n\n /**\n * Persisted event fragments ({@link AnalyticsEventFragment}) keyed by\n * fragment ID. Fragments accumulate properties across a user journey and are\n * removed when the journey is finalized or deleted. Fragments that set\n * `persist: true` can survive {@link AnalyticsController.init}, but only\n * while younger than {@link EVENT_FRAGMENT_MAX_AGE}.\n * This is only used when the event fragments feature is enabled.\n */\n eventFragments?: AnalyticsEventFragments;\n};\n\n/**\n * Event types supported by the persisted analytics event queue.\n */\nexport type AnalyticsQueuedEventType = 'track' | 'identify' | 'view';\n\n/**\n * Base persisted event queue entry.\n */\nexport type AnalyticsQueuedEventBase = {\n /**\n * Event type used to replay the payload with the platform adapter.\n */\n type: AnalyticsQueuedEventType;\n\n /**\n * Stable identifier for the analytics payload.\n */\n messageId: string;\n\n /**\n * Original payload timestamp serialized for persistence.\n */\n timestamp: string;\n};\n\n/**\n * Persisted track event queue entry.\n */\nexport type AnalyticsQueuedTrackEvent = AnalyticsQueuedEventBase & {\n type: 'track';\n eventName: string;\n properties?: AnalyticsEventProperties;\n context?: AnalyticsContext;\n};\n\n/**\n * Persisted identify event queue entry.\n */\nexport type AnalyticsQueuedIdentifyEvent = AnalyticsQueuedEventBase & {\n type: 'identify';\n userId: string;\n traits?: AnalyticsUserTraits;\n context?: AnalyticsContext;\n};\n\n/**\n * Persisted view event queue entry.\n */\nexport type AnalyticsQueuedViewEvent = AnalyticsQueuedEventBase & {\n type: 'view';\n name: string;\n properties?: AnalyticsEventProperties;\n context?: AnalyticsContext;\n};\n\n/**\n * Persisted analytics event queue entry.\n */\nexport type AnalyticsQueuedEvent =\n | AnalyticsQueuedTrackEvent\n | AnalyticsQueuedIdentifyEvent\n | AnalyticsQueuedViewEvent;\n\n/**\n * Persisted analytics event queue keyed by message ID.\n */\nexport type AnalyticsEventQueue = Record<string, AnalyticsQueuedEvent>;\n\n/**\n * Returns default values for AnalyticsController state.\n *\n * Note: analyticsId is NOT included - it's an identity that must be\n * provided by the platform (generated once on first run, then persisted).\n *\n * @returns Default state without analyticsId\n */\nexport function getDefaultAnalyticsControllerState(): Omit<\n AnalyticsControllerState,\n 'analyticsId'\n> {\n return {\n optedIn: false,\n consentDecisionMade: false,\n };\n}\n\n/**\n * The metadata for each property in {@link AnalyticsControllerState}.\n *\n * Both `optedIn` and `analyticsId` are persisted (`persist: true`).\n * The platform must supply a valid UUIDv4 `analyticsId` on first run.\n */\nconst analyticsControllerMetadata = {\n optedIn: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n analyticsId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n eventQueue: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n consentDecisionMade: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n preConsentEventQueue: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n eventFragments: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n} satisfies StateMetadata<AnalyticsControllerState>;\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'trackEvent',\n 'identify',\n 'trackView',\n 'optIn',\n 'optOut',\n 'resetConsentDecision',\n 'createEventFragment',\n 'upsertEventFragment',\n 'updateEventFragment',\n 'getEventFragmentById',\n 'deleteEventFragment',\n 'finalizeEventFragment',\n] as const;\n\n/**\n * Returns the state of the {@link AnalyticsController}.\n */\nexport type AnalyticsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AnalyticsControllerState\n>;\n\n/**\n * Actions that {@link AnalyticsControllerMessenger} exposes to other consumers.\n */\nexport type AnalyticsControllerActions =\n | AnalyticsControllerGetStateAction\n | AnalyticsControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link AnalyticsControllerMessenger} calls.\n */\ntype AllowedActions = GeolocationControllerGetGeolocationDataAction;\n\n/**\n * Event emitted when the state of the {@link AnalyticsController} changes.\n */\nexport type AnalyticsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AnalyticsControllerState\n>;\n\n/**\n * Events that {@link AnalyticsControllerMessenger} exposes to other consumers.\n */\nexport type AnalyticsControllerEvents = AnalyticsControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link AnalyticsControllerMessenger} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link AnalyticsController}.\n */\nexport type AnalyticsControllerMessenger = Messenger<\n typeof controllerName,\n AnalyticsControllerActions | AllowedActions,\n AnalyticsControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * The options that AnalyticsController takes.\n */\nexport type AnalyticsControllerOptions = {\n /**\n * Initial controller state. Must include a valid UUIDv4 `analyticsId`.\n * The platform is responsible for generating the ID on first run.\n * It is then persisted with controller state when using a persisted store.\n */\n state: AnalyticsControllerState;\n /**\n * Messenger used to communicate with BaseController and other controllers.\n */\n messenger: AnalyticsControllerMessenger;\n /**\n * Platform adapter implementation for tracking events.\n */\n platformAdapter: AnalyticsPlatformAdapter;\n\n /**\n * Whether the anonymous events feature is enabled.\n *\n * @default false\n */\n isAnonymousEventsFeatureEnabled?: boolean;\n\n /**\n * Whether analytics event queue persistence is enabled.\n *\n * When enabled, AnalyticsController persists each platform adapter payload\n * until the adapter reports successful delivery.\n *\n * @default false\n */\n isEventQueuePersistenceEnabled?: boolean;\n\n /**\n * Whether the pre-consent event queue is enabled.\n *\n * When enabled, track events received while the user is undecided\n * (no consent decision made yet) are persisted and replayed on opt-in,\n * or dropped on opt-out. When disabled, such events are dropped immediately,\n * preserving the legacy behavior.\n *\n * @default false\n */\n isPreConsentQueueEnabled?: boolean;\n\n /**\n * Whether geolocation enrichment is enabled.\n *\n * When enabled, {@link AnalyticsController.init} resolves the user's\n * country, region, and timezone via `GeolocationController:getGeolocationData`\n * and attaches them to `context.location` on non-anonymous payloads.\n * Compositions must register that action when this is enabled. When disabled,\n * the controller never calls the geolocation action and events are delivered\n * without location.\n *\n * @default false\n */\n isGeolocationEnabled?: boolean;\n\n /**\n * Whether the event fragments feature is enabled.\n *\n * When enabled, clients can accumulate analytics properties across a user\n * journey with {@link AnalyticsController.createEventFragment} and friends,\n * as long as the consent state allows analytics to be captured. When\n * disabled, every fragment method is a logged no-op and no fragment is ever\n * written to state.\n *\n * @default false\n */\n isEventFragmentsEnabled?: boolean;\n};\n\n/**\n * Returns whether a value is a non-array object.\n *\n * @param value - The value to check.\n * @returns True if the value is a record.\n */\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Returns whether a JSON value is a non-array object.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSON record.\n */\nfunction isJsonRecord(value: Json | undefined): value is Record<string, Json> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Builds the analytics location context from geolocation data, keeping only\n * the fields the geolocation API was able to determine.\n *\n * @param geolocation - The geolocation data to convert.\n * @returns The location context, or `undefined` when no field is known.\n */\nfunction buildLocationContext(\n geolocation: GeolocationData,\n): AnalyticsLocationContext | undefined {\n const locationContext: AnalyticsLocationContext = {\n ...(geolocation.country === null\n ? {}\n : { country_code: geolocation.country }),\n ...(geolocation.region === null ? {} : { region: geolocation.region }),\n ...(geolocation.timezone === null\n ? {}\n : { timezone: geolocation.timezone }),\n };\n\n return Object.keys(locationContext).length === 0\n ? undefined\n : locationContext;\n}\n\n/**\n * Returns whether a value is a valid persisted analytics event.\n *\n * @param value - The value to check.\n * @returns True if the value is a queued analytics event.\n */\nfunction isAnalyticsQueuedEvent(value: unknown): value is AnalyticsQueuedEvent {\n if (!isRecord(value)) {\n return false;\n }\n\n if (\n typeof value.messageId !== 'string' ||\n typeof value.timestamp !== 'string'\n ) {\n return false;\n }\n\n if (value.type === 'track') {\n return (\n typeof value.eventName === 'string' &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.context === undefined || isRecord(value.context))\n );\n }\n\n if (value.type === 'identify') {\n return (\n typeof value.userId === 'string' &&\n (value.traits === undefined || isRecord(value.traits)) &&\n (value.context === undefined || isRecord(value.context))\n );\n }\n\n if (value.type === 'view') {\n return (\n typeof value.name === 'string' &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.context === undefined || isRecord(value.context))\n );\n }\n\n return false;\n}\n\n/**\n * Returns whether a value is a valid persisted event fragment.\n *\n * @param value - The value to check.\n * @returns True if the value is an event fragment.\n */\nfunction isAnalyticsEventFragment(\n value: unknown,\n): value is AnalyticsEventFragment {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n typeof value.id === 'string' &&\n typeof value.createdAt === 'number' &&\n typeof value.lastUpdated === 'number' &&\n isRecord(value.properties) &&\n isRecord(value.sensitiveProperties) &&\n (value.initialEvent === undefined ||\n typeof value.initialEvent === 'string') &&\n (value.successEvent === undefined ||\n typeof value.successEvent === 'string') &&\n (value.failureEvent === undefined ||\n typeof value.failureEvent === 'string') &&\n (value.context === undefined || isRecord(value.context)) &&\n (value.persist === undefined || typeof value.persist === 'boolean')\n );\n}\n\n/**\n * Merges a payload into an event fragment.\n *\n * `properties`, `sensitiveProperties` and `context` are merged one level deep,\n * so a key written twice is replaced rather than combined. This keeps array\n * values predictable: writing a shorter array replaces the longer one instead\n * of leaving stale trailing entries behind.\n *\n * @param fragment - The fragment to merge into.\n * @param payload - The payload to merge.\n * @returns A new fragment with the payload applied.\n */\nfunction mergeEventFragment(\n fragment: AnalyticsEventFragment,\n payload: AnalyticsEventFragmentPayload,\n): AnalyticsEventFragment {\n const context = mergeEventFragmentContext(fragment.context, payload.context);\n\n return {\n ...fragment,\n properties: { ...fragment.properties, ...(payload.properties ?? {}) },\n sensitiveProperties: {\n ...fragment.sensitiveProperties,\n ...(payload.sensitiveProperties ?? {}),\n },\n ...(context === undefined ? {} : { context }),\n lastUpdated: Date.now(),\n };\n}\n\n/**\n * Merges two optional analytics contexts, preserving `undefined` when neither\n * side has one so an empty context is never sent.\n *\n * @param base - The context to merge into.\n * @param override - The context whose fields win.\n * @returns The merged context, or `undefined` when both sides are unset.\n */\nfunction mergeEventFragmentContext(\n base: AnalyticsContext | undefined,\n override: AnalyticsContext | undefined,\n): AnalyticsContext | undefined {\n if (base === undefined && override === undefined) {\n return undefined;\n }\n\n return { ...(base ?? {}), ...(override ?? {}) };\n}\n\n/**\n * The AnalyticsController manages analytics tracking across platforms (Mobile/Extension).\n * It provides a unified interface for tracking events, identifying users, and managing\n * analytics preferences while delegating platform-specific implementation to an\n * {@link AnalyticsPlatformAdapter}.\n *\n * This controller follows the MetaMask controller pattern and integrates with the\n * messenger system to allow other controllers and components to track analytics events.\n * It delegates platform-specific implementation to an {@link AnalyticsPlatformAdapter}.\n *\n * The controller persists `optedIn` and `analyticsId` when composed with a persisted\n * store. The platform must supply a valid `analyticsId` on first launch.\n */\nexport class AnalyticsController extends BaseController<\n 'AnalyticsController',\n AnalyticsControllerState,\n AnalyticsControllerMessenger\n> {\n readonly #platformAdapter: AnalyticsPlatformAdapter;\n\n readonly #isAnonymousEventsFeatureEnabled: boolean;\n\n readonly #isEventQueuePersistenceEnabled: boolean;\n\n readonly #isPreConsentQueueEnabled: boolean;\n\n readonly #isGeolocationEnabled: boolean;\n\n readonly #isEventFragmentsEnabled: boolean;\n\n /**\n * The in-flight (or settled) initialization promise. Set on the first\n * {@link init} call and returned by subsequent calls so overlapping callers\n * await the same work rather than observing a premature completion.\n */\n #initPromise: Promise<void> | undefined;\n\n /**\n * The in-flight (or settled) geolocation resolution, if any. Its presence\n * marks that resolution has been started, so it runs at most once.\n */\n #locationResolvePromise: Promise<void> | undefined;\n\n #locationContext: AnalyticsLocationContext | undefined;\n\n /**\n * Constructs an AnalyticsController instance.\n *\n * @param options - Controller options\n * @param options.state - Initial controller state. Must include a valid UUIDv4 `analyticsId`.\n * Use `getDefaultAnalyticsControllerState()` for default opt-in preferences.\n * @param options.messenger - Messenger used to communicate with BaseController\n * @param options.platformAdapter - Platform adapter implementation for tracking\n * @param options.isAnonymousEventsFeatureEnabled - Whether the anonymous events feature is enabled\n * @param options.isEventQueuePersistenceEnabled - Whether analytics event queue persistence is enabled\n * @param options.isPreConsentQueueEnabled - Whether the pre-consent event queue is enabled\n * @param options.isGeolocationEnabled - Whether geolocation enrichment is enabled\n * @param options.isEventFragmentsEnabled - Whether the event fragments feature is enabled\n * @throws Error if state.analyticsId is missing or not a valid UUIDv4\n * @remarks After construction, call {@link AnalyticsController.init} to complete initialization.\n */\n constructor({\n state,\n messenger,\n platformAdapter,\n isAnonymousEventsFeatureEnabled = false,\n isEventQueuePersistenceEnabled = false,\n isPreConsentQueueEnabled = false,\n isGeolocationEnabled = false,\n isEventFragmentsEnabled = false,\n }: AnalyticsControllerOptions) {\n const initialState: AnalyticsControllerState = {\n ...getDefaultAnalyticsControllerState(),\n ...state,\n };\n\n validateAnalyticsControllerState(\n initialState,\n platformAdapter.skipUUIDv4Check === true,\n );\n\n super({\n name: controllerName,\n metadata: analyticsControllerMetadata,\n state: initialState,\n messenger,\n });\n\n this.#isAnonymousEventsFeatureEnabled = isAnonymousEventsFeatureEnabled;\n this.#isEventQueuePersistenceEnabled = isEventQueuePersistenceEnabled;\n this.#isPreConsentQueueEnabled = isPreConsentQueueEnabled;\n this.#isGeolocationEnabled = isGeolocationEnabled;\n this.#isEventFragmentsEnabled = isEventFragmentsEnabled;\n this.#platformAdapter = platformAdapter;\n this.#initPromise = undefined;\n this.#locationResolvePromise = undefined;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n log('AnalyticsController initialized and ready', {\n enabled: analyticsControllerSelectors.selectEnabled(this.state),\n optedIn: this.state.optedIn,\n consentDecisionMade: this.state.consentDecisionMade,\n analyticsId: this.state.analyticsId,\n eventQueuePersistenceEnabled: this.#isEventQueuePersistenceEnabled,\n preConsentQueueEnabled: this.#isPreConsentQueueEnabled,\n geolocationEnabled: this.#isGeolocationEnabled,\n eventFragmentsEnabled: this.#isEventFragmentsEnabled,\n });\n }\n\n /**\n * Initialize the controller by calling the platform adapter's\n * onSetupCompleted lifecycle hook and replaying any queued events. This\n * method must be called after construction to complete the setup process.\n *\n * When geolocation enrichment is enabled (`isGeolocationEnabled`), geolocation\n * is resolved only for a user who is already opted in; for undecided or\n * opted-out users it is deferred until they opt in (see {@link optIn}), so a\n * user's location is never requested before they consent to analytics. In\n * either case the `GeolocationController` and its\n * `GeolocationController:getGeolocationData` action must be registered before\n * resolution occurs, or enrichment is skipped for the session (a message is\n * logged, see {@link #resolveLocationContext}).\n *\n * Safe to call more than once: the first call performs initialization and\n * subsequent calls return the same in-flight (or settled) promise.\n *\n * @returns A promise that resolves once initialization has completed.\n */\n init(): Promise<void> {\n // Cache the in-flight promise so repeated or overlapping calls share a\n // single initialization and all await the same completion (rather than an\n // early call observing a finished init while work is still pending).\n this.#initPromise ??= this.#performInit();\n return this.#initPromise;\n }\n\n /**\n * Performs the one-time initialization work: resolve geolocation, run the\n * platform adapter's onSetupCompleted lifecycle hook, then replay any queued\n * and pre-consent events.\n */\n async #performInit(): Promise<void> {\n // Snapshot fragment IDs and createdAt before any awaited init work so\n // reconciliation can tell previous-session leftovers from fragments\n // created or replaced while init runs.\n const initEventFragmentSnapshot = new Map<string, number>();\n for (const [id, fragment] of Object.entries(\n this.state.eventFragments ?? {},\n )) {\n if (\n isAnalyticsEventFragment(fragment) &&\n fragment.id === id &&\n typeof fragment.createdAt === 'number'\n ) {\n initEventFragmentSnapshot.set(id, fragment.createdAt);\n }\n }\n\n // Resolve geolocation only when the user is already opted in; for undecided\n // or opted-out users it is deferred to {@link optIn}. Awaited so that an\n // already-opted-in session has location available before events replay.\n await this.#maybeResolveLocation();\n\n // Call onSetupCompleted lifecycle hook after initialization\n // State is already validated, so analyticsId is guaranteed to be a valid UUIDv4\n try {\n this.#platformAdapter.onSetupCompleted(this.state.analyticsId);\n } catch (error) {\n // Log error but don't throw - adapter setup failure shouldn't break controller\n log('Error calling platformAdapter.onSetupCompleted', error);\n }\n\n this.#replayQueuedEvents();\n this.#reconcilePreConsentEvents();\n this.#reconcileEventFragments(initEventFragmentSnapshot);\n }\n\n /**\n * Start resolving the geolocation context if warranted, and return the\n * in-flight (or settled) resolution so callers can await it. No-op unless\n * enrichment is enabled, the user is opted in, and a resolution has not\n * already been started. Deferring resolution until opt-in ensures a user's\n * location is never requested before they consent to analytics (for example,\n * during onboarding).\n *\n * Resolution runs at most once per controller session: the settled promise\n * is retained, so the outcome — including a failure (see\n * {@link #resolveLocationContext}) — is not retried, and events are delivered\n * without location for the rest of the session.\n *\n * @returns The geolocation resolution promise, or `undefined` when no\n * resolution is warranted.\n */\n #maybeResolveLocation(): Promise<void> | undefined {\n if (\n this.#isGeolocationEnabled &&\n this.#locationResolvePromise === undefined &&\n analyticsControllerSelectors.selectEnabled(this.state)\n ) {\n this.#locationResolvePromise = this.#resolveLocationContext();\n }\n\n return this.#locationResolvePromise;\n }\n\n async #resolveLocationContext(): Promise<void> {\n try {\n const geolocation = await this.messenger.call(\n 'GeolocationController:getGeolocationData',\n );\n\n this.#locationContext = buildLocationContext(geolocation);\n } catch (error) {\n // A common cause is the GeolocationController not being registered before\n // resolution runs (at init for an opted-in user, otherwise at opt-in).\n // Name it here so the failure is diagnosable, since enrichment is\n // otherwise skipped silently for the session.\n log(\n 'Failed to resolve geolocation for analytics enrichment; events will be sent without location. Ensure the GeolocationController is registered and initialized before the user opts in when geolocation is enabled.',\n error,\n );\n }\n }\n\n /**\n * Merge the resolved location context into a caller-provided context.\n *\n * Caller-provided `location` fields are preserved, but the fields the\n * controller resolves take precedence over them.\n *\n * @param context - Optional caller-provided context.\n * @returns The context enriched with location, or the original context when\n * no location is known.\n */\n #withLocationContext(\n context?: AnalyticsContext,\n ): AnalyticsContext | undefined {\n if (!this.#locationContext) {\n return context;\n }\n\n const callerLocation = context?.location;\n\n return {\n ...context,\n location: {\n ...(isJsonRecord(callerLocation) ? callerLocation : {}),\n ...this.#locationContext,\n },\n };\n }\n\n /**\n * Send final track payload through the platform adapter or queue it if persistence is enabled.\n *\n * @param eventName - The name of the event.\n * @param properties - Optional event properties.\n * @param context - Optional platform-specific context.\n */\n #sendOrQueueTrackEvent(\n eventName: string,\n properties?: AnalyticsEventProperties,\n context?: AnalyticsContext,\n ): void {\n // Direct delivery: enabled and not persisting.\n if (\n analyticsControllerSelectors.selectEnabled(this.state) &&\n !this.#isEventQueuePersistenceEnabled\n ) {\n this.#platformAdapter.track(eventName, properties, context);\n return;\n }\n\n const queuedEvent: AnalyticsQueuedTrackEvent = {\n type: 'track',\n eventName,\n messageId: uuid(),\n timestamp: new Date().toISOString(),\n ...(properties === undefined ? {} : { properties }),\n ...(context === undefined ? {} : { context }),\n };\n\n // Not yet enabled (reached only while undecided with the pre-consent queue\n // enabled): hold the event until the user opts in.\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n this.#enqueuePreConsentEvent(queuedEvent);\n return;\n }\n\n this.#enqueueEvent(queuedEvent);\n }\n\n /**\n * Send final identify payload through the platform adapter or queue it if persistence is enabled.\n *\n * @param userId - The user ID.\n * @param traits - Optional user traits.\n * @param context - Optional platform-specific context.\n */\n #sendOrQueueIdentifyEvent(\n userId: string,\n traits?: AnalyticsUserTraits,\n context?: AnalyticsContext,\n ): void {\n if (!this.#isEventQueuePersistenceEnabled) {\n this.#platformAdapter.identify(userId, traits, context);\n return;\n }\n\n const queuedEvent: AnalyticsQueuedIdentifyEvent = {\n type: 'identify',\n userId,\n messageId: uuid(),\n timestamp: new Date().toISOString(),\n ...(traits === undefined ? {} : { traits }),\n ...(context === undefined ? {} : { context }),\n };\n\n this.#enqueueEvent(queuedEvent);\n }\n\n /**\n * Send final view payload through the platform adapter or queue it if persistence is enabled.\n *\n * @param name - The view name.\n * @param properties - Optional view properties.\n * @param context - Optional platform-specific context.\n */\n #sendOrQueueViewEvent(\n name: string,\n properties?: AnalyticsEventProperties,\n context?: AnalyticsContext,\n ): void {\n if (!this.#isEventQueuePersistenceEnabled) {\n this.#platformAdapter.view(name, properties, context);\n return;\n }\n\n const queuedEvent: AnalyticsQueuedViewEvent = {\n type: 'view',\n name,\n messageId: uuid(),\n timestamp: new Date().toISOString(),\n ...(properties === undefined ? {} : { properties }),\n ...(context === undefined ? {} : { context }),\n };\n\n this.#enqueueEvent(queuedEvent);\n }\n\n /**\n * Add an analytics event to the queue and send it.\n *\n * @param queuedEvent - The event to enqueue and deliver.\n */\n #enqueueEvent(queuedEvent: AnalyticsQueuedEvent): void {\n const eventQueue: Record<string, Json> = {\n ...(this.state.eventQueue ?? {}),\n [queuedEvent.messageId]: queuedEvent as unknown as Json,\n };\n\n this.update((state) => {\n state.eventQueue = eventQueue as never;\n });\n\n this.#sendQueuedEvent(queuedEvent);\n }\n\n /**\n * Send a queued event through the platform adapter.\n *\n * @param queuedEvent - The queued event to deliver.\n */\n #sendQueuedEvent(queuedEvent: AnalyticsQueuedEvent): void {\n const timestamp = new Date(queuedEvent.timestamp);\n\n if (Number.isNaN(timestamp.getTime())) {\n log('Dropping queued analytics event with invalid timestamp', {\n messageId: queuedEvent.messageId,\n });\n this.#removeQueuedEvent(queuedEvent.messageId);\n return;\n }\n\n const options: AnalyticsDeliveryOptions = {\n messageId: queuedEvent.messageId,\n timestamp,\n callback: (error?: unknown) => {\n if (error) {\n log('Queued analytics event delivery failed', {\n messageId: queuedEvent.messageId,\n error,\n });\n }\n\n this.#removeQueuedEvent(queuedEvent.messageId);\n },\n };\n\n try {\n if (queuedEvent.type === 'track') {\n this.#platformAdapter.track(\n queuedEvent.eventName,\n cloneDeep(queuedEvent.properties),\n cloneDeep(queuedEvent.context),\n options,\n );\n } else if (queuedEvent.type === 'identify') {\n this.#platformAdapter.identify(\n queuedEvent.userId,\n cloneDeep(queuedEvent.traits),\n cloneDeep(queuedEvent.context),\n options,\n );\n } else {\n this.#platformAdapter.view(\n queuedEvent.name,\n cloneDeep(queuedEvent.properties),\n cloneDeep(queuedEvent.context),\n options,\n );\n }\n } catch (error) {\n log('Error sending queued analytics event', {\n messageId: queuedEvent.messageId,\n error,\n });\n }\n }\n\n /**\n * Replay persisted analytics events.\n */\n #replayQueuedEvents(): void {\n if (!this.#isEventQueuePersistenceEnabled || !this.state.eventQueue) {\n return;\n }\n\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n this.#clearQueuedEvents();\n return;\n }\n\n for (const [messageId, queuedEvent] of Object.entries(\n this.state.eventQueue,\n )) {\n if (\n !isAnalyticsQueuedEvent(queuedEvent) ||\n queuedEvent.messageId !== messageId\n ) {\n log('Dropping invalid queued analytics event', { messageId });\n this.#removeQueuedEvent(messageId);\n continue;\n }\n\n this.#sendQueuedEvent(queuedEvent);\n }\n }\n\n /**\n * Remove a queued analytics event.\n *\n * @param messageId - The queued event message ID.\n */\n #removeQueuedEvent(messageId: string): void {\n const currentEventQueue = this.state.eventQueue;\n\n if (\n !currentEventQueue ||\n !Object.prototype.hasOwnProperty.call(currentEventQueue, messageId)\n ) {\n return;\n }\n\n const { [messageId]: _deletedEvent, ...eventQueue } = currentEventQueue;\n\n this.update((state) => {\n state.eventQueue = eventQueue as never;\n });\n }\n\n /**\n * Clear all queued analytics events.\n */\n #clearQueuedEvents(): void {\n if (\n !this.state.eventQueue ||\n Object.keys(this.state.eventQueue).length === 0\n ) {\n return;\n }\n\n this.update((state) => {\n state.eventQueue = {} as never;\n });\n }\n\n /**\n * Add an event to the pre-consent queue without delivering it.\n *\n * @param queuedEvent - The event to hold until the user opts in.\n */\n #enqueuePreConsentEvent(queuedEvent: AnalyticsQueuedEvent): void {\n const preConsentEventQueue: Record<string, Json> = {\n ...(this.state.preConsentEventQueue ?? {}),\n [queuedEvent.messageId]: queuedEvent as unknown as Json,\n };\n\n this.update((state) => {\n state.preConsentEventQueue = preConsentEventQueue as never;\n });\n }\n\n /**\n * Replay queued pre-consent events through the delivery path.\n *\n * Only called by {@link #reconcilePreConsentEvents}, which guarantees the\n * pre-consent queue is enabled and that the user is opted in. The queue is\n * cleared before replaying so events cannot be re-queued or replayed twice.\n *\n * @param queue - The pre-consent event queue to replay.\n */\n #replayPreConsentEvents(queue: Record<string, Json>): void {\n this.#clearPreConsentEvents();\n\n for (const [messageId, queuedEvent] of Object.entries(queue)) {\n if (\n !isAnalyticsQueuedEvent(queuedEvent) ||\n queuedEvent.messageId !== messageId\n ) {\n log('Dropping invalid queued pre-consent analytics event', {\n messageId,\n });\n continue;\n }\n\n const eventToReplay = this.#enrichPreConsentEvent(queuedEvent);\n\n if (this.#isEventQueuePersistenceEnabled) {\n this.#enqueueEvent(eventToReplay);\n } else {\n this.#sendQueuedEvent(eventToReplay);\n }\n }\n }\n\n /**\n * Enrich a pre-consent event with the geolocation resolved on opt-in.\n *\n * Pre-consent events are captured while geolocation is not yet resolved, so\n * they are re-enriched here as they replay. Anonymous track payloads are left\n * untouched, since they must never carry location.\n *\n * @param queuedEvent - The queued pre-consent event.\n * @returns The event with its context enriched, or the event unchanged when\n * enrichment does not apply.\n */\n #enrichPreConsentEvent(\n queuedEvent: AnalyticsQueuedEvent,\n ): AnalyticsQueuedEvent {\n if (\n queuedEvent.type === 'track' &&\n queuedEvent.properties?.anonymous === true\n ) {\n return queuedEvent;\n }\n\n const context = this.#withLocationContext(queuedEvent.context);\n\n return {\n ...queuedEvent,\n ...(context === undefined ? {} : { context }),\n };\n }\n\n /**\n * Clear all queued pre-consent events.\n */\n #clearPreConsentEvents(): void {\n if (!this.state.preConsentEventQueue) {\n return;\n }\n\n this.update((state) => {\n state.preConsentEventQueue = {} as never;\n });\n }\n\n /**\n * Reconcile the pre-consent queue on initialization.\n *\n * The queue should normally be empty unless the user is still undecided. This\n * handles the rare cases where a consent decision was persisted but the queue\n * was not flushed/cleared (e.g. an interrupted shutdown): replay it if the\n * user is opted in, or clear it if they opted out.\n *\n * If the pre-consent queue is disabled, any stale persisted entries (e.g. from\n * a previous session where it was enabled) are dropped so they can never be\n * replayed.\n */\n #reconcilePreConsentEvents(): void {\n const queue = this.state.preConsentEventQueue;\n\n if (!queue) {\n return;\n }\n\n if (!this.#isPreConsentQueueEnabled) {\n this.#clearPreConsentEvents();\n return;\n }\n\n if (this.state.optedIn) {\n this.#replayPreConsentEvents(queue);\n } else if (this.state.consentDecisionMade) {\n this.#clearPreConsentEvents();\n }\n }\n\n /**\n * Reconcile persisted event fragments on initialization.\n *\n * A fragment describes a journey that was in progress when the previous\n * session ended. Only fragments that opted into `persist` and are younger\n * than {@link EVENT_FRAGMENT_MAX_AGE} can be resumed, so the rest are\n * discarded. Nothing is emitted: a journey that never reached its own\n * finalization is not a failure, just an unfinished one.\n *\n * If the feature is disabled (e.g. a previous session had it enabled), or the\n * consent state no longer allows capture (e.g. the fragments were written\n * before the user opted out), every persisted fragment is dropped so none of\n * them can linger.\n *\n * Non-persistent fragments are dropped only when their ID and `createdAt`\n * match a fragment present at the start of {@link init}. Fragments created\n * or replaced while init is in flight are kept so a slow startup path cannot\n * discard an in-progress journey, as long as they have not expired.\n *\n * @param initEventFragmentSnapshot - Fragment IDs and `createdAt` values\n * present when {@link init} began.\n */\n #reconcileEventFragments(\n initEventFragmentSnapshot: Map<string, number>,\n ): void {\n const fragments = this.state.eventFragments;\n\n if (!fragments) {\n return;\n }\n\n if (!this.#isEventFragmentsEnabled || !this.#isAnalyticsCaptureAllowed()) {\n this.#clearEventFragments();\n return;\n }\n\n this.#purgeStaleEventFragments(fragments, initEventFragmentSnapshot);\n }\n\n /**\n * Drop every persisted fragment that is invalid, expired, did not opt into\n * `persist`, or was already present with the same `createdAt` when\n * {@link init} began.\n *\n * Only called by {@link #reconcileEventFragments}, which guarantees the\n * fragments exist and that the event fragments feature is enabled.\n *\n * @param currentEventFragments - The persisted fragments to filter.\n * @param initEventFragmentSnapshot - Fragment IDs and `createdAt` values\n * present when {@link init} began.\n */\n #purgeStaleEventFragments(\n currentEventFragments: AnalyticsEventFragments,\n initEventFragmentSnapshot: Map<string, number>,\n ): void {\n const eventFragments: AnalyticsEventFragments = {};\n const now = Date.now();\n\n for (const [id, fragment] of Object.entries(currentEventFragments)) {\n if (!isAnalyticsEventFragment(fragment) || fragment.id !== id) {\n log('Dropping invalid persisted event fragment', { id });\n continue;\n }\n\n if (now - fragment.lastUpdated > EVENT_FRAGMENT_MAX_AGE) {\n log('Dropping expired persisted event fragment', { id });\n continue;\n }\n\n const snapshotCreatedAt = initEventFragmentSnapshot.get(id);\n\n if (\n fragment.persist === true ||\n snapshotCreatedAt === undefined ||\n fragment.createdAt !== snapshotCreatedAt\n ) {\n eventFragments[id] = fragment;\n }\n }\n\n if (\n Object.keys(eventFragments).length ===\n Object.keys(currentEventFragments).length\n ) {\n return;\n }\n\n this.update((state) => {\n state.eventFragments = eventFragments as never;\n });\n }\n\n /**\n * Read an event fragment from state without the feature guard.\n *\n * @param id - The fragment ID.\n * @returns The fragment, or `undefined` when no fragment has that ID.\n */\n #getEventFragment(id: string): AnalyticsEventFragment | undefined {\n return this.state.eventFragments?.[id];\n }\n\n /**\n * Write an event fragment to state, replacing any fragment with the same ID.\n *\n * @param fragment - The fragment to store.\n */\n #setEventFragment(fragment: AnalyticsEventFragment): void {\n const eventFragments: AnalyticsEventFragments = {\n ...this.state.eventFragments,\n [fragment.id]: fragment,\n };\n\n this.update((state) => {\n state.eventFragments = eventFragments as never;\n });\n }\n\n /**\n * Remove an event fragment from state.\n *\n * @param id - The fragment ID.\n */\n #removeEventFragment(id: string): void {\n const currentEventFragments = this.state.eventFragments;\n\n if (\n !currentEventFragments ||\n !Object.prototype.hasOwnProperty.call(currentEventFragments, id)\n ) {\n return;\n }\n\n const { [id]: _deletedFragment, ...eventFragments } = currentEventFragments;\n\n this.update((state) => {\n state.eventFragments = eventFragments as never;\n });\n }\n\n /**\n * Clear all event fragments.\n */\n #clearEventFragments(): void {\n if (\n !this.state.eventFragments ||\n Object.keys(this.state.eventFragments).length === 0\n ) {\n return;\n }\n\n this.update((state) => {\n state.eventFragments = {} as never;\n });\n }\n\n /**\n * Returns whether an event fragment call should be ignored, either because\n * the feature is disabled or because the consent state does not allow\n * capture. The ignored call is logged so a missing `isEventFragmentsEnabled`\n * or an unexpected consent state is diagnosable rather than silent.\n *\n * Consent is checked on every call, not just on the ones that emit, so a\n * fragment never accumulates data for an event that could not be delivered.\n *\n * @param method - The name of the method that was called.\n * @returns True when the call should be ignored.\n */\n #shouldIgnoreEventFragmentCall(method: string): boolean {\n if (!this.#isEventFragmentsEnabled) {\n log(\n 'Ignoring event fragment call because the event fragments feature is disabled',\n { method },\n );\n\n return true;\n }\n\n if (!this.#isAnalyticsCaptureAllowed()) {\n log(\n 'Ignoring event fragment call because the consent state does not allow capturing analytics',\n { method },\n );\n\n return true;\n }\n\n return false;\n }\n\n /**\n * Emit one of an event fragment's events, carrying the properties the\n * fragment has accumulated.\n *\n * Delivery goes through {@link trackEvent}, so consent gating, the anonymous\n * payload split, the pre-consent queue and geolocation enrichment all apply.\n *\n * @param fragment - The fragment supplying the properties.\n * @param name - The name of the event to emit.\n * @param context - The context to send with the event.\n */\n #emitEventFragment(\n fragment: AnalyticsEventFragment,\n name: string,\n context: AnalyticsContext | undefined,\n ): void {\n const properties = { ...fragment.properties };\n const sensitiveProperties = { ...fragment.sensitiveProperties };\n\n this.trackEvent(\n {\n name,\n properties,\n sensitiveProperties,\n saveDataRecording: false,\n hasProperties:\n Object.keys(properties).length > 0 ||\n Object.keys(sensitiveProperties).length > 0,\n },\n context,\n );\n }\n\n /**\n * Returns whether the current consent state allows analytics data to be\n * captured, either for immediate delivery or to be held until the user\n * decides.\n *\n * Capture is allowed once the user has opted in, and also while they are\n * undecided if the pre-consent queue is enabled: what is captured then is\n * replayed when they opt in (see {@link optIn}) and discarded if they opt out\n * (see {@link optOut}). An explicit opt-out never allows capture.\n *\n * @returns True when analytics data may be captured.\n */\n #isAnalyticsCaptureAllowed(): boolean {\n if (analyticsControllerSelectors.selectEnabled(this.state)) {\n return true;\n }\n\n return this.#isPreConsentQueueEnabled && !this.state.consentDecisionMade;\n }\n\n /**\n * Track an analytics event.\n *\n * Events are only tracked if analytics is enabled.\n *\n * @param event - Analytics event with properties and sensitive properties\n * @param context - Optional platform-specific context forwarded to the platform adapter.\n */\n trackEvent(event: AnalyticsTrackingEvent, context?: AnalyticsContext): void {\n // An event captured while the user is still undecided is held in the\n // pre-consent queue (see #sendOrQueueTrackEvent) instead of being\n // delivered, and replayed if they later opt in.\n if (!this.#isAnalyticsCaptureAllowed()) {\n return;\n }\n\n // if event does not have properties, send event without properties\n // and return to prevent any additional processing\n if (!event.hasProperties) {\n this.#sendOrQueueTrackEvent(\n event.name,\n undefined,\n this.#withLocationContext(context),\n );\n return;\n }\n\n // Track regular properties first if anonymous events feature is enabled\n if (this.#isAnonymousEventsFeatureEnabled) {\n // Note: Even if regular properties object is empty, we still send it to ensure\n // an event with user ID is tracked.\n this.#sendOrQueueTrackEvent(\n event.name,\n {\n ...event.properties,\n },\n this.#withLocationContext(context),\n );\n }\n\n const hasSensitiveProperties =\n Object.keys(event.sensitiveProperties).length > 0;\n\n if (!this.#isAnonymousEventsFeatureEnabled || hasSensitiveProperties) {\n this.#sendOrQueueTrackEvent(\n event.name,\n {\n ...event.properties,\n ...event.sensitiveProperties,\n ...(hasSensitiveProperties && { anonymous: true }),\n },\n // When the anonymous events feature is enabled, this payload is the\n // anonymous one and must carry no geolocation. When the feature is\n // disabled, this is the single identified payload, so it is enriched.\n this.#isAnonymousEventsFeatureEnabled\n ? context\n : this.#withLocationContext(context),\n );\n }\n }\n\n /**\n * Identify a user for analytics.\n *\n * @param traits - User traits/properties\n * @param context - Optional platform-specific context forwarded to the platform adapter.\n */\n identify(traits?: AnalyticsUserTraits, context?: AnalyticsContext): void {\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n return;\n }\n\n // Delegate to platform adapter using the current analytics ID\n this.#sendOrQueueIdentifyEvent(\n this.state.analyticsId,\n traits,\n this.#withLocationContext(context),\n );\n }\n\n /**\n * Track a page or screen view.\n *\n * @param name - The identifier/name of the page or screen being viewed (e.g., \"home\", \"settings\", \"wallet\")\n * @param properties - Optional properties associated with the view\n * @param context - Optional platform-specific context forwarded to the platform adapter.\n */\n trackView(\n name: string,\n properties?: AnalyticsEventProperties,\n context?: AnalyticsContext,\n ): void {\n if (!analyticsControllerSelectors.selectEnabled(this.state)) {\n return;\n }\n\n // Delegate to platform adapter\n this.#sendOrQueueViewEvent(\n name,\n properties,\n this.#withLocationContext(context),\n );\n }\n\n /**\n * Create an event fragment.\n *\n * A fragment accumulates properties across a user journey so that several\n * parts of a client can contribute to the same set of events without\n * re-deriving them. Declaring `successEvent` and `failureEvent` turns the\n * fragment into a funnel that {@link finalizeEventFragment} closes. Declaring\n * none of the event names makes it a pure property bag that the client reads\n * back with {@link getEventFragmentById} when it emits its own events.\n *\n * Any existing fragment with the same ID is replaced, so a new journey never\n * inherits properties from a stale one.\n *\n * Nothing is created unless the user is opted in, or undecided with the\n * pre-consent queue enabled, so an opted-out user accumulates no fragment\n * data.\n *\n * @param options - The fragment definition. An ID is generated when one is\n * not supplied.\n * @returns A read-only copy of the created fragment, or `undefined` when the\n * event fragments feature is disabled or the consent state does not allow\n * capture. Mutating the returned object does not change controller state.\n * Use {@link updateEventFragment} or {@link upsertEventFragment} to write.\n */\n createEventFragment(\n options: AnalyticsEventFragmentOptions = {},\n ): ReadonlyAnalyticsEventFragment | undefined {\n if (this.#shouldIgnoreEventFragmentCall('createEventFragment')) {\n return undefined;\n }\n\n const now = Date.now();\n\n const fragment: AnalyticsEventFragment = {\n id: options.id ?? uuid(),\n properties: { ...(options.properties ?? {}) },\n sensitiveProperties: { ...(options.sensitiveProperties ?? {}) },\n createdAt: now,\n lastUpdated: now,\n ...(options.initialEvent === undefined\n ? {}\n : { initialEvent: options.initialEvent }),\n ...(options.successEvent === undefined\n ? {}\n : { successEvent: options.successEvent }),\n ...(options.failureEvent === undefined\n ? {}\n : { failureEvent: options.failureEvent }),\n ...(options.context === undefined\n ? {}\n : { context: { ...options.context } }),\n ...(options.persist === undefined ? {} : { persist: options.persist }),\n };\n\n this.#setEventFragment(fragment);\n\n if (fragment.initialEvent) {\n this.#emitEventFragment(\n fragment,\n fragment.initialEvent,\n fragment.context,\n );\n }\n\n return cloneDeep(fragment);\n }\n\n /**\n * Write to an event fragment, creating a property bag if none exists.\n *\n * This is the ergonomic entry point for contributors that do not know\n * whether the journey has been started yet, and it avoids the read then\n * write race a caller would otherwise have to implement itself.\n *\n * @param id - The fragment ID.\n * @param payload - The properties and context to merge in.\n */\n upsertEventFragment(\n id: string,\n payload: AnalyticsEventFragmentPayload = {},\n ): void {\n if (this.#shouldIgnoreEventFragmentCall('upsertEventFragment')) {\n return;\n }\n\n const fragment = this.#getEventFragment(id);\n\n if (!fragment) {\n this.createEventFragment({ id, ...payload });\n return;\n }\n\n this.#setEventFragment(mergeEventFragment(fragment, payload));\n }\n\n /**\n * Write to an existing event fragment.\n *\n * @param id - The fragment ID.\n * @param payload - The properties and context to merge in.\n * @throws Error if no fragment has that ID when the call is not ignored.\n * Use {@link upsertEventFragment} when the fragment may not exist yet.\n * When the event fragments feature is disabled or the consent state does not\n * allow capture, the call is a logged no-op and does not throw.\n */\n updateEventFragment(\n id: string,\n payload: AnalyticsEventFragmentPayload = {},\n ): void {\n if (this.#shouldIgnoreEventFragmentCall('updateEventFragment')) {\n return;\n }\n\n const fragment = this.#getEventFragment(id);\n\n if (!fragment) {\n throw new Error(`Event fragment with id ${id} does not exist.`);\n }\n\n this.#setEventFragment(mergeEventFragment(fragment, payload));\n }\n\n /**\n * Read an event fragment.\n *\n * @param id - The fragment ID.\n * @returns A read-only copy of the fragment, or `undefined` when no fragment\n * has that ID, the event fragments feature is disabled, or the consent state\n * does not allow capture. Mutating the returned object does not change\n * controller state. Use {@link updateEventFragment} or\n * {@link upsertEventFragment} to write.\n */\n getEventFragmentById(id: string): ReadonlyAnalyticsEventFragment | undefined {\n if (this.#shouldIgnoreEventFragmentCall('getEventFragmentById')) {\n return undefined;\n }\n\n const fragment = this.#getEventFragment(id);\n\n return fragment === undefined ? undefined : cloneDeep(fragment);\n }\n\n /**\n * Discard an event fragment without emitting anything.\n *\n * @param id - The fragment ID.\n */\n deleteEventFragment(id: string): void {\n if (this.#shouldIgnoreEventFragmentCall('deleteEventFragment')) {\n return;\n }\n\n this.#removeEventFragment(id);\n }\n\n /**\n * Close an event fragment, emitting its closing event and discarding it.\n *\n * The event emitted is `failureEvent` when the journey was abandoned and\n * `successEvent` otherwise. A fragment that does not declare the relevant\n * event name is discarded silently, which is what makes a pure property bag\n * possible.\n *\n * @param id - The fragment ID.\n * @param options - Finalization options.\n * @param options.abandoned - Whether the journey was abandoned.\n * @param options.context - Context merged over the fragment's own context.\n * @throws Error if no fragment has that ID when the call is not ignored.\n * When the event fragments feature is disabled or the consent state does not\n * allow capture, the call is a logged no-op and does not throw.\n */\n finalizeEventFragment(\n id: string,\n { abandoned = false, context }: AnalyticsEventFragmentFinalizeOptions = {},\n ): void {\n if (this.#shouldIgnoreEventFragmentCall('finalizeEventFragment')) {\n return;\n }\n\n const fragment = this.#getEventFragment(id);\n\n if (!fragment) {\n throw new Error(`Event fragment with id ${id} does not exist.`);\n }\n\n const eventName = abandoned ? fragment.failureEvent : fragment.successEvent;\n\n if (eventName) {\n this.#emitEventFragment(\n fragment,\n eventName,\n mergeEventFragmentContext(fragment.context, context),\n );\n }\n\n this.#removeEventFragment(id);\n }\n\n /**\n * Opt in to analytics.\n *\n * Records that a consent decision has been made and replays any events that\n * were queued while the user was undecided.\n *\n * When geolocation enrichment is enabled, geolocation is resolved here (once\n * the user has consented) and awaited before the queued events are replayed,\n * so those events are enriched with the resolved location as they are sent.\n *\n * @returns A promise that resolves once opt-in processing has completed.\n */\n async optIn(): Promise<void> {\n this.update((state) => {\n state.optedIn = true;\n state.consentDecisionMade = true;\n });\n\n // Now that the user has consented, resolve geolocation (once) and wait for\n // it so the queued pre-consent events can be enriched as they replay.\n await this.#maybeResolveLocation();\n\n // Reconcile against the current state rather than replaying blindly: the\n // consent decision may have changed while geolocation was resolving (e.g.\n // resetConsentDecision ran during the await), and preserved pre-consent\n // events must not be delivered once the user is no longer opted in.\n this.#reconcilePreConsentEvents();\n }\n\n /**\n * Opt out of analytics.\n *\n * Records that a consent decision has been made and discards any persisted\n * events and in-progress event fragments so nothing captured before the\n * decision is ever delivered.\n */\n optOut(): void {\n this.update((state) => {\n state.optedIn = false;\n state.consentDecisionMade = true;\n });\n\n this.#clearQueuedEvents();\n this.#clearPreConsentEvents();\n this.#clearEventFragments();\n }\n\n /**\n * Reset the consent decision back to undecided.\n *\n * Intended for client flows that restart onboarding. Clears the opt-in\n * preference and discards the delivery queue, but preserves any pre-consent\n * events so they can still be replayed if the user opts in again. The user is\n * treated as undecided again.\n *\n * In-progress event fragments are kept only while the undecided user can\n * still accumulate them, and discarded otherwise, so no fragment outlives the\n * consent state that allowed it.\n */\n resetConsentDecision(): void {\n this.update((state) => {\n state.optedIn = false;\n state.consentDecisionMade = false;\n });\n\n this.#clearQueuedEvents();\n\n if (!this.#isAnalyticsCaptureAllowed()) {\n this.#clearEventFragments();\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventFragment.types.cjs","sourceRoot":"","sources":["../src/EventFragment.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AnalyticsContext,\n AnalyticsEventProperties,\n} from './AnalyticsPlatformAdapter.types';\n\n/**\n * A bag of analytics properties that accumulates across a user journey.\n *\n * A fragment lets several parts of a client contribute properties to the same\n * logical journey (a signature request, a transaction confirmation) without\n * having to re-derive them for every event, and lets the journey be closed as\n * a success or a failure.\n *\n * All three event names are optional. A fragment that declares none of them\n * never emits anything and acts purely as a property bag that the client reads\n * back with {@link AnalyticsController.getEventFragmentById} at the moment it\n * emits its own event.\n */\nexport type AnalyticsEventFragment = {\n /**\n * The fragment identifier, unique per client.\n */\n id: string;\n\n /**\n * Properties tracked with every event this fragment emits.\n */\n properties: AnalyticsEventProperties;\n\n /**\n * Properties that must not be linked to the user's analytics ID. They are\n * delivered on a separate anonymous payload when the anonymous events\n * feature is enabled.\n */\n sensitiveProperties: AnalyticsEventProperties;\n\n /**\n * Name of an event emitted immediately when the fragment is created.\n */\n initialEvent?: string;\n\n /**\n * Name of the event emitted when the fragment is finalized normally.\n */\n successEvent?: string;\n\n /**\n * Name of the event emitted when the fragment is finalized as abandoned.\n */\n failureEvent?: string;\n\n /**\n * Platform-specific context forwarded with every event this fragment emits.\n */\n context?: AnalyticsContext;\n\n /**\n * Whether the fragment survives {@link AnalyticsController.init}. Fragments\n * that do not set this are discarded when the controller re-initializes,\n * since the journey they belonged to cannot be resumed. Even with this set,\n * a fragment whose {@link lastUpdated} is older than the controller's max\n * fragment age is discarded on init.\n */\n persist?: boolean;\n\n /**\n * `Date.now()` when the fragment was created.\n */\n createdAt: number;\n\n /**\n * `Date.now()` when the fragment was last written to. Used on\n * {@link AnalyticsController.init} to expire abandoned persisted fragments.\n */\n lastUpdated: number;\n};\n\n/**\n * Public, read-only view of an {@link AnalyticsEventFragment}.\n *\n * Returned by {@link AnalyticsController.createEventFragment} and\n * {@link AnalyticsController.getEventFragmentById}. Callers must use\n * {@link AnalyticsController.updateEventFragment} (or\n * {@link AnalyticsController.upsertEventFragment}) to modify fragment data.\n */\nexport type ReadonlyAnalyticsEventFragment = Readonly<{\n id: string;\n properties: Readonly<AnalyticsEventProperties>;\n sensitiveProperties: Readonly<AnalyticsEventProperties>;\n initialEvent?: string;\n successEvent?: string;\n failureEvent?: string;\n context?: Readonly<AnalyticsContext>;\n persist?: boolean;\n createdAt: number;\n lastUpdated: number;\n}>;\n\n/**\n * Event fragments keyed by fragment ID.\n */\nexport type AnalyticsEventFragments = Record<string, AnalyticsEventFragment>;\n\n/**\n * Options accepted when creating an event fragment. An `id` is generated when\n * one is not supplied.\n */\nexport type AnalyticsEventFragmentOptions = Partial<\n Pick<\n AnalyticsEventFragment,\n | 'id'\n | 'initialEvent'\n | 'successEvent'\n | 'failureEvent'\n | 'properties'\n | 'sensitiveProperties'\n | 'context'\n | 'persist'\n >\n>;\n\n/**\n * The fields that can be written to an existing event fragment.\n */\nexport type AnalyticsEventFragmentPayload = Pick<\n AnalyticsEventFragmentOptions,\n 'properties' | 'sensitiveProperties' | 'context'\n>;\n\n/**\n * Options accepted when finalizing an event fragment.\n */\nexport type AnalyticsEventFragmentFinalizeOptions = {\n /**\n * Whether the journey was abandoned, which selects `failureEvent` instead of\n * `successEvent`.\n */\n abandoned?: boolean;\n\n /**\n * Context merged over the fragment's own context for the emitted event.\n */\n context?: AnalyticsContext;\n};\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { AnalyticsContext, AnalyticsEventProperties } from "./AnalyticsPlatformAdapter.types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* A bag of analytics properties that accumulates across a user journey.
|
|
4
|
+
*
|
|
5
|
+
* A fragment lets several parts of a client contribute properties to the same
|
|
6
|
+
* logical journey (a signature request, a transaction confirmation) without
|
|
7
|
+
* having to re-derive them for every event, and lets the journey be closed as
|
|
8
|
+
* a success or a failure.
|
|
9
|
+
*
|
|
10
|
+
* All three event names are optional. A fragment that declares none of them
|
|
11
|
+
* never emits anything and acts purely as a property bag that the client reads
|
|
12
|
+
* back with {@link AnalyticsController.getEventFragmentById} at the moment it
|
|
13
|
+
* emits its own event.
|
|
14
|
+
*/
|
|
15
|
+
export type AnalyticsEventFragment = {
|
|
16
|
+
/**
|
|
17
|
+
* The fragment identifier, unique per client.
|
|
18
|
+
*/
|
|
19
|
+
id: string;
|
|
20
|
+
/**
|
|
21
|
+
* Properties tracked with every event this fragment emits.
|
|
22
|
+
*/
|
|
23
|
+
properties: AnalyticsEventProperties;
|
|
24
|
+
/**
|
|
25
|
+
* Properties that must not be linked to the user's analytics ID. They are
|
|
26
|
+
* delivered on a separate anonymous payload when the anonymous events
|
|
27
|
+
* feature is enabled.
|
|
28
|
+
*/
|
|
29
|
+
sensitiveProperties: AnalyticsEventProperties;
|
|
30
|
+
/**
|
|
31
|
+
* Name of an event emitted immediately when the fragment is created.
|
|
32
|
+
*/
|
|
33
|
+
initialEvent?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Name of the event emitted when the fragment is finalized normally.
|
|
36
|
+
*/
|
|
37
|
+
successEvent?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Name of the event emitted when the fragment is finalized as abandoned.
|
|
40
|
+
*/
|
|
41
|
+
failureEvent?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Platform-specific context forwarded with every event this fragment emits.
|
|
44
|
+
*/
|
|
45
|
+
context?: AnalyticsContext;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the fragment survives {@link AnalyticsController.init}. Fragments
|
|
48
|
+
* that do not set this are discarded when the controller re-initializes,
|
|
49
|
+
* since the journey they belonged to cannot be resumed. Even with this set,
|
|
50
|
+
* a fragment whose {@link lastUpdated} is older than the controller's max
|
|
51
|
+
* fragment age is discarded on init.
|
|
52
|
+
*/
|
|
53
|
+
persist?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* `Date.now()` when the fragment was created.
|
|
56
|
+
*/
|
|
57
|
+
createdAt: number;
|
|
58
|
+
/**
|
|
59
|
+
* `Date.now()` when the fragment was last written to. Used on
|
|
60
|
+
* {@link AnalyticsController.init} to expire abandoned persisted fragments.
|
|
61
|
+
*/
|
|
62
|
+
lastUpdated: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Public, read-only view of an {@link AnalyticsEventFragment}.
|
|
66
|
+
*
|
|
67
|
+
* Returned by {@link AnalyticsController.createEventFragment} and
|
|
68
|
+
* {@link AnalyticsController.getEventFragmentById}. Callers must use
|
|
69
|
+
* {@link AnalyticsController.updateEventFragment} (or
|
|
70
|
+
* {@link AnalyticsController.upsertEventFragment}) to modify fragment data.
|
|
71
|
+
*/
|
|
72
|
+
export type ReadonlyAnalyticsEventFragment = Readonly<{
|
|
73
|
+
id: string;
|
|
74
|
+
properties: Readonly<AnalyticsEventProperties>;
|
|
75
|
+
sensitiveProperties: Readonly<AnalyticsEventProperties>;
|
|
76
|
+
initialEvent?: string;
|
|
77
|
+
successEvent?: string;
|
|
78
|
+
failureEvent?: string;
|
|
79
|
+
context?: Readonly<AnalyticsContext>;
|
|
80
|
+
persist?: boolean;
|
|
81
|
+
createdAt: number;
|
|
82
|
+
lastUpdated: number;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Event fragments keyed by fragment ID.
|
|
86
|
+
*/
|
|
87
|
+
export type AnalyticsEventFragments = Record<string, AnalyticsEventFragment>;
|
|
88
|
+
/**
|
|
89
|
+
* Options accepted when creating an event fragment. An `id` is generated when
|
|
90
|
+
* one is not supplied.
|
|
91
|
+
*/
|
|
92
|
+
export type AnalyticsEventFragmentOptions = Partial<Pick<AnalyticsEventFragment, 'id' | 'initialEvent' | 'successEvent' | 'failureEvent' | 'properties' | 'sensitiveProperties' | 'context' | 'persist'>>;
|
|
93
|
+
/**
|
|
94
|
+
* The fields that can be written to an existing event fragment.
|
|
95
|
+
*/
|
|
96
|
+
export type AnalyticsEventFragmentPayload = Pick<AnalyticsEventFragmentOptions, 'properties' | 'sensitiveProperties' | 'context'>;
|
|
97
|
+
/**
|
|
98
|
+
* Options accepted when finalizing an event fragment.
|
|
99
|
+
*/
|
|
100
|
+
export type AnalyticsEventFragmentFinalizeOptions = {
|
|
101
|
+
/**
|
|
102
|
+
* Whether the journey was abandoned, which selects `failureEvent` instead of
|
|
103
|
+
* `successEvent`.
|
|
104
|
+
*/
|
|
105
|
+
abandoned?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Context merged over the fragment's own context for the emitted event.
|
|
108
|
+
*/
|
|
109
|
+
context?: AnalyticsContext;
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=EventFragment.types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventFragment.types.d.cts","sourceRoot":"","sources":["../src/EventFragment.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,6CAAyC;AAE1C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,UAAU,EAAE,wBAAwB,CAAC;IAErC;;;;OAIG;IACH,mBAAmB,EAAE,wBAAwB,CAAC;IAE9C;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAE3B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,8BAA8B,GAAG,QAAQ,CAAC;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IAC/C,mBAAmB,EAAE,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAE7E;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,OAAO,CACjD,IAAI,CACF,sBAAsB,EACpB,IAAI,GACJ,cAAc,GACd,cAAc,GACd,cAAc,GACd,YAAY,GACZ,qBAAqB,GACrB,SAAS,GACT,SAAS,CACZ,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC9C,6BAA6B,EAC7B,YAAY,GAAG,qBAAqB,GAAG,SAAS,CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { AnalyticsContext, AnalyticsEventProperties } from "./AnalyticsPlatformAdapter.types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* A bag of analytics properties that accumulates across a user journey.
|
|
4
|
+
*
|
|
5
|
+
* A fragment lets several parts of a client contribute properties to the same
|
|
6
|
+
* logical journey (a signature request, a transaction confirmation) without
|
|
7
|
+
* having to re-derive them for every event, and lets the journey be closed as
|
|
8
|
+
* a success or a failure.
|
|
9
|
+
*
|
|
10
|
+
* All three event names are optional. A fragment that declares none of them
|
|
11
|
+
* never emits anything and acts purely as a property bag that the client reads
|
|
12
|
+
* back with {@link AnalyticsController.getEventFragmentById} at the moment it
|
|
13
|
+
* emits its own event.
|
|
14
|
+
*/
|
|
15
|
+
export type AnalyticsEventFragment = {
|
|
16
|
+
/**
|
|
17
|
+
* The fragment identifier, unique per client.
|
|
18
|
+
*/
|
|
19
|
+
id: string;
|
|
20
|
+
/**
|
|
21
|
+
* Properties tracked with every event this fragment emits.
|
|
22
|
+
*/
|
|
23
|
+
properties: AnalyticsEventProperties;
|
|
24
|
+
/**
|
|
25
|
+
* Properties that must not be linked to the user's analytics ID. They are
|
|
26
|
+
* delivered on a separate anonymous payload when the anonymous events
|
|
27
|
+
* feature is enabled.
|
|
28
|
+
*/
|
|
29
|
+
sensitiveProperties: AnalyticsEventProperties;
|
|
30
|
+
/**
|
|
31
|
+
* Name of an event emitted immediately when the fragment is created.
|
|
32
|
+
*/
|
|
33
|
+
initialEvent?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Name of the event emitted when the fragment is finalized normally.
|
|
36
|
+
*/
|
|
37
|
+
successEvent?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Name of the event emitted when the fragment is finalized as abandoned.
|
|
40
|
+
*/
|
|
41
|
+
failureEvent?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Platform-specific context forwarded with every event this fragment emits.
|
|
44
|
+
*/
|
|
45
|
+
context?: AnalyticsContext;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the fragment survives {@link AnalyticsController.init}. Fragments
|
|
48
|
+
* that do not set this are discarded when the controller re-initializes,
|
|
49
|
+
* since the journey they belonged to cannot be resumed. Even with this set,
|
|
50
|
+
* a fragment whose {@link lastUpdated} is older than the controller's max
|
|
51
|
+
* fragment age is discarded on init.
|
|
52
|
+
*/
|
|
53
|
+
persist?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* `Date.now()` when the fragment was created.
|
|
56
|
+
*/
|
|
57
|
+
createdAt: number;
|
|
58
|
+
/**
|
|
59
|
+
* `Date.now()` when the fragment was last written to. Used on
|
|
60
|
+
* {@link AnalyticsController.init} to expire abandoned persisted fragments.
|
|
61
|
+
*/
|
|
62
|
+
lastUpdated: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Public, read-only view of an {@link AnalyticsEventFragment}.
|
|
66
|
+
*
|
|
67
|
+
* Returned by {@link AnalyticsController.createEventFragment} and
|
|
68
|
+
* {@link AnalyticsController.getEventFragmentById}. Callers must use
|
|
69
|
+
* {@link AnalyticsController.updateEventFragment} (or
|
|
70
|
+
* {@link AnalyticsController.upsertEventFragment}) to modify fragment data.
|
|
71
|
+
*/
|
|
72
|
+
export type ReadonlyAnalyticsEventFragment = Readonly<{
|
|
73
|
+
id: string;
|
|
74
|
+
properties: Readonly<AnalyticsEventProperties>;
|
|
75
|
+
sensitiveProperties: Readonly<AnalyticsEventProperties>;
|
|
76
|
+
initialEvent?: string;
|
|
77
|
+
successEvent?: string;
|
|
78
|
+
failureEvent?: string;
|
|
79
|
+
context?: Readonly<AnalyticsContext>;
|
|
80
|
+
persist?: boolean;
|
|
81
|
+
createdAt: number;
|
|
82
|
+
lastUpdated: number;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Event fragments keyed by fragment ID.
|
|
86
|
+
*/
|
|
87
|
+
export type AnalyticsEventFragments = Record<string, AnalyticsEventFragment>;
|
|
88
|
+
/**
|
|
89
|
+
* Options accepted when creating an event fragment. An `id` is generated when
|
|
90
|
+
* one is not supplied.
|
|
91
|
+
*/
|
|
92
|
+
export type AnalyticsEventFragmentOptions = Partial<Pick<AnalyticsEventFragment, 'id' | 'initialEvent' | 'successEvent' | 'failureEvent' | 'properties' | 'sensitiveProperties' | 'context' | 'persist'>>;
|
|
93
|
+
/**
|
|
94
|
+
* The fields that can be written to an existing event fragment.
|
|
95
|
+
*/
|
|
96
|
+
export type AnalyticsEventFragmentPayload = Pick<AnalyticsEventFragmentOptions, 'properties' | 'sensitiveProperties' | 'context'>;
|
|
97
|
+
/**
|
|
98
|
+
* Options accepted when finalizing an event fragment.
|
|
99
|
+
*/
|
|
100
|
+
export type AnalyticsEventFragmentFinalizeOptions = {
|
|
101
|
+
/**
|
|
102
|
+
* Whether the journey was abandoned, which selects `failureEvent` instead of
|
|
103
|
+
* `successEvent`.
|
|
104
|
+
*/
|
|
105
|
+
abandoned?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Context merged over the fragment's own context for the emitted event.
|
|
108
|
+
*/
|
|
109
|
+
context?: AnalyticsContext;
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=EventFragment.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventFragment.types.d.mts","sourceRoot":"","sources":["../src/EventFragment.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,6CAAyC;AAE1C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,UAAU,EAAE,wBAAwB,CAAC;IAErC;;;;OAIG;IACH,mBAAmB,EAAE,wBAAwB,CAAC;IAE9C;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAE3B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,8BAA8B,GAAG,QAAQ,CAAC;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IAC/C,mBAAmB,EAAE,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAE7E;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,OAAO,CACjD,IAAI,CACF,sBAAsB,EACpB,IAAI,GACJ,cAAc,GACd,cAAc,GACd,cAAc,GACd,YAAY,GACZ,qBAAqB,GACrB,SAAS,GACT,SAAS,CACZ,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC9C,6BAA6B,EAC7B,YAAY,GAAG,qBAAqB,GAAG,SAAS,CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventFragment.types.mjs","sourceRoot":"","sources":["../src/EventFragment.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AnalyticsContext,\n AnalyticsEventProperties,\n} from './AnalyticsPlatformAdapter.types';\n\n/**\n * A bag of analytics properties that accumulates across a user journey.\n *\n * A fragment lets several parts of a client contribute properties to the same\n * logical journey (a signature request, a transaction confirmation) without\n * having to re-derive them for every event, and lets the journey be closed as\n * a success or a failure.\n *\n * All three event names are optional. A fragment that declares none of them\n * never emits anything and acts purely as a property bag that the client reads\n * back with {@link AnalyticsController.getEventFragmentById} at the moment it\n * emits its own event.\n */\nexport type AnalyticsEventFragment = {\n /**\n * The fragment identifier, unique per client.\n */\n id: string;\n\n /**\n * Properties tracked with every event this fragment emits.\n */\n properties: AnalyticsEventProperties;\n\n /**\n * Properties that must not be linked to the user's analytics ID. They are\n * delivered on a separate anonymous payload when the anonymous events\n * feature is enabled.\n */\n sensitiveProperties: AnalyticsEventProperties;\n\n /**\n * Name of an event emitted immediately when the fragment is created.\n */\n initialEvent?: string;\n\n /**\n * Name of the event emitted when the fragment is finalized normally.\n */\n successEvent?: string;\n\n /**\n * Name of the event emitted when the fragment is finalized as abandoned.\n */\n failureEvent?: string;\n\n /**\n * Platform-specific context forwarded with every event this fragment emits.\n */\n context?: AnalyticsContext;\n\n /**\n * Whether the fragment survives {@link AnalyticsController.init}. Fragments\n * that do not set this are discarded when the controller re-initializes,\n * since the journey they belonged to cannot be resumed. Even with this set,\n * a fragment whose {@link lastUpdated} is older than the controller's max\n * fragment age is discarded on init.\n */\n persist?: boolean;\n\n /**\n * `Date.now()` when the fragment was created.\n */\n createdAt: number;\n\n /**\n * `Date.now()` when the fragment was last written to. Used on\n * {@link AnalyticsController.init} to expire abandoned persisted fragments.\n */\n lastUpdated: number;\n};\n\n/**\n * Public, read-only view of an {@link AnalyticsEventFragment}.\n *\n * Returned by {@link AnalyticsController.createEventFragment} and\n * {@link AnalyticsController.getEventFragmentById}. Callers must use\n * {@link AnalyticsController.updateEventFragment} (or\n * {@link AnalyticsController.upsertEventFragment}) to modify fragment data.\n */\nexport type ReadonlyAnalyticsEventFragment = Readonly<{\n id: string;\n properties: Readonly<AnalyticsEventProperties>;\n sensitiveProperties: Readonly<AnalyticsEventProperties>;\n initialEvent?: string;\n successEvent?: string;\n failureEvent?: string;\n context?: Readonly<AnalyticsContext>;\n persist?: boolean;\n createdAt: number;\n lastUpdated: number;\n}>;\n\n/**\n * Event fragments keyed by fragment ID.\n */\nexport type AnalyticsEventFragments = Record<string, AnalyticsEventFragment>;\n\n/**\n * Options accepted when creating an event fragment. An `id` is generated when\n * one is not supplied.\n */\nexport type AnalyticsEventFragmentOptions = Partial<\n Pick<\n AnalyticsEventFragment,\n | 'id'\n | 'initialEvent'\n | 'successEvent'\n | 'failureEvent'\n | 'properties'\n | 'sensitiveProperties'\n | 'context'\n | 'persist'\n >\n>;\n\n/**\n * The fields that can be written to an existing event fragment.\n */\nexport type AnalyticsEventFragmentPayload = Pick<\n AnalyticsEventFragmentOptions,\n 'properties' | 'sensitiveProperties' | 'context'\n>;\n\n/**\n * Options accepted when finalizing an event fragment.\n */\nexport type AnalyticsEventFragmentFinalizeOptions = {\n /**\n * Whether the journey was abandoned, which selects `failureEvent` instead of\n * `successEvent`.\n */\n abandoned?: boolean;\n\n /**\n * Context merged over the fragment's own context for the emitted event.\n */\n context?: AnalyticsContext;\n};\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.analyticsControllerSelectors = exports.AnalyticsPlatformAdapterSetupError = exports.getDefaultAnalyticsControllerState = exports.AnalyticsController = void 0;
|
|
3
|
+
exports.analyticsControllerSelectors = exports.AnalyticsPlatformAdapterSetupError = exports.getDefaultAnalyticsControllerState = exports.EVENT_FRAGMENT_MAX_AGE = exports.AnalyticsController = void 0;
|
|
4
4
|
// Export controller class and state utilities
|
|
5
5
|
var AnalyticsController_js_1 = require("./AnalyticsController.cjs");
|
|
6
6
|
Object.defineProperty(exports, "AnalyticsController", { enumerable: true, get: function () { return AnalyticsController_js_1.AnalyticsController; } });
|
|
7
|
+
Object.defineProperty(exports, "EVENT_FRAGMENT_MAX_AGE", { enumerable: true, get: function () { return AnalyticsController_js_1.EVENT_FRAGMENT_MAX_AGE; } });
|
|
7
8
|
Object.defineProperty(exports, "getDefaultAnalyticsControllerState", { enumerable: true, get: function () { return AnalyticsController_js_1.getDefaultAnalyticsControllerState; } });
|
|
8
9
|
// Export errors
|
|
9
10
|
var AnalyticsPlatformAdapterSetupError_js_1 = require("./AnalyticsPlatformAdapterSetupError.cjs");
|