@metamask-previews/analytics-controller 1.0.1-preview-4678f2f94 → 1.0.1-preview-784cc181c

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.
@@ -1,9 +1,8 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
- import type { Json } from "@metamask/utils";
5
4
  import type { AnalyticsControllerMethodActions } from "./AnalyticsController-method-action-types.cjs";
6
- import type { AnalyticsPlatformAdapter, AnalyticsContext, AnalyticsEventProperties, AnalyticsUserTraits, AnalyticsTrackingEvent } from "./AnalyticsPlatformAdapter.types.cjs";
5
+ import type { AnalyticsPlatformAdapter, AnalyticsEventProperties, AnalyticsUserTraits, AnalyticsTrackingEvent } from "./AnalyticsPlatformAdapter.types.cjs";
7
6
  /**
8
7
  * The name of the {@link AnalyticsController}, used to namespace the
9
8
  * controller's actions and events and to namespace the controller's state data
@@ -24,68 +23,7 @@ export type AnalyticsControllerState = {
24
23
  * Must be provided by the platform - the controller does not generate it.
25
24
  */
26
25
  analyticsId: string;
27
- /**
28
- * Persisted queue of analytics events waiting for delivery acknowledgement.
29
- * This is only used when event queue persistence is enabled.
30
- */
31
- eventQueue?: Record<string, Json>;
32
- };
33
- /**
34
- * Event types supported by the persisted analytics event queue.
35
- */
36
- export type AnalyticsQueuedEventType = 'track' | 'identify' | 'view';
37
- /**
38
- * Base persisted event queue entry.
39
- */
40
- export type AnalyticsQueuedEventBase = {
41
- /**
42
- * Event type used to replay the payload with the platform adapter.
43
- */
44
- type: AnalyticsQueuedEventType;
45
- /**
46
- * Stable identifier for the analytics payload.
47
- */
48
- messageId: string;
49
- /**
50
- * Original payload timestamp serialized for persistence.
51
- */
52
- timestamp: string;
53
- };
54
- /**
55
- * Persisted track event queue entry.
56
- */
57
- export type AnalyticsQueuedTrackEvent = AnalyticsQueuedEventBase & {
58
- type: 'track';
59
- eventName: string;
60
- properties?: AnalyticsEventProperties;
61
- context?: AnalyticsContext;
62
26
  };
63
- /**
64
- * Persisted identify event queue entry.
65
- */
66
- export type AnalyticsQueuedIdentifyEvent = AnalyticsQueuedEventBase & {
67
- type: 'identify';
68
- userId: string;
69
- traits?: AnalyticsUserTraits;
70
- context?: AnalyticsContext;
71
- };
72
- /**
73
- * Persisted view event queue entry.
74
- */
75
- export type AnalyticsQueuedViewEvent = AnalyticsQueuedEventBase & {
76
- type: 'view';
77
- name: string;
78
- properties?: AnalyticsEventProperties;
79
- context?: AnalyticsContext;
80
- };
81
- /**
82
- * Persisted analytics event queue entry.
83
- */
84
- export type AnalyticsQueuedEvent = AnalyticsQueuedTrackEvent | AnalyticsQueuedIdentifyEvent | AnalyticsQueuedViewEvent;
85
- /**
86
- * Persisted analytics event queue keyed by message ID.
87
- */
88
- export type AnalyticsEventQueue = Record<string, AnalyticsQueuedEvent>;
89
27
  /**
90
28
  * Returns default values for AnalyticsController state.
91
29
  *
@@ -148,15 +86,6 @@ export type AnalyticsControllerOptions = {
148
86
  * @default false
149
87
  */
150
88
  isAnonymousEventsFeatureEnabled?: boolean;
151
- /**
152
- * Whether analytics event queue persistence is enabled.
153
- *
154
- * When enabled, AnalyticsController persists each platform adapter payload
155
- * until the adapter reports successful delivery.
156
- *
157
- * @default false
158
- */
159
- isEventQueuePersistenceEnabled?: boolean;
160
89
  };
