@metamask-previews/analytics-controller 0.0.0-preview-a5935709 → 0.0.0-preview-e493d3e8
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 +1 -1
- package/README.md +105 -208
- package/dist/AnalyticsController-method-action-types.cjs.map +1 -1
- package/dist/AnalyticsController-method-action-types.d.cts +26 -28
- package/dist/AnalyticsController-method-action-types.d.cts.map +1 -1
- package/dist/AnalyticsController-method-action-types.d.mts +26 -28
- 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 +73 -110
- package/dist/AnalyticsController.cjs.map +1 -1
- package/dist/AnalyticsController.d.cts +32 -50
- package/dist/AnalyticsController.d.cts.map +1 -1
- package/dist/AnalyticsController.d.mts +32 -50
- package/dist/AnalyticsController.d.mts.map +1 -1
- package/dist/AnalyticsController.mjs +72 -109
- package/dist/AnalyticsController.mjs.map +1 -1
- package/dist/AnalyticsPlatformAdapter.types.cjs.map +1 -1
- package/dist/AnalyticsPlatformAdapter.types.d.cts +15 -63
- package/dist/AnalyticsPlatformAdapter.types.d.cts.map +1 -1
- package/dist/AnalyticsPlatformAdapter.types.d.mts +15 -63
- package/dist/AnalyticsPlatformAdapter.types.d.mts.map +1 -1
- package/dist/AnalyticsPlatformAdapter.types.mjs.map +1 -1
- package/dist/index.cjs +4 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/AnalyticsPlatformAdapterSetupError.cjs +0 -17
- package/dist/AnalyticsPlatformAdapterSetupError.cjs.map +0 -1
- package/dist/AnalyticsPlatformAdapterSetupError.d.cts +0 -8
- package/dist/AnalyticsPlatformAdapterSetupError.d.cts.map +0 -1
- package/dist/AnalyticsPlatformAdapterSetupError.d.mts +0 -8
- package/dist/AnalyticsPlatformAdapterSetupError.d.mts.map +0 -1
- package/dist/AnalyticsPlatformAdapterSetupError.mjs +0 -13
- package/dist/AnalyticsPlatformAdapterSetupError.mjs.map +0 -1
- package/dist/analyticsControllerStateValidator.cjs +0 -34
- package/dist/analyticsControllerStateValidator.cjs.map +0 -1
- package/dist/analyticsControllerStateValidator.d.cts +0 -16
- package/dist/analyticsControllerStateValidator.d.cts.map +0 -1
- package/dist/analyticsControllerStateValidator.d.mts +0 -16
- package/dist/analyticsControllerStateValidator.d.mts.map +0 -1
- package/dist/analyticsControllerStateValidator.mjs +0 -29
- package/dist/analyticsControllerStateValidator.mjs.map +0 -1
- package/dist/selectors.cjs +0 -43
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -12
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -12
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs +0 -40
- 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.
|
|
13
13
|
|
|
14
14
|
[Unreleased]: https://github.com/MetaMask/core/
|
package/README.md
CHANGED
|
@@ -4,10 +4,13 @@ Common Analytics controller for event tracking.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Provides a unified interface for:
|
|
8
|
+
- Tracking analytics events
|
|
9
|
+
- Identifying users
|
|
10
|
+
- Managing analytics preferences (enable/disable, opt-in/opt-out)
|
|
8
11
|
- Delegates platform-specific implementation to `AnalyticsPlatformAdapter`
|
|
9
12
|
- Integrates with the MetaMask messenger system for inter-controller communication
|
|
10
|
-
-
|
|
13
|
+
- Supports state persistence and migrations
|
|
11
14
|
|
|
12
15
|
## Installation
|
|
13
16
|
|
|
@@ -21,290 +24,184 @@ or
|
|
|
21
24
|
|
|
22
25
|
### 1. Create a Platform Adapter
|
|
23
26
|
|
|
24
|
-
The controller delegates platform-specific analytics implementation to
|
|
27
|
+
The controller delegates platform-specific analytics implementation to a `AnalyticsPlatformAdapter`. You must provide an adapter that implements the required methods:
|
|
25
28
|
|
|
26
29
|
```typescript
|
|
27
30
|
import type { AnalyticsPlatformAdapter } from '@metamask/analytics-controller';
|
|
28
31
|
|
|
29
32
|
const platformAdapter: AnalyticsPlatformAdapter = {
|
|
30
|
-
|
|
33
|
+
trackEvent: (eventName: string, properties: Record<string, unknown>) => {
|
|
34
|
+
// Platform-specific implementation (e.g., Segment, Mixpanel, etc.)
|
|
31
35
|
segment.track(eventName, properties);
|
|
32
36
|
},
|
|
33
37
|
identify: (userId: string, traits?: Record<string, unknown>) => {
|
|
34
38
|
segment.identify(userId, traits);
|
|
35
39
|
},
|
|
36
|
-
|
|
37
|
-
segment.page(
|
|
38
|
-
},
|
|
39
|
-
onSetupCompleted: async (analyticsId: string) => {
|
|
40
|
-
// Lifecycle hook called after controller initialization
|
|
41
|
-
// The analyticsId is guaranteed to be set when this method is called
|
|
42
|
-
// Use this for platform-specific setup that requires the analytics ID
|
|
43
|
-
// For example, adding plugins that need the analytics ID:
|
|
44
|
-
segment.add({
|
|
45
|
-
plugin: new PrivacyPlugin(analyticsId),
|
|
46
|
-
});
|
|
40
|
+
trackPage: (pageName: string, properties?: Record<string, unknown>) => {
|
|
41
|
+
segment.page(pageName, properties);
|
|
47
42
|
},
|
|
48
43
|
};
|
|
49
44
|
```
|
|
50
45
|
|
|
51
|
-
### 2.
|
|
52
|
-
|
|
53
|
-
The platform is responsible for loading and persisting analytics settings—the controller does not handle storage internally. This design allows:
|
|
46
|
+
### 2. Initialize the Controller
|
|
54
47
|
|
|
55
|
-
|
|
56
|
-
- **Resilience**: Storing analytics settings separately from main state protects them from state corruption, allowing analytics to continue working even when main state is corrupted
|
|
48
|
+
#### Basic Initialization (Uses Defaults)
|
|
57
49
|
|
|
58
|
-
|
|
50
|
+
The controller uses default state values when no `state` parameter is provided:
|
|
59
51
|
|
|
60
52
|
```typescript
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
]);
|
|
75
|
-
|
|
76
|
-
const defaults = getDefaultAnalyticsControllerState();
|
|
77
|
-
|
|
78
|
-
// Generate UUID on first run if not in storage
|
|
79
|
-
let analyticsId = savedAnalyticsId;
|
|
80
|
-
if (!analyticsId) {
|
|
81
|
-
analyticsId = uuidv4();
|
|
82
|
-
// Persist immediately - this ID must never change
|
|
83
|
-
await storage.setItem('analytics.id', analyticsId);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Parse boolean values (stored as strings)
|
|
87
|
-
const optedInForRegularAccount =
|
|
88
|
-
savedOptedInRegular !== null
|
|
89
|
-
? savedOptedInRegular === 'true'
|
|
90
|
-
: defaults.optedInForRegularAccount;
|
|
91
|
-
|
|
92
|
-
const optedInForSocialAccount =
|
|
93
|
-
savedOptedInSocial !== null
|
|
94
|
-
? savedOptedInSocial === 'true'
|
|
95
|
-
: defaults.optedInForSocialAccount;
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
analyticsId,
|
|
99
|
-
optedInForRegularAccount,
|
|
100
|
-
optedInForSocialAccount,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
53
|
+
import { AnalyticsController } from '@metamask/analytics-controller';
|
|
54
|
+
import { Messenger } from '@metamask/messenger';
|
|
55
|
+
|
|
56
|
+
const messenger = new Messenger({ namespace: 'AnalyticsController' });
|
|
57
|
+
|
|
58
|
+
const controller = new AnalyticsController({
|
|
59
|
+
messenger,
|
|
60
|
+
platformAdapter,
|
|
61
|
+
// State defaults to:
|
|
62
|
+
// - enabled: true
|
|
63
|
+
// - optedIn: false
|
|
64
|
+
// - analyticsId: auto-generated UUIDv4 (if not provided)
|
|
65
|
+
});
|
|
103
66
|
```
|
|
104
67
|
|
|
105
|
-
|
|
68
|
+
#### Custom Initial State
|
|
106
69
|
|
|
107
|
-
|
|
70
|
+
You can provide partial state to override defaults:
|
|
108
71
|
|
|
109
72
|
```typescript
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
'analytics.optedInForRegularAccount',
|
|
120
|
-
String(state.optedInForRegularAccount),
|
|
121
|
-
);
|
|
122
|
-
storage.setItem(
|
|
123
|
-
'analytics.optedInForSocialAccount',
|
|
124
|
-
String(state.optedInForSocialAccount),
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function initializeAnalyticsController(
|
|
129
|
-
messenger: AnalyticsControllerMessenger,
|
|
130
|
-
): Promise<AnalyticsController> {
|
|
131
|
-
// 1. Load settings from storage
|
|
132
|
-
const state = await loadAnalyticsSettings();
|
|
133
|
-
|
|
134
|
-
// 2. Create controller with loaded state
|
|
135
|
-
const controller = new AnalyticsController({
|
|
136
|
-
messenger,
|
|
137
|
-
platformAdapter,
|
|
138
|
-
state, // Must include valid UUIDv4 analyticsId
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// 3. Subscribe to state changes for persistence
|
|
142
|
-
messenger.subscribe('AnalyticsController:stateChange', (newState) => {
|
|
143
|
-
persistAnalyticsSettings(newState);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
return controller;
|
|
147
|
-
}
|
|
73
|
+
const controller = new AnalyticsController({
|
|
74
|
+
messenger,
|
|
75
|
+
platformAdapter,
|
|
76
|
+
state: {
|
|
77
|
+
enabled: false, // Override default (true)
|
|
78
|
+
optedIn: true, // Override default (false)
|
|
79
|
+
analyticsId: '550e8400-e29b-41d4-a716-446655440000', // Override default
|
|
80
|
+
},
|
|
81
|
+
});
|
|
148
82
|
```
|
|
149
83
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
One benefit of platform-managed storage is accessing the analytics ID before the controller is initialized:
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
async function getAnalyticsId(): Promise<string | null> {
|
|
156
|
-
return storage.getItem('analytics.id');
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Use in other controllers or early initialization
|
|
160
|
-
const analyticsId = await getAnalyticsId();
|
|
161
|
-
if (analyticsId) {
|
|
162
|
-
// Use analyticsId before AnalyticsController is ready
|
|
163
|
-
}
|
|
164
|
-
```
|
|
84
|
+
**Important:** The `state` parameter is the single source of truth for initial values. Any properties you provide will override the defaults from `getDefaultAnalyticsControllerState()`.
|
|
165
85
|
|
|
166
|
-
###
|
|
86
|
+
### 3. Track Events
|
|
167
87
|
|
|
168
88
|
```typescript
|
|
169
|
-
// Track
|
|
170
|
-
controller.trackEvent({
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
sensitiveProperties: {},
|
|
174
|
-
hasProperties: true,
|
|
175
|
-
saveDataRecording: true,
|
|
89
|
+
// Track a simple event
|
|
90
|
+
controller.trackEvent('wallet_connected', {
|
|
91
|
+
network: 'ethereum',
|
|
92
|
+
account_type: 'hd',
|
|
176
93
|
});
|
|
177
94
|
|
|
178
|
-
// Events are filtered when analytics is disabled
|
|
95
|
+
// Events are automatically filtered when analytics is disabled
|
|
96
|
+
controller.disable();
|
|
97
|
+
controller.trackEvent('some_event'); // This will not be tracked
|
|
179
98
|
```
|
|
180
99
|
|
|
181
|
-
###
|
|
100
|
+
### 4. Identify Users
|
|
182
101
|
|
|
183
102
|
```typescript
|
|
184
|
-
controller.identify({
|
|
185
|
-
|
|
186
|
-
|
|
103
|
+
controller.identify('550e8400-e29b-41d4-a716-446655440000', {
|
|
104
|
+
email: 'user@example.com',
|
|
105
|
+
plan: 'premium',
|
|
187
106
|
});
|
|
188
107
|
|
|
189
|
-
//
|
|
108
|
+
// The analytics ID is automatically stored in controller state
|
|
109
|
+
console.log(controller.state.analyticsId); // '550e8400-e29b-41d4-a716-446655440000'
|
|
190
110
|
```
|
|
191
111
|
|
|
192
|
-
###
|
|
112
|
+
### 5. Track Page Views
|
|
193
113
|
|
|
194
114
|
```typescript
|
|
195
|
-
controller.
|
|
115
|
+
controller.trackPage('home', {
|
|
196
116
|
referrer: 'google',
|
|
197
117
|
campaign: 'summer-2024',
|
|
198
118
|
});
|
|
199
119
|
```
|
|
200
120
|
|
|
201
|
-
###
|
|
121
|
+
### 6. Manage Analytics State
|
|
202
122
|
|
|
203
123
|
```typescript
|
|
204
|
-
//
|
|
205
|
-
controller.
|
|
206
|
-
controller.
|
|
207
|
-
|
|
208
|
-
// Opt in/out for social account
|
|
209
|
-
controller.optInForSocialAccount();
|
|
210
|
-
controller.optOutForSocialAccount();
|
|
124
|
+
// Enable/disable analytics
|
|
125
|
+
controller.enable();
|
|
126
|
+
controller.disable();
|
|
211
127
|
|
|
212
|
-
//
|
|
128
|
+
// Opt in/out
|
|
129
|
+
controller.optIn();
|
|
130
|
+
controller.optOut();
|
|
213
131
|
```
|
|
214
132
|
|
|
215
|
-
###
|
|
133
|
+
### 7. Use Messenger Actions
|
|
134
|
+
|
|
135
|
+
The controller exposes methods as messenger actions for inter-controller communication:
|
|
216
136
|
|
|
217
137
|
```typescript
|
|
218
138
|
// From another controller
|
|
219
|
-
messenger.call('AnalyticsController:trackEvent', {
|
|
220
|
-
|
|
221
|
-
properties: { wallet_type: 'hd' },
|
|
222
|
-
sensitiveProperties: {},
|
|
223
|
-
hasProperties: true,
|
|
224
|
-
saveDataRecording: true,
|
|
139
|
+
messenger.call('AnalyticsController:trackEvent', 'wallet_created', {
|
|
140
|
+
wallet_type: 'hd',
|
|
225
141
|
});
|
|
226
142
|
|
|
227
|
-
messenger.call(
|
|
143
|
+
messenger.call(
|
|
144
|
+
'AnalyticsController:identify',
|
|
145
|
+
'550e8400-e29b-41d4-a716-446655440000',
|
|
146
|
+
{
|
|
147
|
+
email: 'newuser@example.com',
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
messenger.call('AnalyticsController:enable');
|
|
152
|
+
messenger.call('AnalyticsController:disable');
|
|
153
|
+
messenger.call('AnalyticsController:optIn');
|
|
154
|
+
messenger.call('AnalyticsController:optOut');
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 8. Subscribe to State Changes
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
messenger.subscribe('AnalyticsController:stateChange', (state, prevState) => {
|
|
161
|
+
console.log('Analytics state changed:', {
|
|
162
|
+
enabled: state.enabled,
|
|
163
|
+
optedIn: state.optedIn,
|
|
164
|
+
analyticsId: state.analyticsId,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
228
167
|
```
|
|
229
168
|
|
|
230
169
|
## State Management
|
|
231
170
|
|
|
232
171
|
### Default State
|
|
233
172
|
|
|
234
|
-
|
|
173
|
+
The default state is provided by `getDefaultAnalyticsControllerState()`:
|
|
235
174
|
|
|
236
175
|
```typescript
|
|
237
176
|
import { getDefaultAnalyticsControllerState } from '@metamask/analytics-controller';
|
|
238
177
|
|
|
239
|
-
const
|
|
240
|
-
//
|
|
241
|
-
//
|
|
178
|
+
const defaultState = getDefaultAnalyticsControllerState();
|
|
179
|
+
// {
|
|
180
|
+
// enabled: true,
|
|
181
|
+
// optedIn: false,
|
|
182
|
+
// analyticsId: auto-generated UUIDv4
|
|
183
|
+
// }
|
|
242
184
|
```
|
|
243
185
|
|
|
244
|
-
###
|
|
245
|
-
|
|
246
|
-
| Field | Type | Description |
|
|
247
|
-
| -------------------------- | --------- | -------------------------------------- |
|
|
248
|
-
| `analyticsId` | `string` | UUIDv4 identifier (platform-generated) |
|
|
249
|
-
| `optedInForRegularAccount` | `boolean` | User opt-in status for regular account |
|
|
250
|
-
| `optedInForSocialAccount` | `boolean` | User opt-in status for social account |
|
|
251
|
-
|
|
252
|
-
### Why `analyticsId` Has No Default
|
|
253
|
-
|
|
254
|
-
The `analyticsId` is an **identity** (unique per user), not a **preference** (static default). A default should return the same value each call (deterministic), but a UUID must be unique each time (non-deterministic). These are mutually exclusive.
|
|
255
|
-
|
|
256
|
-
**Solution:** Platform generates the UUID once on first run, persists it, and provides it to the controller.
|
|
257
|
-
|
|
258
|
-
### Platform Responsibilities
|
|
186
|
+
### Initialization Strategy
|
|
259
187
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
4. **Persist to isolated storage**: Keep analytics settings separate from main state (protects against state corruption)
|
|
188
|
+
- **No `state` parameter**: Uses defaults from `getDefaultAnalyticsControllerState()` and auto-generates `analyticsId` as UUIDv4
|
|
189
|
+
- **Partial `state`**: Merges with defaults (user-provided values override defaults); `analyticsId` is auto-generated if not provided
|
|
190
|
+
- **Complete `state`**: Full control for migrations and advanced use cases
|
|
264
191
|
|
|
265
|
-
|
|
192
|
+
**Best Practice:** Use `state` as the single source of truth for initial values. Do not use convenience parameters—they have been removed to ensure consistency.
|
|
266
193
|
|
|
267
|
-
|
|
268
|
-
- **Protection from state corruption**: Analytics settings in separate storage survive main state corruption
|
|
269
|
-
- **Analytics during corruption**: Can still report issues even when main state is corrupted
|
|
270
|
-
- **Platform flexibility**: Each platform uses its preferred storage mechanism
|
|
271
|
-
|
|
272
|
-
## Lifecycle Hooks
|
|
273
|
-
|
|
274
|
-
### `onSetupCompleted`
|
|
275
|
-
|
|
276
|
-
Called once after controller initialization with guaranteed valid `analyticsId`:
|
|
277
|
-
|
|
278
|
-
```typescript
|
|
279
|
-
onSetupCompleted: async (analyticsId: string) => {
|
|
280
|
-
// analyticsId is guaranteed to be a valid UUIDv4
|
|
281
|
-
client.add({ plugin: new PrivacyPlugin(analyticsId) });
|
|
282
|
-
},
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
Errors in `onSetupCompleted` are caught and logged—they don't break the controller.
|
|
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).
|
|
286
195
|
|
|
287
196
|
## Debugging
|
|
288
197
|
|
|
289
|
-
|
|
198
|
+
To display analytics-controller logs in the mobile app, you can add the following to your `.js.env` file:
|
|
290
199
|
|
|
291
200
|
```bash
|
|
292
201
|
export DEBUG="metamask:analytics-controller"
|
|
293
202
|
```
|
|
294
203
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
### Build
|
|
298
|
-
|
|
299
|
-
```bash
|
|
300
|
-
yarn install && yarn workspace @metamask/analytics-controller build
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
### Test
|
|
304
|
-
|
|
305
|
-
```bash
|
|
306
|
-
yarn install && yarn workspace @metamask/analytics-controller test
|
|
307
|
-
```
|
|
204
|
+
This will enable debug logging for the analytics-controller, allowing you to see detailed logs of analytics events, state changes, and controller operations.
|
|
308
205
|
|
|
309
206
|
## Contributing
|
|
310
207
|
|
|
@@ -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
|
|
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
|
|
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
|
|
29
|
+
* Track a page view.
|
|
28
30
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param properties -
|
|
31
|
+
* @param pageName - The name of the page
|
|
32
|
+
* @param properties - Page properties
|
|
31
33
|
*/
|
|
32
|
-
export type
|
|
33
|
-
type: `AnalyticsController:
|
|
34
|
-
handler: AnalyticsController['
|
|
34
|
+
export type AnalyticsControllerTrackPageAction = {
|
|
35
|
+
type: `AnalyticsController:trackPage`;
|
|
36
|
+
handler: AnalyticsController['trackPage'];
|
|
35
37
|
};
|
|
36
38
|
/**
|
|
37
|
-
*
|
|
38
|
-
* This updates the user's opt-in status for regular account.
|
|
39
|
+
* Enable analytics tracking.
|
|
39
40
|
*/
|
|
40
|
-
export type
|
|
41
|
-
type: `AnalyticsController:
|
|
42
|
-
handler: AnalyticsController['
|
|
41
|
+
export type AnalyticsControllerEnableAction = {
|
|
42
|
+
type: `AnalyticsController:enable`;
|
|
43
|
+
handler: AnalyticsController['enable'];
|
|
43
44
|
};
|
|
44
45
|
/**
|
|
45
|
-
*
|
|
46
|
-
* This updates the user's opt-in status for regular account.
|
|
46
|
+
* Disable analytics tracking.
|
|
47
47
|
*/
|
|
48
|
-
export type
|
|
49
|
-
type: `AnalyticsController:
|
|
50
|
-
handler: AnalyticsController['
|
|
48
|
+
export type AnalyticsControllerDisableAction = {
|
|
49
|
+
type: `AnalyticsController:disable`;
|
|
50
|
+
handler: AnalyticsController['disable'];
|
|
51
51
|
};
|
|
52
52
|
/**
|
|
53
|
-
* Opt in to analytics
|
|
54
|
-
* This updates the user's opt-in status for social account.
|
|
53
|
+
* Opt in to analytics.
|
|
55
54
|
*/
|
|
56
|
-
export type
|
|
57
|
-
type: `AnalyticsController:
|
|
58
|
-
handler: AnalyticsController['
|
|
55
|
+
export type AnalyticsControllerOptInAction = {
|
|
56
|
+
type: `AnalyticsController:optIn`;
|
|
57
|
+
handler: AnalyticsController['optIn'];
|
|
59
58
|
};
|
|
60
59
|
/**
|
|
61
|
-
* Opt out of analytics
|
|
62
|
-
* This updates the user's opt-in status for social account.
|
|
60
|
+
* Opt out of analytics.
|
|
63
61
|
*/
|
|
64
|
-
export type
|
|
65
|
-
type: `AnalyticsController:
|
|
66
|
-
handler: AnalyticsController['
|
|
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 |
|
|
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
|
|
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
|
|
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
|
|
29
|
+
* Track a page view.
|
|
28
30
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param properties -
|
|
31
|
+
* @param pageName - The name of the page
|
|
32
|
+
* @param properties - Page properties
|
|
31
33
|
*/
|
|
32
|
-
export type
|
|
33
|
-
type: `AnalyticsController:
|
|
34
|
-
handler: AnalyticsController['
|
|
34
|
+
export type AnalyticsControllerTrackPageAction = {
|
|
35
|
+
type: `AnalyticsController:trackPage`;
|
|
36
|
+
handler: AnalyticsController['trackPage'];
|
|
35
37
|
};
|
|
36
38
|
/**
|
|
37
|
-
*
|
|
38
|
-
* This updates the user's opt-in status for regular account.
|
|
39
|
+
* Enable analytics tracking.
|
|
39
40
|
*/
|
|
40
|
-
export type
|
|
41
|
-
type: `AnalyticsController:
|
|
42
|
-
handler: AnalyticsController['
|
|
41
|
+
export type AnalyticsControllerEnableAction = {
|
|
42
|
+
type: `AnalyticsController:enable`;
|
|
43
|
+
handler: AnalyticsController['enable'];
|
|
43
44
|
};
|
|
44
45
|
/**
|
|
45
|
-
*
|
|
46
|
-
* This updates the user's opt-in status for regular account.
|
|
46
|
+
* Disable analytics tracking.
|
|
47
47
|
*/
|
|
48
|
-
export type
|
|
49
|
-
type: `AnalyticsController:
|
|
50
|
-
handler: AnalyticsController['
|
|
48
|
+
export type AnalyticsControllerDisableAction = {
|
|
49
|
+
type: `AnalyticsController:disable`;
|
|
50
|
+
handler: AnalyticsController['disable'];
|
|
51
51
|
};
|
|
52
52
|
/**
|
|
53
|
-
* Opt in to analytics
|
|
54
|
-
* This updates the user's opt-in status for social account.
|
|
53
|
+
* Opt in to analytics.
|
|
55
54
|
*/
|
|
56
|
-
export type
|
|
57
|
-
type: `AnalyticsController:
|
|
58
|
-
handler: AnalyticsController['
|
|
55
|
+
export type AnalyticsControllerOptInAction = {
|
|
56
|
+
type: `AnalyticsController:optIn`;
|
|
57
|
+
handler: AnalyticsController['optIn'];
|
|
59
58
|
};
|
|
60
59
|
/**
|
|
61
|
-
* Opt out of analytics
|
|
62
|
-
* This updates the user's opt-in status for social account.
|
|
60
|
+
* Opt out of analytics.
|
|
63
61
|
*/
|
|
64
|
-
export type
|
|
65
|
-
type: `AnalyticsController:
|
|
66
|
-
handler: AnalyticsController['
|
|
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 |
|
|
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
|
|
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"}
|