@metamask-previews/analytics-controller 0.0.0-preview-21a5ddac → 0.0.0-preview-4ed214fa

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +11 -72
  3. package/dist/AnalyticsController-method-action-types.cjs.map +1 -1
  4. package/dist/AnalyticsController-method-action-types.d.cts +26 -28
  5. package/dist/AnalyticsController-method-action-types.d.cts.map +1 -1
  6. package/dist/AnalyticsController-method-action-types.d.mts +26 -28
  7. package/dist/AnalyticsController-method-action-types.d.mts.map +1 -1
  8. package/dist/AnalyticsController-method-action-types.mjs.map +1 -1
  9. package/dist/AnalyticsController.cjs +52 -81
  10. package/dist/AnalyticsController.cjs.map +1 -1
  11. package/dist/AnalyticsController.d.cts +24 -27
  12. package/dist/AnalyticsController.d.cts.map +1 -1
  13. package/dist/AnalyticsController.d.mts +24 -27
  14. package/dist/AnalyticsController.d.mts.map +1 -1
  15. package/dist/AnalyticsController.mjs +52 -81
  16. package/dist/AnalyticsController.mjs.map +1 -1
  17. package/dist/AnalyticsPlatformAdapter.types.cjs.map +1 -1
  18. package/dist/AnalyticsPlatformAdapter.types.d.cts +15 -58
  19. package/dist/AnalyticsPlatformAdapter.types.d.cts.map +1 -1
  20. package/dist/AnalyticsPlatformAdapter.types.d.mts +15 -58
  21. package/dist/AnalyticsPlatformAdapter.types.d.mts.map +1 -1
  22. package/dist/AnalyticsPlatformAdapter.types.mjs.map +1 -1
  23. package/dist/index.cjs +1 -7
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +2 -4
  26. package/dist/index.d.cts.map +1 -1
  27. package/dist/index.d.mts +2 -4
  28. package/dist/index.d.mts.map +1 -1
  29. package/dist/index.mjs +0 -4
  30. package/dist/index.mjs.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/AnalyticsPlatformAdapterSetupError.cjs +0 -17
  33. package/dist/AnalyticsPlatformAdapterSetupError.cjs.map +0 -1
  34. package/dist/AnalyticsPlatformAdapterSetupError.d.cts +0 -8
  35. package/dist/AnalyticsPlatformAdapterSetupError.d.cts.map +0 -1
  36. package/dist/AnalyticsPlatformAdapterSetupError.d.mts +0 -8
  37. package/dist/AnalyticsPlatformAdapterSetupError.d.mts.map +0 -1
  38. package/dist/AnalyticsPlatformAdapterSetupError.mjs +0 -13
  39. package/dist/AnalyticsPlatformAdapterSetupError.mjs.map +0 -1
  40. package/dist/analyticsStateComputer.cjs +0 -46
  41. package/dist/analyticsStateComputer.cjs.map +0 -1
  42. package/dist/analyticsStateComputer.d.cts +0 -35
  43. package/dist/analyticsStateComputer.d.cts.map +0 -1
  44. package/dist/analyticsStateComputer.d.mts +0 -35
  45. package/dist/analyticsStateComputer.d.mts.map +0 -1
  46. package/dist/analyticsStateComputer.mjs +0 -42
  47. package/dist/analyticsStateComputer.mjs.map +0 -1
  48. package/dist/analyticsStateValidator.cjs +0 -19
  49. package/dist/analyticsStateValidator.cjs.map +0 -1
  50. package/dist/analyticsStateValidator.d.cts +0 -9
  51. package/dist/analyticsStateValidator.d.cts.map +0 -1
  52. package/dist/analyticsStateValidator.d.mts +0 -9
  53. package/dist/analyticsStateValidator.d.mts.map +0 -1
  54. package/dist/analyticsStateValidator.mjs +0 -15
  55. package/dist/analyticsStateValidator.mjs.map +0 -1
  56. package/dist/selectors.cjs +0 -44
  57. package/dist/selectors.cjs.map +0 -1
  58. package/dist/selectors.d.cts +0 -12
  59. package/dist/selectors.d.cts.map +0 -1
  60. package/dist/selectors.d.mts +0 -12
  61. package/dist/selectors.d.mts.map +0 -1
  62. package/dist/selectors.mjs +0 -41
  63. package/dist/selectors.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -9,6 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