161
90
  /**
162
91
  * The AnalyticsController manages analytics tracking across platforms (Mobile/Extension).
@@ -182,11 +111,10 @@ export declare class AnalyticsController extends BaseController<'AnalyticsContro
182
111
  * @param options.messenger - Messenger used to communicate with BaseController
183
112
  * @param options.platformAdapter - Platform adapter implementation for tracking
184
113
  * @param options.isAnonymousEventsFeatureEnabled - Whether the anonymous events feature is enabled
185
- * @param options.isEventQueuePersistenceEnabled - Whether analytics event queue persistence is enabled
186
114
  * @throws Error if state.analyticsId is missing or not a valid UUIDv4
187
115
  * @remarks After construction, call {@link AnalyticsController.init} to complete initialization.
188
116
  */
189
- constructor({ state, messenger, platformAdapter, isAnonymousEventsFeatureEnabled, isEventQueuePersistenceEnabled, }: AnalyticsControllerOptions);
117
+ constructor({ state, messenger, platformAdapter, isAnonymousEventsFeatureEnabled, }: AnalyticsControllerOptions);
190
118
  /**
191
119
  * Initialize the controller by calling the platform adapter's onSetupCompleted lifecycle hook.
192
120
  * This method must be called after construction to complete the setup process.
@@ -198,24 +126,21 @@ export declare class AnalyticsController extends BaseController<'AnalyticsContro
198
126
  * Events are only tracked if analytics is enabled.
199
127
  *
200
128
  * @param event - Analytics event with properties and sensitive properties
201
- * @param context - Optional platform-specific context forwarded to the platform adapter.
202
129
  */
203
- trackEvent(event: AnalyticsTrackingEvent, context?: AnalyticsContext): void;
130
+ trackEvent(event: AnalyticsTrackingEvent): void;
204
131
  /**
205
132
  * Identify a user for analytics.
206
133
  *
207
134
  * @param traits - User traits/properties
208
- * @param context - Optional platform-specific context forwarded to the platform adapter.
209
135
  */
210
- identify(traits?: AnalyticsUserTraits, context?: AnalyticsContext): void;
136
+ identify(traits?: AnalyticsUserTraits): void;
211
137
  /**
212
138
  * Track a page or screen view.
213
139
  *
214
140
  * @param name - The identifier/name of the page or screen being viewed (e.g., "home", "settings", "wallet")
215
141
  * @param properties - Optional properties associated with the view
216
- * @param context - Optional platform-specific context forwarded to the platform adapter.
217
142
  */
218
- trackView(name: string, properties?: AnalyticsEventProperties, context?: AnalyticsContext): void;
143
+ trackView(name: string, properties?: AnalyticsEventProperties): void;
219
144
  /**
220
145
  * Opt in to analytics.
221
146
  */
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsController.d.cts","sourceRoot":"","sources":["../src/AnalyticsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK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,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAkC/C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI;IAS5C;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,wBAAwB,GAAG,IAAI;IASpE;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,MAAM,IAAI,IAAI;CAKf"}
@@ -1,9 +1,8 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
- import type { Json } from "@metamask/utils";
5
4
  import type { AnalyticsControllerMethodActions } from "./AnalyticsController-method-action-types.mjs";
6
- import type { AnalyticsPlatformAdapter, AnalyticsContext, AnalyticsEventProperties, AnalyticsUserTraits, AnalyticsTrackingEvent } from "./AnalyticsPlatformAdapter.types.mjs";
5
+ import type { AnalyticsPlatformAdapter, AnalyticsEventProperties, AnalyticsUserTraits, AnalyticsTrackingEvent } from "./AnalyticsPlatformAdapter.types.mjs";
7
6
  /**
8
7
  * The name of the {@link AnalyticsController}, used to namespace the
9
8
  * controller's actions and events and to namespace the controller's state data
@@ -24,68 +23,7 @@ export type AnalyticsControllerState = {
24
23
  * Must be provided by the platform - the controller does not generate it.
25
24
  */
26
25
  analyticsId: string;
27
- /**
28
- * Persisted queue of analytics events waiting for delivery acknowledgement.
29
- * This is only used when event queue persistence is enabled.
30
- */
31
- eventQueue?: Record<string, Json>;
32
- };
33
- /**
34
- * Event types supported by the persisted analytics event queue.
35
- */
36
- export type AnalyticsQueuedEventType = 'track' | 'identify' | 'view';
37
- /**
38
- * Base persisted event queue entry.
39
- */
40
- export type AnalyticsQueuedEventBase = {
41
- /**
42
- * Event type used to replay the payload with the platform adapter.
43
- */
44
- type: AnalyticsQueuedEventType;
45
- /**
46
- * Stable identifier for the analytics payload.
47
- */
48
- messageId: string;
49
- /**
50
- * Original payload timestamp serialized for persistence.
51
- */
52
- timestamp: string;
53
- };
54
- /**
55
- * Persisted track event queue entry.
56
- */
57
- export type AnalyticsQueuedTrackEvent = AnalyticsQueuedEventBase & {
58
- type: 'track';
59
- eventName: string;
60
- properties?: AnalyticsEventProperties;
61
- context?: AnalyticsContext;
62
26
  };
63
- /**
64
- * Persisted identify event queue entry.
65
- */
66
- export type AnalyticsQueuedIdentifyEvent = AnalyticsQueuedEventBase & {
67
- type: 'identify';
68
- userId: string;
69
- traits?: AnalyticsUserTraits;
70
- context?: AnalyticsContext;
71
- };
72
- /**
73
- * Persisted view event queue entry.
74
- */
75
- export type AnalyticsQueuedViewEvent = AnalyticsQueuedEventBase & {
76
- type: 'view';
77
- name: string;
78
- properties?: AnalyticsEventProperties;
79
- context?: AnalyticsContext;
80
- };
81
- /**
82
- * Persisted analytics event queue entry.
83
- */
84
- export type AnalyticsQueuedEvent = AnalyticsQueuedTrackEvent | AnalyticsQueuedIdentifyEvent | AnalyticsQueuedViewEvent;
85
- /**
86
- * Persisted analytics event queue keyed by message ID.
87
- */
88
- export type AnalyticsEventQueue = Record<string, AnalyticsQueuedEvent>;
89
27
  /**
90
28
  * Returns default values for AnalyticsController state.
91
29
  *
@@ -148,15 +86,6 @@ export type AnalyticsControllerOptions = {
148
86
  * @default false
149
87
  */
150
88
  isAnonymousEventsFeatureEnabled?: boolean;
151
- /**
152
- * Whether analytics event queue persistence is enabled.
153
- *
154
- * When enabled, AnalyticsController persists each platform adapter payload
155
- * until the adapter reports successful delivery.
156
- *
157
- * @default false
158
- */
159
- isEventQueuePersistenceEnabled?: boolean;
160
89
  };
161
90
  /**
162
91
  * The AnalyticsController manages analytics tracking across platforms (Mobile/Extension).
@@ -182,11 +111,10 @@ export declare class AnalyticsController extends BaseController<'AnalyticsContro
182
111
  * @param options.messenger - Messenger used to communicate with BaseController
183
112
  * @param options.platformAdapter - Platform adapter implementation for tracking
184
113
  * @param options.isAnonymousEventsFeatureEnabled - Whether the anonymous events feature is enabled
185
- * @param options.isEventQueuePersistenceEnabled - Whether analytics event queue persistence is enabled
186
114
  * @throws Error if state.analyticsId is missing or not a valid UUIDv4
187
115
  * @remarks After construction, call {@link AnalyticsController.init} to complete initialization.
188
116
  */