- - Initial release of @metamask/analytics-controller.
12
+ - Initial release of @metamask/analytics-controller. ([#7017](https://github.com/MetaMask/core/pull/7017), [#7202](https://github.com/MetaMask/core/pull/7202))
13
13
 
14
14
  [Unreleased]: https://github.com/MetaMask/core/
package/README.md CHANGED
@@ -30,24 +30,15 @@ The controller delegates platform-specific analytics implementation to a `Analyt
30
30
  import type { AnalyticsPlatformAdapter } from '@metamask/analytics-controller';
31
31
 
32
32
  const platformAdapter: AnalyticsPlatformAdapter = {
33
- track: (eventName: string, properties: Record<string, unknown>) => {
33
+ trackEvent: (eventName: string, properties: Record<string, unknown>) => {
34
34
  // Platform-specific implementation (e.g., Segment, Mixpanel, etc.)
35
35
  segment.track(eventName, properties);
36
36
  },
37
37
  identify: (userId: string, traits?: Record<string, unknown>) => {
38
38
  segment.identify(userId, traits);
39
39
  },
40
- view: (name: string, properties?: Record<string, unknown>) => {
41
- segment.page(name, properties);
42
- },
43
- onSetupCompleted: (analyticsId: string) => {
44
- // Lifecycle hook called after controller initialization
45
- // The analyticsId is guaranteed to be set when this method is called
46
- // Use this for platform-specific setup that requires the analytics ID
47
- // For example, adding plugins that need the analytics ID:
48
- segment.add({
49
- plugin: new PrivacyPlugin(analyticsId),
50
- });
40
+ trackPage: (pageName: string, properties?: Record<string, unknown>) => {
41
+ segment.page(pageName, properties);
51
42
  },
52
43
  };
53
44
  ```
@@ -121,7 +112,7 @@ console.log(controller.state.analyticsId); // '550e8400-e29b-41d4-a716-446655440
121
112
  ### 5. Track Page Views
122
113
 
123
114
  ```typescript
124
- controller.trackView('home', {
115
+ controller.trackPage('home', {
125
116
  referrer: 'google',
126
117
  campaign: 'summer-2024',
127
118
  });
@@ -134,13 +125,9 @@ controller.trackView('home', {
134
125
  controller.enable();
135
126
  controller.disable();
136
127
 
137
- // Opt in/out for regular account
138
- controller.optInForRegularAccount();
139
- controller.optOutForRegularAccount();
140
-
141
- // Opt in/out for social account
142
- controller.optInForSocialAccount();
143
- controller.optOutForSocialAccount();
128
+ // Opt in/out
129
+ controller.optIn();
130
+ controller.optOut();
144
131
  ```
145
132
 
146
133
  ### 7. Use Messenger Actions
@@ -161,10 +148,10 @@ messenger.call(
161
148
  },
162
149
  );
163
150
 
164
- messenger.call('AnalyticsController:optInForRegularAccount');
165
- messenger.call('AnalyticsController:optOutForRegularAccount');
166
- messenger.call('AnalyticsController:optInForSocialAccount');
167
- messenger.call('AnalyticsController:optOutForSocialAccount');
151
+ messenger.call('AnalyticsController:enable');
152
+ messenger.call('AnalyticsController:disable');
153
+ messenger.call('AnalyticsController:optIn');
154
+ messenger.call('AnalyticsController:optOut');
168
155
  ```
169
156
 
170
157
  ### 8. Subscribe to State Changes
@@ -206,54 +193,6 @@ const defaultState = getDefaultAnalyticsControllerState();
206
193
 
207
194
  **Analytics ID:** The `analyticsId` is a UUIDv4 string. If not provided in the `state` parameter, the controller automatically generates one on initialization. This ID is persisted in state and remains consistent across restarts. If you provide an `analyticsId` in the `state` parameter, it will be used instead (useful for migrations).
208
195
 
209
- ## Lifecycle Hooks
210
-
211
- ### `onSetupCompleted`
212
-
213
- The `onSetupCompleted` lifecycle hook is called once after the `AnalyticsController` is fully initialized. This hook allows platform-specific adapters to perform setup that requires access to the controller's state (e.g., `analyticsId`).
214
-
215
- **When it's called:**
216
-
217
- - After the controller is fully initialized
218
- - Only when `analyticsId` is set in controller state (the presence of `analyticsId` is the definition of "completed" setup)
219
- - The `analyticsId` parameter is guaranteed to be set and be a valid UUIDv4 when this method is called
220
-
221
- **What it's used for:**
222
-
223
- Platform-specific setup that requires access to adapter implementation like adding plugins or middleware that need the `analyticsId`
224
- Any initialization that depends on the controller being ready
225
-
226
- **Example usage:**
227
-
228
- ```typescript
229
- const platformAdapter: AnalyticsPlatformAdapter = {
230
- // ... other methods ...
231
- onSetupCompleted: (analyticsId: string) => {
232
- // Add platform-specific plugins that require analyticsId
233
- client.add({
234
- plugin: new PrivacyPlugin(analyticsId),
235
- });
236
- },
237
- };
238
- ```
239
-
240
- **Error handling:**
241
-
242
- - Errors thrown in `onSetupCompleted` are caught and logged
243
-
244
- **Best practices:**
245
-
246
- - Use `onSetupCompleted` for setup that requires controller state
247
- - Keep setup logic minimal and focused
248
- - Handle errors gracefully within the hook
249
- - If you don't need setup, provide a no-op implementation:
250
-
251
- ```typescript
252
- onSetupCompleted: (_analyticsId: string) => {
253
- // No-op: this adapter doesn't need setup
254
- },
255
- ```
256
-
257
196
  ## Debugging
258
197
 
259
198
  To display analytics-controller logs in the mobile app, you can add the following to your `.js.env` file:
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AnalyticsController } from './AnalyticsController';\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 */\nexport type AnalyticsControllerTrackEventAction = {\n type: `AnalyticsController:trackEvent`;\n handler: AnalyticsController['trackEvent'];\n};\n\n/**\n * Identify a user for analytics.\n *\n * @param traits - User traits/properties\n */\nexport type AnalyticsControllerIdentifyAction = {\n type: `AnalyticsController:identify`;\n handler: AnalyticsController['identify'];\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 */\nexport type AnalyticsControllerTrackViewAction = {\n type: `AnalyticsController:trackView`;\n handler: AnalyticsController['trackView'];\n};\n\n/**\n * Opt in to analytics for regular account.\n * This updates the user's opt-in status for regular account.\n */\nexport type AnalyticsControllerOptInForRegularAccountAction = {\n type: `AnalyticsController:optInForRegularAccount`;\n handler: AnalyticsController['optInForRegularAccount'];\n};\n\n/**\n * Opt out of analytics for regular account.\n * This updates the user's opt-in status for regular account.\n */\nexport type AnalyticsControllerOptOutForRegularAccountAction = {\n type: `AnalyticsController:optOutForRegularAccount`;\n handler: AnalyticsController['optOutForRegularAccount'];\n};\n\n/**\n * Opt in to analytics for social account.\n * This updates the user's opt-in status for social account.\n */\nexport type AnalyticsControllerOptInForSocialAccountAction = {\n type: `AnalyticsController:optInForSocialAccount`;\n handler: AnalyticsController['optInForSocialAccount'];\n};\n\n/**\n * Opt out of analytics for social account.\n * This updates the user's opt-in status for social account.\n */\nexport type AnalyticsControllerOptOutForSocialAccountAction = {\n type: `AnalyticsController:optOutForSocialAccount`;\n handler: AnalyticsController['optOutForSocialAccount'];\n};\n\n/**\n * Union of all AnalyticsController action types.\n */\nexport type AnalyticsControllerMethodActions =\n | AnalyticsControllerTrackEventAction\n | AnalyticsControllerIdentifyAction\n | AnalyticsControllerTrackViewAction\n | AnalyticsControllerOptInForRegularAccountAction\n | AnalyticsControllerOptOutForRegularAccountAction\n | AnalyticsControllerOptInForSocialAccountAction\n | AnalyticsControllerOptOutForSocialAccountAction;\n"]}
1
+ {"version":3,"file":"AnalyticsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AnalyticsController } from './AnalyticsController';\n\n/**\n * Track an analytics event.\n *\n * Events are only tracked if analytics is enabled.\n *\n * @param eventName - The name of the event\n * @param properties - Event properties\n */\nexport type AnalyticsControllerTrackEventAction = {\n type: `AnalyticsController:trackEvent`;\n handler: AnalyticsController['trackEvent'];\n};\n\n/**\n * Identify a user for analytics.\n *\n * @param userId - The user identifier (e.g., metametrics ID)\n * @param traits - User traits/properties\n */\nexport type AnalyticsControllerIdentifyAction = {\n type: `AnalyticsController:identify`;\n handler: AnalyticsController['identify'];\n};\n\n/**\n * Track a page view.\n *\n * @param pageName - The name of the page\n * @param properties - Page properties\n */\nexport type AnalyticsControllerTrackPageAction = {\n type: `AnalyticsController:trackPage`;\n handler: AnalyticsController['trackPage'];\n};\n\n/**\n * Enable analytics tracking.\n */\nexport type AnalyticsControllerEnableAction = {\n type: `AnalyticsController:enable`;\n handler: AnalyticsController['enable'];\n};\n\n/**\n * Disable analytics tracking.\n */\nexport type AnalyticsControllerDisableAction = {\n type: `AnalyticsController:disable`;\n handler: AnalyticsController['disable'];\n};\n\n/**\n * Opt in to analytics.\n */\nexport type AnalyticsControllerOptInAction = {\n type: `AnalyticsController:optIn`;\n handler: AnalyticsController['optIn'];\n};\n\n/**\n * Opt out of analytics.\n */\nexport type AnalyticsControllerOptOutAction = {\n type: `AnalyticsController:optOut`;\n handler: AnalyticsController['optOut'];\n};\n\n/**\n * Union of all AnalyticsController action types.\n */\nexport type AnalyticsControllerMethodActions =\n | AnalyticsControllerTrackEventAction\n | AnalyticsControllerIdentifyAction\n | AnalyticsControllerTrackPageAction\n | AnalyticsControllerEnableAction\n | AnalyticsControllerDisableAction\n | AnalyticsControllerOptInAction\n | AnalyticsControllerOptOutAction;\n"]}
@@ -8,7 +8,8 @@ import type { AnalyticsController } from "./AnalyticsController.cjs";
8
8
  *
9
9
  * Events are only tracked if analytics is enabled.
10
10
  *
11
- * @param event - Analytics event with properties and sensitive properties
11
+ * @param eventName - The name of the event
12
+ * @param properties - Event properties
12
13
  */
13
14
  export type AnalyticsControllerTrackEventAction = {
14
15
  type: `AnalyticsController:trackEvent`;
@@ -17,6 +18,7 @@ export type AnalyticsControllerTrackEventAction = {
17
18
  /**
18
19
  * Identify a user for analytics.
19
20
  *
21
+ * @param userId - The user identifier (e.g., metametrics ID)
20
22
  * @param traits - User traits/properties
21
23
  */
22
24
  export type AnalyticsControllerIdentifyAction = {
@@ -24,49 +26,45 @@ export type AnalyticsControllerIdentifyAction = {
24
26
  handler: AnalyticsController['identify'];
25
27
  };
26
28
  /**
27
- * Track a page or screen view.
29
+ * Track a page view.
28
30
  *
29
- * @param name - The identifier/name of the page or screen being viewed (e.g., "home", "settings", "wallet")
30
- * @param properties - Optional properties associated with the view
31
+ * @param pageName - The name of the page
32
+ * @param properties - Page properties
31
33
  */
32
- export type AnalyticsControllerTrackViewAction = {
33
- type: `AnalyticsController:trackView`;
34
- handler: AnalyticsController['trackView'];
34
+ export type AnalyticsControllerTrackPageAction = {
35
+ type: `AnalyticsController:trackPage`;
36
+ handler: AnalyticsController['trackPage'];
35
37
  };
36
38
  /**
37
- * Opt in to analytics for regular account.
38
- * This updates the user's opt-in status for regular account.
39
+ * Enable analytics tracking.
39
40
  */
40
- export type AnalyticsControllerOptInForRegularAccountAction = {
41
- type: `AnalyticsController:optInForRegularAccount`;
42
- handler: AnalyticsController['optInForRegularAccount'];
41
+ export type AnalyticsControllerEnableAction = {
42
+ type: `AnalyticsController:enable`;
43
+ handler: AnalyticsController['enable'];
43
44
  };
44
45
  /**
45
- * Opt out of analytics for regular account.
46
- * This updates the user's opt-in status for regular account.
46
+ * Disable analytics tracking.
47
47
  */
48
- export type AnalyticsControllerOptOutForRegularAccountAction = {
49
- type: `AnalyticsController:optOutForRegularAccount`;
50
- handler: AnalyticsController['optOutForRegularAccount'];
48
+ export type AnalyticsControllerDisableAction = {
49
+ type: `AnalyticsController:disable`;
50
+ handler: AnalyticsController['disable'];
51
51
  };
52
52
  /**
53
- * Opt in to analytics for social account.
54
- * This updates the user's opt-in status for social account.
53
+ * Opt in to analytics.
55
54
  */
56
- export type AnalyticsControllerOptInForSocialAccountAction = {
57
- type: `AnalyticsController:optInForSocialAccount`;
58
- handler: AnalyticsController['optInForSocialAccount'];
55
+ export type AnalyticsControllerOptInAction = {
56
+ type: `AnalyticsController:optIn`;
57
+ handler: AnalyticsController['optIn'];
59
58
  };
60
59
  /**
61
- * Opt out of analytics for social account.
62
- * This updates the user's opt-in status for social account.
60
+ * Opt out of analytics.
63
61
  */
64
- export type AnalyticsControllerOptOutForSocialAccountAction = {
65
- type: `AnalyticsController:optOutForSocialAccount`;
66
- handler: AnalyticsController['optOutForSocialAccount'];
62
+ export type AnalyticsControllerOptOutAction = {
63
+ type: `AnalyticsController:optOut`;
64
+ handler: AnalyticsController['optOut'];
67
65
  };
68
66
  /**
69
67
  * Union of all AnalyticsController action types.
70
68
  */
71
- export type AnalyticsControllerMethodActions = AnalyticsControllerTrackEventAction | AnalyticsControllerIdentifyAction | AnalyticsControllerTrackViewAction | AnalyticsControllerOptInForRegularAccountAction | AnalyticsControllerOptOutForRegularAccountAction | AnalyticsControllerOptInForSocialAccountAction | AnalyticsControllerOptOutForSocialAccountAction;
69
+ export type AnalyticsControllerMethodActions = AnalyticsControllerTrackEventAction | AnalyticsControllerIdentifyAction | AnalyticsControllerTrackPageAction | AnalyticsControllerEnableAction | AnalyticsControllerDisableAction | AnalyticsControllerOptInAction | AnalyticsControllerOptOutAction;
72
70
  //# sourceMappingURL=AnalyticsController-method-action-types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAA8B;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;CAC3C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;CACxD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;CACzD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;CACvD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;CACxD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GACxC,mCAAmC,GACnC,iCAAiC,GACjC,kCAAkC,GAClC,+CAA+C,GAC/C,gDAAgD,GAChD,8CAA8C,GAC9C,+CAA+C,CAAC"}
1
+ {"version":3,"file":"AnalyticsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAA8B;AAEjE;;;;;;;GAOG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GACxC,mCAAmC,GACnC,iCAAiC,GACjC,kCAAkC,GAClC,+BAA+B,GAC/B,gCAAgC,GAChC,8BAA8B,GAC9B,+BAA+B,CAAC"}
@@ -8,7 +8,8 @@ import type { AnalyticsController } from "./AnalyticsController.mjs";
8
8
  *
9
9
  * Events are only tracked if analytics is enabled.
10
10
  *
11
- * @param event - Analytics event with properties and sensitive properties
11
+ * @param eventName - The name of the event
12
+ * @param properties - Event properties
12
13
  */
13
14
  export type AnalyticsControllerTrackEventAction = {
14
15
  type: `AnalyticsController:trackEvent`;
@@ -17,6 +18,7 @@ export type AnalyticsControllerTrackEventAction = {
17
18
  /**
18
19
  * Identify a user for analytics.
19
20
  *
21
+ * @param userId - The user identifier (e.g., metametrics ID)
20
22
  * @param traits - User traits/properties
21
23
  */
22
24
  export type AnalyticsControllerIdentifyAction = {
@@ -24,49 +26,45 @@ export type AnalyticsControllerIdentifyAction = {
24
26
  handler: AnalyticsController['identify'];
25
27
  };
26
28
  /**
27
- * Track a page or screen view.
29
+ * Track a page view.
28
30
  *
29
- * @param name - The identifier/name of the page or screen being viewed (e.g., "home", "settings", "wallet")
30
- * @param properties - Optional properties associated with the view
31
+ * @param pageName - The name of the page
32
+ * @param properties - Page properties
31
33
  */
32
- export type AnalyticsControllerTrackViewAction = {
33
- type: `AnalyticsController:trackView`;
34
- handler: AnalyticsController['trackView'];
34
+ export type AnalyticsControllerTrackPageAction = {
35
+ type: `AnalyticsController:trackPage`;
36
+ handler: AnalyticsController['trackPage'];
35
37
  };
36
38
  /**
37
- * Opt in to analytics for regular account.
38
- * This updates the user's opt-in status for regular account.
39
+ * Enable analytics tracking.
39
40
  */
40
- export type AnalyticsControllerOptInForRegularAccountAction = {
41
- type: `AnalyticsController:optInForRegularAccount`;
42
- handler: AnalyticsController['optInForRegularAccount'];
41
+ export type AnalyticsControllerEnableAction = {
42
+ type: `AnalyticsController:enable`;
43
+ handler: AnalyticsController['enable'];
43
44
  };
44
45
  /**
45
- * Opt out of analytics for regular account.
46
- * This updates the user's opt-in status for regular account.
46
+ * Disable analytics tracking.
47
47
  */
48
- export type AnalyticsControllerOptOutForRegularAccountAction = {
49
- type: `AnalyticsController:optOutForRegularAccount`;
50
- handler: AnalyticsController['optOutForRegularAccount'];
48
+ export type AnalyticsControllerDisableAction = {
49
+ type: `AnalyticsController:disable`;
50
+ handler: AnalyticsController['disable'];
51
51
  };
52
52
  /**
53
- * Opt in to analytics for social account.
54
- * This updates the user's opt-in status for social account.
53
+ * Opt in to analytics.
55
54
  */
56
- export type AnalyticsControllerOptInForSocialAccountAction = {
57
- type: `AnalyticsController:optInForSocialAccount`;
58
- handler: AnalyticsController['optInForSocialAccount'];
55
+ export type AnalyticsControllerOptInAction = {
56
+ type: `AnalyticsController:optIn`;
57
+ handler: AnalyticsController['optIn'];
59
58
  };
60
59
  /**
61
- * Opt out of analytics for social account.
62
- * This updates the user's opt-in status for social account.
60
+ * Opt out of analytics.
63
61
  */
64
- export type AnalyticsControllerOptOutForSocialAccountAction = {
65
- type: `AnalyticsController:optOutForSocialAccount`;
66
- handler: AnalyticsController['optOutForSocialAccount'];
62
+ export type AnalyticsControllerOptOutAction = {
63
+ type: `AnalyticsController:optOut`;
64
+ handler: AnalyticsController['optOut'];
67
65
  };
68
66
  /**
69
67
  * Union of all AnalyticsController action types.
70
68
  */
71
- export type AnalyticsControllerMethodActions = AnalyticsControllerTrackEventAction | AnalyticsControllerIdentifyAction | AnalyticsControllerTrackViewAction | AnalyticsControllerOptInForRegularAccountAction | AnalyticsControllerOptOutForRegularAccountAction | AnalyticsControllerOptInForSocialAccountAction | AnalyticsControllerOptOutForSocialAccountAction;
69
+ export type AnalyticsControllerMethodActions = AnalyticsControllerTrackEventAction | AnalyticsControllerIdentifyAction | AnalyticsControllerTrackPageAction | AnalyticsControllerEnableAction | AnalyticsControllerDisableAction | AnalyticsControllerOptInAction | AnalyticsControllerOptOutAction;
72
70
  //# sourceMappingURL=AnalyticsController-method-action-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAA8B;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;CAC3C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;CACxD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;CACzD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;CACvD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;CACxD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GACxC,mCAAmC,GACnC,iCAAiC,GACjC,kCAAkC,GAClC,+CAA+C,GAC/C,gDAAgD,GAChD,8CAA8C,GAC9C,+CAA+C,CAAC"}
1
+ {"version":3,"file":"AnalyticsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAA8B;AAEjE;;;;;;;GAOG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GACxC,mCAAmC,GACnC,iCAAiC,GACjC,kCAAkC,GAClC,+BAA+B,GAC/B,gCAAgC,GAChC,8BAA8B,GAC9B,+BAA+B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AnalyticsController } from './AnalyticsController';\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 */\nexport type AnalyticsControllerTrackEventAction = {\n type: `AnalyticsController:trackEvent`;\n handler: AnalyticsController['trackEvent'];\n};\n\n/**\n * Identify a user for analytics.\n *\n * @param traits - User traits/properties\n */\nexport type AnalyticsControllerIdentifyAction = {\n type: `AnalyticsController:identify`;\n handler: AnalyticsController['identify'];\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 */\nexport type AnalyticsControllerTrackViewAction = {\n type: `AnalyticsController:trackView`;\n handler: AnalyticsController['trackView'];\n};\n\n/**\n * Opt in to analytics for regular account.\n * This updates the user's opt-in status for regular account.\n */\nexport type AnalyticsControllerOptInForRegularAccountAction = {\n type: `AnalyticsController:optInForRegularAccount`;\n handler: AnalyticsController['optInForRegularAccount'];\n};\n\n/**\n * Opt out of analytics for regular account.\n * This updates the user's opt-in status for regular account.\n */\nexport type AnalyticsControllerOptOutForRegularAccountAction = {\n type: `AnalyticsController:optOutForRegularAccount`;\n handler: AnalyticsController['optOutForRegularAccount'];\n};\n\n/**\n * Opt in to analytics for social account.\n * This updates the user's opt-in status for social account.\n */\nexport type AnalyticsControllerOptInForSocialAccountAction = {\n type: `AnalyticsController:optInForSocialAccount`;\n handler: AnalyticsController['optInForSocialAccount'];\n};\n\n/**\n * Opt out of analytics for social account.\n * This updates the user's opt-in status for social account.\n */\nexport type AnalyticsControllerOptOutForSocialAccountAction = {\n type: `AnalyticsController:optOutForSocialAccount`;\n handler: AnalyticsController['optOutForSocialAccount'];\n};\n\n/**\n * Union of all AnalyticsController action types.\n */\nexport type AnalyticsControllerMethodActions =\n | AnalyticsControllerTrackEventAction\n | AnalyticsControllerIdentifyAction\n | AnalyticsControllerTrackViewAction\n | AnalyticsControllerOptInForRegularAccountAction\n | AnalyticsControllerOptOutForRegularAccountAction\n | AnalyticsControllerOptInForSocialAccountAction\n | AnalyticsControllerOptOutForSocialAccountAction;\n"]}
1
+ {"version":3,"file":"AnalyticsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AnalyticsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AnalyticsController } from './AnalyticsController';\n\n/**\n * Track an analytics event.\n *\n * Events are only tracked if analytics is enabled.\n *\n * @param eventName - The name of the event\n * @param properties - Event properties\n */\nexport type AnalyticsControllerTrackEventAction = {\n type: `AnalyticsController:trackEvent`;\n handler: AnalyticsController['trackEvent'];\n};\n\n/**\n * Identify a user for analytics.\n *\n * @param userId - The user identifier (e.g., metametrics ID)\n * @param traits - User traits/properties\n */\nexport type AnalyticsControllerIdentifyAction = {\n type: `AnalyticsController:identify`;\n handler: AnalyticsController['identify'];\n};\n\n/**\n * Track a page view.\n *\n * @param pageName - The name of the page\n * @param properties - Page properties\n */\nexport type AnalyticsControllerTrackPageAction = {\n type: `AnalyticsController:trackPage`;\n handler: AnalyticsController['trackPage'];\n};\n\n/**\n * Enable analytics tracking.\n */\nexport type AnalyticsControllerEnableAction = {\n type: `AnalyticsController:enable`;\n handler: AnalyticsController['enable'];\n};\n\n/**\n * Disable analytics tracking.\n */\nexport type AnalyticsControllerDisableAction = {\n type: `AnalyticsController:disable`;\n handler: AnalyticsController['disable'];\n};\n\n/**\n * Opt in to analytics.\n */\nexport type AnalyticsControllerOptInAction = {\n type: `AnalyticsController:optIn`;\n handler: AnalyticsController['optIn'];\n};\n\n/**\n * Opt out of analytics.\n */\nexport type AnalyticsControllerOptOutAction = {\n type: `AnalyticsController:optOut`;\n handler: AnalyticsController['optOut'];\n};\n\n/**\n * Union of all AnalyticsController action types.\n */\nexport type AnalyticsControllerMethodActions =\n | AnalyticsControllerTrackEventAction\n | AnalyticsControllerIdentifyAction\n | AnalyticsControllerTrackPageAction\n | AnalyticsControllerEnableAction\n | AnalyticsControllerDisableAction\n | AnalyticsControllerOptInAction\n | AnalyticsControllerOptOutAction;\n"]}
@@ -16,8 +16,6 @@ exports.AnalyticsController = exports.getDefaultAnalyticsControllerState = expor
16
16
  const base_controller_1 = require("@metamask/base-controller");
17
17
  const uuid_1 = require("uuid");
18
18
  const AnalyticsLogger_1 = require("./AnalyticsLogger.cjs");
19
- const analyticsStateComputer_1 = require("./analyticsStateComputer.cjs");
20
- const analyticsStateValidator_1 = require("./analyticsStateValidator.cjs");
21
19
  // === GENERAL ===
22
20
  /**
23
21
  * The name of the {@link AnalyticsController}, used to namespace the
@@ -29,13 +27,13 @@ exports.controllerName = 'AnalyticsController';
29
27
  * The metadata for each property in {@link AnalyticsControllerState}.
30
28
  */
31
29
  const analyticsControllerMetadata = {
32
- optedInForRegularAccount: {
30
+ enabled: {
33
31
  includeInStateLogs: true,
34
32
  persist: true,
35
33
  includeInDebugSnapshot: true,
36
34
  usedInUi: true,
37
35
  },
38
- optedInForSocialAccount: {
36
+ optedIn: {
39
37
  includeInStateLogs: true,
40
38
  persist: true,
41
39
  includeInDebugSnapshot: true,
@@ -58,8 +56,8 @@ const analyticsControllerMetadata = {
58
56
  */
59
57
  function getDefaultAnalyticsControllerState() {
60
58
  return {
61
- optedInForRegularAccount: false,
62
- optedInForSocialAccount: false,
59
+ enabled: true,
60
+ optedIn: false,
63
61
  analyticsId: (0, uuid_1.v4)(),
64
62
  };
65
63
  }
@@ -68,11 +66,11 @@ exports.getDefaultAnalyticsControllerState = getDefaultAnalyticsControllerState;
68
66
  const MESSENGER_EXPOSED_METHODS = [
69
67
  'trackEvent',
70
68
  'identify',
71
- 'trackView',
72
- 'optInForRegularAccount',
73
- 'optOutForRegularAccount',
74
- 'optInForSocialAccount',
75
- 'optOutForSocialAccount',
69
+ 'trackPage',
70
+ 'enable',
71
+ 'disable',
72
+ 'optIn',
73
+ 'optOut',
76
74
  ];
77
75
  /**
78
76
  * The AnalyticsController manages analytics tracking across platforms (Mobile/Extension).
@@ -89,136 +87,109 @@ class AnalyticsController extends base_controller_1.BaseController {
89
87
  * Constructs an AnalyticsController instance.
90
88
  *
91
89
  * @param options - Controller options
92
- * @param options.state - Initial controller state (defaults from getDefaultAnalyticsControllerState).
93
- * For migration from a previous system, pass the existing analytics ID via state.analyticsId.
90
+ * @param options.state - Initial controller state (defaults from getDefaultAnalyticsControllerState)
94
91
  * @param options.messenger - Messenger used to communicate with BaseController
95
92
  * @param options.platformAdapter - Platform adapter implementation for tracking
96
93
  */
97
94
  constructor({ state = {}, messenger, platformAdapter, }) {
98
- const initialState = {
99
- ...getDefaultAnalyticsControllerState(),
100
- ...state,
101
- };
102
- (0, analyticsStateValidator_1.validateAnalyticsState)(initialState);
103
95
  super({
104
96
  name: exports.controllerName,
105
97
  metadata: analyticsControllerMetadata,
106
- state: initialState,
98
+ state: {
99
+ ...getDefaultAnalyticsControllerState(),
100
+ ...state,
101
+ },
107
102
  messenger,
108
103
  });
109
104
  _AnalyticsController_platformAdapter.set(this, void 0);
110
105
  __classPrivateFieldSet(this, _AnalyticsController_platformAdapter, platformAdapter, "f");
111
106
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
112
107
  (0, AnalyticsLogger_1.projectLogger)('AnalyticsController initialized and ready', {
113
- enabled: (0, analyticsStateComputer_1.computeEnabledState)(this.state),
114
- optedIn: this.state.optedInForRegularAccount,
115
- socialOptedIn: this.state.optedInForSocialAccount,
108
+ enabled: this.state.enabled,
109
+ optedIn: this.state.optedIn,
116
110
  analyticsId: this.state.analyticsId,
117
111
  });
118
- // Call onSetupCompleted lifecycle hook after initialization
119
- // State is already validated, so analyticsId is guaranteed to be a valid UUIDv4
120
- try {
121
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").onSetupCompleted(this.state.analyticsId);
122
- }
123
- catch (error) {
124
- // Log error but don't throw - adapter setup failure shouldn't break controller
125
- (0, AnalyticsLogger_1.projectLogger)('Error calling platformAdapter.onSetupCompleted', error);
126
- }
127
112
  }
128
113
  /**
129
114
  * Track an analytics event.
130
115
  *
131
116
  * Events are only tracked if analytics is enabled.
132
117
  *
133
- * @param event - Analytics event with properties and sensitive properties
118
+ * @param eventName - The name of the event
119
+ * @param properties - Event properties
134
120
  */
135
- trackEvent(event) {
121
+ trackEvent(eventName, properties = {}) {
136
122
  // Don't track if analytics is disabled
137
- if (!(0, analyticsStateComputer_1.computeEnabledState)(this.state)) {
138
- return;
139
- }
140
- // Derive sensitivity from presence of sensitiveProperties
141
- const hasSensitiveProperties = Object.keys(event.sensitiveProperties).length > 0;
142
- // if event does not have properties, send event without properties
143
- // and return to prevent any additional processing
144
- if (!event.hasProperties) {
145
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(event.name);
123
+ if (!this.state.enabled) {
146
124
  return;
147
125
  }
148
- // Track regular properties (without isSensitive flag - it's the default)
149
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(event.name, {
150
- ...event.properties,
151
- });
152
- // Track sensitive properties in a separate event with isSensitive flag
153
- if (hasSensitiveProperties) {
154
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").track(event.name, {
155
- isSensitive: true,
156
- ...event.properties,
157
- ...event.sensitiveProperties,
158
- });
159
- }
126
+ // Delegate to platform adapter
127
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").trackEvent(eventName, properties);
160
128
  }
161
129
  /**
162
130
  * Identify a user for analytics.
163
131
  *
132
+ * @param userId - The user identifier (e.g., metametrics ID)
164
133
  * @param traits - User traits/properties
165
134
  */
166
- identify(traits) {
167
- if (!(0, analyticsStateComputer_1.computeEnabledState)(this.state)) {
135
+ identify(userId, traits) {
136
+ if (!this.state.enabled) {
168
137
  return;
169
138
  }
170
- // Delegate to platform adapter if supported, using the current analytics ID
139
+ // Update state with analytics ID
140
+ this.update((state) => {
141
+ state.analyticsId = userId;
142
+ });
143
+ // Delegate to platform adapter if supported
171
144
  if (__classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").identify) {
172
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").identify(this.state.analyticsId, traits);
145
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").identify(userId, traits);
173
146
  }
174
147
  }
175
148
  /**
176
- * Track a page or screen view.
149
+ * Track a page view.
177
150
  *
178
- * @param name - The identifier/name of the page or screen being viewed (e.g., "home", "settings", "wallet")
179
- * @param properties - Optional properties associated with the view
151
+ * @param pageName - The name of the page
152
+ * @param properties - Page properties
180
153
  */
181
- trackView(name, properties) {
182
- if (!(0, analyticsStateComputer_1.computeEnabledState)(this.state)) {
154
+ trackPage(pageName, properties) {
155
+ if (!this.state.enabled) {
183
156
  return;
184
157
  }
185
- // Delegate to platform adapter
186
- __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").view(name, properties);
158
+ // Delegate to platform adapter if supported
159
+ if (__classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").trackPage) {
160
+ __classPrivateFieldGet(this, _AnalyticsController_platformAdapter, "f").trackPage(pageName, properties);
161
+ }
187
162
  }
188
163
  /**
189
- * Opt in to analytics for regular account.
190
- * This updates the user's opt-in status for regular account.
164
+ * Enable analytics tracking.
191
165
  */
192
- optInForRegularAccount() {
166
+ enable() {
193
167
  this.update((state) => {
194
- state.optedInForRegularAccount = true;
168
+ state.enabled = true;
195
169
  });
196
170
  }
197
171
  /**
198
- * Opt out of analytics for regular account.
199
- * This updates the user's opt-in status for regular account.
172
+ * Disable analytics tracking.
200
173
  */
201
- optOutForRegularAccount() {
174
+ disable() {
202
175
  this.update((state) => {
203
- state.optedInForRegularAccount = false;
176
+ state.enabled = false;
204
177
  });
205
178
  }
206
179
  /**
207
- * Opt in to analytics for social account.
208
- * This updates the user's opt-in status for social account.
180
+ * Opt in to analytics.
209
181
  */
210
- optInForSocialAccount() {
182
+ optIn() {
211
183
  this.update((state) => {
212
- state.optedInForSocialAccount = true;
184
+ state.optedIn = true;
213
185
  });
214
186
  }
215
187
  /**
216
- * Opt out of analytics for social account.
217
- * This updates the user's opt-in status for social account.
188
+ * Opt out of analytics.
218
189
  */
219
- optOutForSocialAccount() {
190
+ optOut() {
220
191
  this.update((state) => {
221
- state.optedInForSocialAccount = false;
192
+ state.optedIn = false;
222
193
  });
223
194
  }
224
195
  }