189
- constructor({ state, messenger, platformAdapter, isAnonymousEventsFeatureEnabled, isEventQueuePersistenceEnabled, }: AnalyticsControllerOptions);
117
+ constructor({ state, messenger, platformAdapter, isAnonymousEventsFeatureEnabled, }: AnalyticsControllerOptions);
190
118
  /**
191
119
  * Initialize the controller by calling the platform adapter's onSetupCompleted lifecycle hook.
192
120
  * This method must be called after construction to complete the setup process.
@@ -198,24 +126,21 @@ export declare class AnalyticsController extends BaseController<'AnalyticsContro
198
126
  * Events are only tracked if analytics is enabled.
199
127
  *
200
128
  * @param event - Analytics event with properties and sensitive properties
201
- * @param context - Optional platform-specific context forwarded to the platform adapter.
202
129
  */
203
- trackEvent(event: AnalyticsTrackingEvent, context?: AnalyticsContext): void;
130
+ trackEvent(event: AnalyticsTrackingEvent): void;
204
131
  /**
205
132
  * Identify a user for analytics.
206
133
  *
207
134
  * @param traits - User traits/properties
208
- * @param context - Optional platform-specific context forwarded to the platform adapter.
209
135
  */
210
- identify(traits?: AnalyticsUserTraits, context?: AnalyticsContext): void;
136
+ identify(traits?: AnalyticsUserTraits): void;
211
137
  /**
212
138
  * Track a page or screen view.
213
139
  *
214
140
  * @param name - The identifier/name of the page or screen being viewed (e.g., "home", "settings", "wallet")
215
141
  * @param properties - Optional properties associated with the view
216
- * @param context - Optional platform-specific context forwarded to the platform adapter.
217
142
  */
218
- trackView(name: string, properties?: AnalyticsEventProperties, context?: AnalyticsContext): void;
143
+ trackView(name: string, properties?: AnalyticsEventProperties): void;
219
144
  /**
220
145
  * Opt in to analytics.
221
146
  */
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsController.d.mts","sourceRoot":"","sources":["../src/AnalyticsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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ACS,EACV,KAAK,EACL,SAAS,EACT,eAAe,EACf,+BAAuC,GACxC,EAAE,0BAA0B;IAkC7B;;;OAGG;IACH,IAAI,IAAI,IAAI;IAkBZ;;;;;;OAMG;IACH,UAAU,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAkC/C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,IAAI;IAS5C;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,wBAAwB,GAAG,IAAI;IASpE;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,MAAM,IAAI,IAAI;CAKf"}
@@ -9,11 +9,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _AnalyticsController_instances, _AnalyticsController_platformAdapter, _AnalyticsController_isAnonymousEventsFeatureEnabled, _AnalyticsController_isEventQueuePersistenceEnabled, _AnalyticsController_initialized, _AnalyticsController_sendOrQueueTrackEvent, _AnalyticsController_sendOrQueueIdentifyEvent, _AnalyticsController_sendOrQueueViewEvent, _AnalyticsController_enqueueEvent, _AnalyticsController_sendQueuedEvent, _AnalyticsController_replayQueuedEvents, _AnalyticsController_removeQueuedEvent, _AnalyticsController_clearQueuedEvents;
12
+ var _AnalyticsController_platformAdapter, _AnalyticsController_isAnonymousEventsFeatureEnabled, _AnalyticsController_initialized;
13
13
  import { BaseController } from "@metamask/base-controller";
14
- import $lodash from "lodash";
15
- const { cloneDeep } = $lodash;
16
- import { v4 as uuid } from "uuid";
17
14
  import { validateAnalyticsControllerState } from "./analyticsControllerStateValidator.mjs";
18
15
  import { projectLogger as log } from "./AnalyticsLogger.mjs";
19
16
  import { analyticsControllerSelectors } from "./selectors.mjs";
@@ -56,12 +53,6 @@ const analyticsControllerMetadata = {
56
53
  includeInDebugSnapshot: true,
57
54
  usedInUi: false,
58
55
  },
59
- eventQueue: {
60
- includeInStateLogs: false,
61
- persist: true,
62
- includeInDebugSnapshot: false,
63
- usedInUi: false,
64
- },
65
56
  };
66
57
  // === MESSENGER ===
67
58
  const MESSENGER_EXPOSED_METHODS = [
@@ -71,46 +62,6 @@ const MESSENGER_EXPOSED_METHODS = [
71
62
  'optIn',
72
63
  'optOut',
73
64
  ];
74
- /**
75
- * Returns whether a value is a non-array object.
76
- *
77
- * @param value - The value to check.
78
- * @returns True if the value is a record.
79
- */
80
- function isRecord(value) {
81
- return value !== null && typeof value === 'object' && !Array.isArray(value);
82
- }
83
- /**
84
- * Returns whether a value is a valid persisted analytics event.
85
- *
86
- * @param value - The value to check.
87
- * @returns True if the value is a queued analytics event.
88
- */
89
- function isAnalyticsQueuedEvent(value) {
90
- if (!isRecord(value)) {
91
- return false;
92
- }
93
- if (typeof value.messageId !== 'string' ||
94
- typeof value.timestamp !== 'string') {
95
- return false;
96
- }
97
- if (value.type === 'track') {
98
- return (typeof value.eventName === 'string' &&
99
- (value.properties === undefined || isRecord(value.properties)) &&
100
- (value.context === undefined || isRecord(value.context)));
101
- }
102
- if (value.type === 'identify') {
103
- return (typeof value.userId === 'string' &&
104
- (value.traits === undefined || isRecord(value.traits)) &&
105
- (value.context === undefined || isRecord(value.context)));
106
- }
107
- if (value.type === 'view') {
108
- return (typeof value.name === 'string' &&
109
- (value.properties === undefined || isRecord(value.properties)) &&
110
- (value.context === undefined || isRecord(value.context)));
111
- }
112
- return false;
113
- }
114
65
  /**
115
66
  * The AnalyticsController manages analytics tracking across platforms (Mobile/Extension).
116
67
  * It provides a unified interface for tracking events, identifying users, and managing
@@ -134,11 +85,10 @@ export class AnalyticsController extends BaseController {
134
85
  * @param options.messenger - Messenger used to communicate with BaseController
135
86
  * @param options.platformAdapter - Platform adapter implementation for tracking
136
87
  * @param options.isAnonymousEventsFeatureEnabled - Whether the anonymous events feature is enabled
137
- * @param options.isEventQueuePersistenceEnabled - Whether analytics event queue persistence is enabled
138
88
  * @throws Error if state.analyticsId is missing or not a valid UUIDv4
139
89
  * @remarks After construction, call {@link AnalyticsController.init} to complete initialization.
140
90
  */
141
- constructor({ state, messenger, platformAdapter, isAnonymousEventsFeatureEnabled = false, isEventQueuePersistenceEnabled = false, }) {
91
+ constructor({ state, messenger, platformAdapter, isAnonymousEventsFeatureEnabled = false, }) {
142
92
  const initialState = {
143
93
  ...getDefaultAnalyticsControllerState(),
144
94
  ...state,
@@ -150,13 +100,10 @@ export class AnalyticsController extends BaseController {
150
100
  state: initialState,
151
101
  messenger,
152
102
  });
153
- _AnalyticsController_instances.add(this);
154
103
  _AnalyticsController_platformAdapter.set(this, void 0);
155
104
  _AnalyticsController_isAnonymousEventsFeatureEnabled.set(this, void 0);
156
- _AnalyticsController_isEventQueuePersistenceEnabled.set(this, void 0);
157
105
  _AnalyticsController_initialized.set(this, void 0);
158
106
  __classPrivateFieldSet(this, _AnalyticsController_isAnonymousEventsFeatureEnabled, isAnonymousEventsFeatureEnabled, "f");
159
- __classPrivateFieldSet(this, _AnalyticsController_isEventQueuePersistenceEnabled, isEventQueuePersistenceEnabled, "f");
160
107
  __classPrivateFieldSet(this, _AnalyticsController_platformAdapter, platformAdapter, "f");
161
108
  __classPrivateFieldSet(this, _AnalyticsController_initialized, false, "f");
162
109
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
@@ -164,7 +111,6 @@ export class AnalyticsController extends BaseController {
164
111
  enabled: analyticsControllerSelectors.selectEnabled(this.state),
165
112
  optedIn: this.state.optedIn,
166
113
  analyticsId: this.state.analyticsId,
167
- eventQueuePersistenceEnabled: __classPrivateFieldGet(this, _AnalyticsController_isEventQueuePersistenceEnabled, "f"),
168
114
  });
169
115
  }
170
116
  /**
@@ -186,7 +132,6 @@ export class AnalyticsController extends BaseController {
186
132
  // Log error but don't throw - adapter setup failure shouldn't break controller
187
133
  log('Error calling platformAdapter.onSetupCompleted', error);
188
134
  }
189
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_replayQueuedEvents).call(this);
190
135
  }
191
136
  /**
192
137
  * Track an analytics event.
@@ -194,9 +139,8 @@ export class AnalyticsController extends BaseController {
194
139
  * Events are only tracked if analytics is enabled.
195
140
  *
196
141
  * @param event - Analytics event with properties and sensitive properties
197
- * @param context - Optional platform-specific context forwarded to the platform adapter.
198
142
  */
199
- trackEvent(event, context) {
143
+ trackEvent(event) {
200
144
  // Don't track if analytics is disabled
201
145
  if (!analyticsControllerSelectors.selectEnabled(this.state)) {
202
146
  return;
@@ -204,52 +148,50 @@ export class AnalyticsController extends BaseController {
204
148
  // if event does not have properties, send event without properties
205
149
  // and return to prevent any additional processing
206
150
  if (!event.hasProperties) {
207
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_sendOrQueueTrackEvent).call(this, event.name, undefined, context);
151
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(event.name);
208
152
  return;
209
153
  }
210
154
  // Track regular properties first if anonymous events feature is enabled
211
155
  if (__classPrivateFieldGet(this, _AnalyticsController_isAnonymousEventsFeatureEnabled, "f")) {
212
156
  // Note: Even if regular properties object is empty, we still send it to ensure
213
157
  // an event with user ID is tracked.
214
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_sendOrQueueTrackEvent).call(this, event.name, {
158
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(event.name, {
215
159
  ...event.properties,
216
- }, context);
160
+ });
217
161
  }
218
162
  const hasSensitiveProperties = Object.keys(event.sensitiveProperties).length > 0;
219
163
  if (!__classPrivateFieldGet(this, _AnalyticsController_isAnonymousEventsFeatureEnabled, "f") || hasSensitiveProperties) {
220
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_sendOrQueueTrackEvent).call(this, event.name, {
164
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(event.name, {
221
165
  ...event.properties,
222
166
  ...event.sensitiveProperties,
223
167
  ...(hasSensitiveProperties && { anonymous: true }),
224
- }, context);
168
+ });
225
169
  }
226
170
  }
227
171
  /**
228
172
  * Identify a user for analytics.
229
173
  *
230
174
  * @param traits - User traits/properties
231
- * @param context - Optional platform-specific context forwarded to the platform adapter.
232
175
  */
233
- identify(traits, context) {
176
+ identify(traits) {
234
177
  if (!analyticsControllerSelectors.selectEnabled(this.state)) {
235
178
  return;
236
179
  }
237
180
  // Delegate to platform adapter using the current analytics ID
238
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_sendOrQueueIdentifyEvent).call(this, this.state.analyticsId, traits, context);
181
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").identify(this.state.analyticsId, traits);
239
182
  }
240
183
  /**
241
184
  * Track a page or screen view.
242
185
  *
243
186
  * @param name - The identifier/name of the page or screen being viewed (e.g., "home", "settings", "wallet")
244
187
  * @param properties - Optional properties associated with the view
245
- * @param context - Optional platform-specific context forwarded to the platform adapter.
246
188
  */
247
- trackView(name, properties, context) {
189
+ trackView(name, properties) {
248
190
  if (!analyticsControllerSelectors.selectEnabled(this.state)) {
249
191
  return;
250
192
  }
251
193
  // Delegate to platform adapter
252
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_sendOrQueueViewEvent).call(this, name, properties, context);
194
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").view(name, properties);
253
195
  }
254
196
  /**
255
197
  * Opt in to analytics.
@@ -266,134 +208,7 @@ export class AnalyticsController extends BaseController {
266
208
  this.update((state) => {
267
209
  state.optedIn = false;
268
210
  });
269
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_clearQueuedEvents).call(this);
270
211
  }
271
212
  }
272
- _AnalyticsController_platformAdapter = new WeakMap(), _AnalyticsController_isAnonymousEventsFeatureEnabled = new WeakMap(), _AnalyticsController_isEventQueuePersistenceEnabled = new WeakMap(), _AnalyticsController_initialized = new WeakMap(), _AnalyticsController_instances = new WeakSet(), _AnalyticsController_sendOrQueueTrackEvent = function _AnalyticsController_sendOrQueueTrackEvent(eventName, properties, context) {
273
- if (!__classPrivateFieldGet(this, _AnalyticsController_isEventQueuePersistenceEnabled, "f")) {
274
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(eventName, properties, context);
275
- return;
276
- }
277
- const queuedEvent = {
278
- type: 'track',
279
- eventName,
280
- messageId: uuid(),
281
- timestamp: new Date().toISOString(),
282
- ...(properties === undefined ? {} : { properties }),
283
- ...(context === undefined ? {} : { context }),
284
- };
285
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_enqueueEvent).call(this, queuedEvent);
286
- }, _AnalyticsController_sendOrQueueIdentifyEvent = function _AnalyticsController_sendOrQueueIdentifyEvent(userId, traits, context) {
287
- if (!__classPrivateFieldGet(this, _AnalyticsController_isEventQueuePersistenceEnabled, "f")) {
288
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").identify(userId, traits, context);
289
- return;
290
- }
291
- const queuedEvent = {
292
- type: 'identify',
293
- userId,
294
- messageId: uuid(),
295
- timestamp: new Date().toISOString(),
296
- ...(traits === undefined ? {} : { traits }),
297
- ...(context === undefined ? {} : { context }),
298
- };
299
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_enqueueEvent).call(this, queuedEvent);
300
- }, _AnalyticsController_sendOrQueueViewEvent = function _AnalyticsController_sendOrQueueViewEvent(name, properties, context) {
301
- if (!__classPrivateFieldGet(this, _AnalyticsController_isEventQueuePersistenceEnabled, "f")) {
302
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").view(name, properties, context);
303
- return;
304
- }
305
- const queuedEvent = {
306
- type: 'view',
307
- name,
308
- messageId: uuid(),
309
- timestamp: new Date().toISOString(),
310
- ...(properties === undefined ? {} : { properties }),
311
- ...(context === undefined ? {} : { context }),
312
- };
313
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_enqueueEvent).call(this, queuedEvent);
314
- }, _AnalyticsController_enqueueEvent = function _AnalyticsController_enqueueEvent(queuedEvent) {
315
- const eventQueue = {
316
- ...(this.state.eventQueue ?? {}),
317
- [queuedEvent.messageId]: queuedEvent,
318
- };
319
- this.update((state) => {
320
- state.eventQueue = eventQueue;
321
- });
322
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_sendQueuedEvent).call(this, queuedEvent);
323
- }, _AnalyticsController_sendQueuedEvent = function _AnalyticsController_sendQueuedEvent(queuedEvent) {
324
- const timestamp = new Date(queuedEvent.timestamp);
325
- if (Number.isNaN(timestamp.getTime())) {
326
- log('Dropping queued analytics event with invalid timestamp', {
327
- messageId: queuedEvent.messageId,
328
- });
329
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_removeQueuedEvent).call(this, queuedEvent.messageId);
330
- return;
331
- }
332
- const options = {
333
- messageId: queuedEvent.messageId,
334
- timestamp,
335
- callback: (error) => {
336
- if (error) {
337
- log('Queued analytics event delivery failed', {
338
- messageId: queuedEvent.messageId,
339
- error,
340
- });
341
- return;
342
- }
343
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_removeQueuedEvent).call(this, queuedEvent.messageId);
344
- },
345
- };
346
- try {
347
- if (queuedEvent.type === 'track') {
348
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(queuedEvent.eventName, cloneDeep(queuedEvent.properties), cloneDeep(queuedEvent.context), options);
349
- }
350
- else if (queuedEvent.type === 'identify') {
351
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").identify(queuedEvent.userId, cloneDeep(queuedEvent.traits), cloneDeep(queuedEvent.context), options);
352
- }
353
- else {
354
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").view(queuedEvent.name, cloneDeep(queuedEvent.properties), cloneDeep(queuedEvent.context), options);
355
- }
356
- }
357
- catch (error) {
358
- log('Error sending queued analytics event', {
359
- messageId: queuedEvent.messageId,
360
- error,
361
- });
362
- }
363
- }, _AnalyticsController_replayQueuedEvents = function _AnalyticsController_replayQueuedEvents() {
364
- if (!__classPrivateFieldGet(this, _AnalyticsController_isEventQueuePersistenceEnabled, "f") || !this.state.eventQueue) {
365
- return;
366
- }
367
- if (!analyticsControllerSelectors.selectEnabled(this.state)) {
368
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_clearQueuedEvents).call(this);
369
- return;
370
- }
371
- for (const [messageId, queuedEvent] of Object.entries(this.state.eventQueue)) {
372
- if (!isAnalyticsQueuedEvent(queuedEvent) ||
373
- queuedEvent.messageId !== messageId) {
374
- log('Dropping invalid queued analytics event', { messageId });
375
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_removeQueuedEvent).call(this, messageId);
376
- continue;
377
- }
378
- __classPrivateFieldGet(this, _AnalyticsController_instances, "m", _AnalyticsController_sendQueuedEvent).call(this, queuedEvent);
379
- }
380
- }, _AnalyticsController_removeQueuedEvent = function _AnalyticsController_removeQueuedEvent(messageId) {
381
- const currentEventQueue = this.state.eventQueue;
382
- if (!currentEventQueue ||
383
- !Object.prototype.hasOwnProperty.call(currentEventQueue, messageId)) {
384
- return;
385
- }
386
- const { [messageId]: _deletedEvent, ...eventQueue } = currentEventQueue;
387
- this.update((state) => {
388
- state.eventQueue = eventQueue;
389
- });
390
- }, _AnalyticsController_clearQueuedEvents = function _AnalyticsController_clearQueuedEvents() {
391
- if (!this.state.eventQueue ||
392
- Object.keys(this.state.eventQueue).length === 0) {
393
- return;
394
- }
395
- this.update((state) => {
396
- state.eventQueue = {};
397
- });
398
- };
213
+ _AnalyticsController_platformAdapter = new WeakMap(), _AnalyticsController_isAnonymousEventsFeatureEnabled = new WeakMap(), _AnalyticsController_initialized = new WeakMap();
399
214
  //# sourceMappingURL=AnalyticsController.mjs.map