@od-oneapp/analytics 2026.1.1301
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/README.md +509 -0
- package/dist/ai-YMnynb-t.mjs +3347 -0
- package/dist/ai-YMnynb-t.mjs.map +1 -0
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/client-CTzJVFU5.mjs +9 -0
- package/dist/client-CTzJVFU5.mjs.map +1 -0
- package/dist/client-CcFTauAh.mjs +54 -0
- package/dist/client-CcFTauAh.mjs.map +1 -0
- package/dist/client-CeOLjbac.mjs +281 -0
- package/dist/client-CeOLjbac.mjs.map +1 -0
- package/dist/client-D339NFJS.mjs +267 -0
- package/dist/client-D339NFJS.mjs.map +1 -0
- package/dist/client-next.d.mts +62 -0
- package/dist/client-next.d.mts.map +1 -0
- package/dist/client-next.mjs +525 -0
- package/dist/client-next.mjs.map +1 -0
- package/dist/client.d.mts +30 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +186 -0
- package/dist/client.mjs.map +1 -0
- package/dist/config-DPS6bSYo.d.mts +34 -0
- package/dist/config-DPS6bSYo.d.mts.map +1 -0
- package/dist/config-P6P5adJg.mjs +287 -0
- package/dist/config-P6P5adJg.mjs.map +1 -0
- package/dist/console-8bND3mMU.mjs +128 -0
- package/dist/console-8bND3mMU.mjs.map +1 -0
- package/dist/ecommerce-Cgu4wlux.mjs +993 -0
- package/dist/ecommerce-Cgu4wlux.mjs.map +1 -0
- package/dist/emitters-6-nKo8i-.mjs +208 -0
- package/dist/emitters-6-nKo8i-.mjs.map +1 -0
- package/dist/emitters-DldkVSPp.d.mts +12 -0
- package/dist/emitters-DldkVSPp.d.mts.map +1 -0
- package/dist/index-BfNWgfa5.d.mts +1494 -0
- package/dist/index-BfNWgfa5.d.mts.map +1 -0
- package/dist/index-BkIWe--N.d.mts +953 -0
- package/dist/index-BkIWe--N.d.mts.map +1 -0
- package/dist/index-jPzXRn52.d.mts +184 -0
- package/dist/index-jPzXRn52.d.mts.map +1 -0
- package/dist/manager-DvRRjza6.d.mts +76 -0
- package/dist/manager-DvRRjza6.d.mts.map +1 -0
- package/dist/posthog-bootstrap-CYfIy_WS.mjs +1769 -0
- package/dist/posthog-bootstrap-CYfIy_WS.mjs.map +1 -0
- package/dist/posthog-bootstrap-DWxFrxlt.d.mts +81 -0
- package/dist/posthog-bootstrap-DWxFrxlt.d.mts.map +1 -0
- package/dist/providers-http-client.d.mts +37 -0
- package/dist/providers-http-client.d.mts.map +1 -0
- package/dist/providers-http-client.mjs +320 -0
- package/dist/providers-http-client.mjs.map +1 -0
- package/dist/providers-http-server.d.mts +31 -0
- package/dist/providers-http-server.d.mts.map +1 -0
- package/dist/providers-http-server.mjs +297 -0
- package/dist/providers-http-server.mjs.map +1 -0
- package/dist/providers-http.d.mts +46 -0
- package/dist/providers-http.d.mts.map +1 -0
- package/dist/providers-http.mjs +4 -0
- package/dist/server-edge.d.mts +9 -0
- package/dist/server-edge.d.mts.map +1 -0
- package/dist/server-edge.mjs +373 -0
- package/dist/server-edge.mjs.map +1 -0
- package/dist/server-next.d.mts +67 -0
- package/dist/server-next.d.mts.map +1 -0
- package/dist/server-next.mjs +193 -0
- package/dist/server-next.mjs.map +1 -0
- package/dist/server.d.mts +10 -0
- package/dist/server.mjs +7 -0
- package/dist/service-cYtBBL8x.mjs +945 -0
- package/dist/service-cYtBBL8x.mjs.map +1 -0
- package/dist/shared.d.mts +16 -0
- package/dist/shared.d.mts.map +1 -0
- package/dist/shared.mjs +93 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/types-BxBnNQ0V.d.mts +354 -0
- package/dist/types-BxBnNQ0V.d.mts.map +1 -0
- package/dist/types-CBvxUEaF.d.mts +216 -0
- package/dist/types-CBvxUEaF.d.mts.map +1 -0
- package/dist/types.d.mts +4 -0
- package/dist/types.mjs +0 -0
- package/dist/vercel-types-lwakUfoI.d.mts +102 -0
- package/dist/vercel-types-lwakUfoI.d.mts.map +1 -0
- package/package.json +129 -0
- package/src/client/index.ts +164 -0
- package/src/client/manager.ts +71 -0
- package/src/client/next/components.tsx +270 -0
- package/src/client/next/hooks.ts +217 -0
- package/src/client/next/manager.ts +141 -0
- package/src/client/next.ts +144 -0
- package/src/client-next.ts +101 -0
- package/src/client.ts +89 -0
- package/src/examples/ai-sdk-patterns.ts +583 -0
- package/src/examples/emitter-patterns.ts +476 -0
- package/src/examples/nextjs-emitter-patterns.tsx +403 -0
- package/src/next/app-router.tsx +564 -0
- package/src/next/client.ts +419 -0
- package/src/next/index.ts +84 -0
- package/src/next/middleware.ts +429 -0
- package/src/next/rsc.tsx +300 -0
- package/src/next/server.ts +253 -0
- package/src/next/types.d.ts +220 -0
- package/src/providers/base-provider.ts +419 -0
- package/src/providers/console/client.ts +10 -0
- package/src/providers/console/index.ts +152 -0
- package/src/providers/console/server.ts +6 -0
- package/src/providers/console/types.ts +15 -0
- package/src/providers/http/client.ts +464 -0
- package/src/providers/http/index.ts +30 -0
- package/src/providers/http/server.ts +396 -0
- package/src/providers/http/types.ts +135 -0
- package/src/providers/posthog/client.ts +518 -0
- package/src/providers/posthog/index.ts +11 -0
- package/src/providers/posthog/server.ts +329 -0
- package/src/providers/posthog/types.ts +104 -0
- package/src/providers/segment/client.ts +113 -0
- package/src/providers/segment/index.ts +11 -0
- package/src/providers/segment/server.ts +115 -0
- package/src/providers/segment/types.ts +51 -0
- package/src/providers/vercel/client.ts +102 -0
- package/src/providers/vercel/index.ts +11 -0
- package/src/providers/vercel/server.ts +89 -0
- package/src/providers/vercel/types.ts +27 -0
- package/src/server/index.ts +103 -0
- package/src/server/manager.ts +62 -0
- package/src/server/next.ts +210 -0
- package/src/server-edge.ts +442 -0
- package/src/server-next.ts +39 -0
- package/src/server.ts +106 -0
- package/src/shared/emitters/ai/README.md +981 -0
- package/src/shared/emitters/ai/events/agent.ts +130 -0
- package/src/shared/emitters/ai/events/artifacts.ts +167 -0
- package/src/shared/emitters/ai/events/chat.ts +126 -0
- package/src/shared/emitters/ai/events/chatbot-ecommerce.ts +133 -0
- package/src/shared/emitters/ai/events/completion.ts +103 -0
- package/src/shared/emitters/ai/events/content-generation.ts +347 -0
- package/src/shared/emitters/ai/events/conversation.ts +332 -0
- package/src/shared/emitters/ai/events/product-features.ts +1402 -0
- package/src/shared/emitters/ai/events/streaming.ts +114 -0
- package/src/shared/emitters/ai/events/tool.ts +93 -0
- package/src/shared/emitters/ai/index.ts +69 -0
- package/src/shared/emitters/ai/track-ai-sdk.ts +74 -0
- package/src/shared/emitters/ai/track-ai.ts +50 -0
- package/src/shared/emitters/ai/types.ts +1041 -0
- package/src/shared/emitters/ai/utils.ts +468 -0
- package/src/shared/emitters/ecommerce/events/cart-checkout.ts +106 -0
- package/src/shared/emitters/ecommerce/events/coupon.ts +49 -0
- package/src/shared/emitters/ecommerce/events/engagement.ts +61 -0
- package/src/shared/emitters/ecommerce/events/marketplace.ts +119 -0
- package/src/shared/emitters/ecommerce/events/order.ts +199 -0
- package/src/shared/emitters/ecommerce/events/product.ts +205 -0
- package/src/shared/emitters/ecommerce/events/registry.ts +123 -0
- package/src/shared/emitters/ecommerce/events/wishlist-sharing.ts +140 -0
- package/src/shared/emitters/ecommerce/index.ts +46 -0
- package/src/shared/emitters/ecommerce/track-ecommerce.ts +53 -0
- package/src/shared/emitters/ecommerce/types.ts +314 -0
- package/src/shared/emitters/ecommerce/utils.ts +216 -0
- package/src/shared/emitters/emitter-types.ts +974 -0
- package/src/shared/emitters/emitters.ts +292 -0
- package/src/shared/emitters/helpers.ts +419 -0
- package/src/shared/emitters/index.ts +66 -0
- package/src/shared/index.ts +142 -0
- package/src/shared/ingestion/index.ts +66 -0
- package/src/shared/ingestion/schemas.ts +386 -0
- package/src/shared/ingestion/service.ts +628 -0
- package/src/shared/node22-features.ts +848 -0
- package/src/shared/providers/console-provider.ts +160 -0
- package/src/shared/types/base-types.ts +54 -0
- package/src/shared/types/console-types.ts +19 -0
- package/src/shared/types/posthog-types.ts +131 -0
- package/src/shared/types/segment-types.ts +15 -0
- package/src/shared/types/types.ts +397 -0
- package/src/shared/types/vercel-types.ts +19 -0
- package/src/shared/utils/config-client.ts +19 -0
- package/src/shared/utils/config.ts +250 -0
- package/src/shared/utils/emitter-adapter.ts +212 -0
- package/src/shared/utils/manager.test.ts +36 -0
- package/src/shared/utils/manager.ts +1322 -0
- package/src/shared/utils/posthog-bootstrap.ts +136 -0
- package/src/shared/utils/posthog-client-utils.ts +48 -0
- package/src/shared/utils/posthog-next-utils.ts +282 -0
- package/src/shared/utils/posthog-server-utils.ts +210 -0
- package/src/shared/utils/rate-limit.ts +289 -0
- package/src/shared/utils/security.ts +545 -0
- package/src/shared/utils/validation-client.ts +161 -0
- package/src/shared/utils/validation.ts +399 -0
- package/src/shared.ts +155 -0
- package/src/types/index.ts +62 -0
|
@@ -0,0 +1,974 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Type Definitions for Analytics Emitters
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive type definitions for analytics emitters based on the Segment.io
|
|
5
|
+
* specification. These types ensure type-safe event tracking across all analytics
|
|
6
|
+
* providers.
|
|
7
|
+
*
|
|
8
|
+
* **Core Types**:
|
|
9
|
+
* - `EmitterContext`: Contextual information about the environment
|
|
10
|
+
* - `EmitterOptions`: Options that can be passed to any analytics method
|
|
11
|
+
* - `EmitterPayload`: Union type for all event payloads
|
|
12
|
+
* - `EmitterConfig`: Configuration for analytics emitters
|
|
13
|
+
* - `AnalyticsEmitter`: Interface that all analytics providers should implement
|
|
14
|
+
*
|
|
15
|
+
* **Payload Types**:
|
|
16
|
+
* - `EmitterIdentifyPayload`: Identify user events
|
|
17
|
+
* - `EmitterTrackPayload`: Custom event tracking
|
|
18
|
+
* - `EmitterPagePayload`: Page view tracking
|
|
19
|
+
* - `EmitterScreenPayload`: Screen view tracking (mobile)
|
|
20
|
+
* - `EmitterGroupPayload`: Group association events
|
|
21
|
+
* - `EmitterAliasPayload`: User ID aliasing events
|
|
22
|
+
*
|
|
23
|
+
* **Reference**: https://segment.com/docs/connections/spec/common/
|
|
24
|
+
*
|
|
25
|
+
* @module @od-oneapp/analytics/shared/emitters/emitter-types
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { GroupTraits, Properties, PropertyValue, UserTraits } from '../types/base-types';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Common context object that provides additional information about the environment.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Context is automatically collected and attached to all events. You can also
|
|
35
|
+
* manually provide context when creating events. This ensures consistent
|
|
36
|
+
* metadata across all analytics events.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const context: EmitterContext = {
|
|
41
|
+
* app: { name: 'MyApp', version: '1.0.0' },
|
|
42
|
+
* page: { path: '/dashboard', title: 'Dashboard' },
|
|
43
|
+
* campaign: { source: 'google', medium: 'cpc' }
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export interface EmitterContext {
|
|
48
|
+
/**
|
|
49
|
+
* Whether a user is active (usually used to flag an identify call to just update traits).
|
|
50
|
+
*/
|
|
51
|
+
active?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Dictionary of information about the current application.
|
|
55
|
+
*/
|
|
56
|
+
app?: {
|
|
57
|
+
/** Application name */
|
|
58
|
+
name?: string;
|
|
59
|
+
/** Application version */
|
|
60
|
+
version?: string;
|
|
61
|
+
/** Build number or identifier */
|
|
62
|
+
build?: string;
|
|
63
|
+
/** Application namespace */
|
|
64
|
+
namespace?: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Dictionary of information about the campaign that resulted in the API call.
|
|
69
|
+
* Includes UTM parameters and other campaign metadata.
|
|
70
|
+
*/
|
|
71
|
+
campaign?: {
|
|
72
|
+
/** Campaign name */
|
|
73
|
+
name?: string;
|
|
74
|
+
/** Campaign source (e.g., 'google', 'facebook') */
|
|
75
|
+
source?: string;
|
|
76
|
+
/** Campaign medium (e.g., 'cpc', 'email') */
|
|
77
|
+
medium?: string;
|
|
78
|
+
/** Campaign term (for paid search) */
|
|
79
|
+
term?: string;
|
|
80
|
+
/** Campaign content (for A/B testing) */
|
|
81
|
+
content?: string;
|
|
82
|
+
/** Any other custom UTM parameters */
|
|
83
|
+
[key: string]: string | undefined;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Dictionary of information about the device.
|
|
88
|
+
*/
|
|
89
|
+
device?: {
|
|
90
|
+
/** Device identifier */
|
|
91
|
+
id?: string;
|
|
92
|
+
/** Advertising ID (mobile) */
|
|
93
|
+
advertisingId?: string;
|
|
94
|
+
/** Whether ad tracking is enabled */
|
|
95
|
+
adTrackingEnabled?: boolean;
|
|
96
|
+
/** Device manufacturer */
|
|
97
|
+
manufacturer?: string;
|
|
98
|
+
/** Device model */
|
|
99
|
+
model?: string;
|
|
100
|
+
/** Device name */
|
|
101
|
+
name?: string;
|
|
102
|
+
/** Device type (e.g., 'mobile', 'desktop') */
|
|
103
|
+
type?: string;
|
|
104
|
+
/** Device version */
|
|
105
|
+
version?: string;
|
|
106
|
+
/** Push notification token */
|
|
107
|
+
token?: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Current user's IP address.
|
|
112
|
+
*/
|
|
113
|
+
ip?: string;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Dictionary of information about the library making the requests.
|
|
117
|
+
*/
|
|
118
|
+
library?: {
|
|
119
|
+
/** Library name */
|
|
120
|
+
name: string;
|
|
121
|
+
/** Library version */
|
|
122
|
+
version: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Locale string for the current user (e.g., 'en-US').
|
|
127
|
+
*/
|
|
128
|
+
locale?: string;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Dictionary of information about the current network connection.
|
|
132
|
+
*/
|
|
133
|
+
network?: {
|
|
134
|
+
/** Whether Bluetooth is enabled */
|
|
135
|
+
bluetooth?: boolean;
|
|
136
|
+
/** Network carrier name */
|
|
137
|
+
carrier?: string;
|
|
138
|
+
/** Whether using cellular connection */
|
|
139
|
+
cellular?: boolean;
|
|
140
|
+
/** Whether using WiFi connection */
|
|
141
|
+
wifi?: boolean;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Dictionary of information about the operating system.
|
|
146
|
+
*/
|
|
147
|
+
os?: {
|
|
148
|
+
/** OS name (e.g., 'iOS', 'Android', 'Windows') */
|
|
149
|
+
name?: string;
|
|
150
|
+
/** OS version */
|
|
151
|
+
version?: string;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Dictionary of information about the current page in the browser.
|
|
156
|
+
*/
|
|
157
|
+
page?: {
|
|
158
|
+
/** Page path */
|
|
159
|
+
path?: string;
|
|
160
|
+
/** Referrer URL */
|
|
161
|
+
referrer?: string;
|
|
162
|
+
/** Query string */
|
|
163
|
+
search?: string;
|
|
164
|
+
/** Page title */
|
|
165
|
+
title?: string;
|
|
166
|
+
/** Full page URL */
|
|
167
|
+
url?: string;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Dictionary of information about the way the user was referred.
|
|
172
|
+
*/
|
|
173
|
+
referrer?: {
|
|
174
|
+
/** Referrer ID */
|
|
175
|
+
id?: string;
|
|
176
|
+
/** Referrer type */
|
|
177
|
+
type?: string;
|
|
178
|
+
/** Referrer name */
|
|
179
|
+
name?: string;
|
|
180
|
+
/** Referrer URL */
|
|
181
|
+
url?: string;
|
|
182
|
+
/** Referrer link */
|
|
183
|
+
link?: string;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Dictionary of information about the device's screen.
|
|
188
|
+
*/
|
|
189
|
+
screen?: {
|
|
190
|
+
/** Screen density (DPI) */
|
|
191
|
+
density?: number;
|
|
192
|
+
/** Screen height in pixels */
|
|
193
|
+
height?: number;
|
|
194
|
+
/** Screen width in pixels */
|
|
195
|
+
width?: number;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Timezone as tzdata string (e.g., 'America/New_York').
|
|
200
|
+
*/
|
|
201
|
+
timezone?: string;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Group/Account ID (useful in B2B use cases).
|
|
205
|
+
*/
|
|
206
|
+
groupId?: string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Dictionary of traits of the current user.
|
|
210
|
+
*/
|
|
211
|
+
traits?: UserTraits;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* User agent of the device making the request.
|
|
215
|
+
*/
|
|
216
|
+
userAgent?: string;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* User agent data from Client Hints API.
|
|
220
|
+
*/
|
|
221
|
+
userAgentData?: {
|
|
222
|
+
/** Browser brands */
|
|
223
|
+
brands?: {
|
|
224
|
+
brand: string;
|
|
225
|
+
version: string;
|
|
226
|
+
}[];
|
|
227
|
+
/** Whether device is mobile */
|
|
228
|
+
mobile?: boolean;
|
|
229
|
+
/** Platform name */
|
|
230
|
+
platform?: string;
|
|
231
|
+
/** Architecture bitness */
|
|
232
|
+
bitness?: string;
|
|
233
|
+
/** Device model */
|
|
234
|
+
model?: string;
|
|
235
|
+
/** Platform version */
|
|
236
|
+
platformVersion?: string;
|
|
237
|
+
/** Full user agent version */
|
|
238
|
+
uaFullVersion?: string;
|
|
239
|
+
/** Full version list */
|
|
240
|
+
fullVersionList?: {
|
|
241
|
+
brand: string;
|
|
242
|
+
version: string;
|
|
243
|
+
}[];
|
|
244
|
+
/** Whether running in WOW64 mode */
|
|
245
|
+
wow64?: boolean;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Where the request originated from: 'server', 'browser', or 'mobile'.
|
|
250
|
+
*/
|
|
251
|
+
channel?: string;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Location context (less commonly used).
|
|
255
|
+
*/
|
|
256
|
+
location?: {
|
|
257
|
+
/** City name */
|
|
258
|
+
city?: string;
|
|
259
|
+
/** Country code */
|
|
260
|
+
country?: string;
|
|
261
|
+
/** Latitude */
|
|
262
|
+
latitude?: number;
|
|
263
|
+
/** Longitude */
|
|
264
|
+
longitude?: number;
|
|
265
|
+
/** Region/state */
|
|
266
|
+
region?: string;
|
|
267
|
+
/** Movement speed */
|
|
268
|
+
speed?: number;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Allow additional custom properties.
|
|
273
|
+
*/
|
|
274
|
+
[key: string]: unknown;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Integration configuration value.
|
|
279
|
+
*
|
|
280
|
+
* @remarks
|
|
281
|
+
* Can be a boolean to enable/disable, or an object with specific settings
|
|
282
|
+
* for the integration.
|
|
283
|
+
*/
|
|
284
|
+
export type IntegrationConfig = boolean | Record<string, PropertyValue | PropertyValue[]>;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Options that can be passed to any analytics method.
|
|
288
|
+
*
|
|
289
|
+
* @remarks
|
|
290
|
+
* These options allow you to customize event behavior, including context,
|
|
291
|
+
* integrations, timestamps, and callbacks.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* const options: EmitterOptions = {
|
|
296
|
+
* anonymousId: 'anon-123',
|
|
297
|
+
* context: { page: { path: '/dashboard' } },
|
|
298
|
+
* integrations: { All: true, Mixpanel: false },
|
|
299
|
+
* timestamp: new Date()
|
|
300
|
+
* };
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
export interface EmitterOptions {
|
|
304
|
+
/**
|
|
305
|
+
* Anonymous ID if user is not identified.
|
|
306
|
+
*/
|
|
307
|
+
anonymousId?: string;
|
|
308
|
+
/**
|
|
309
|
+
* Callback function (client-side only).
|
|
310
|
+
* Called after the event is sent.
|
|
311
|
+
*/
|
|
312
|
+
callback?: (...args: unknown[]) => void;
|
|
313
|
+
/**
|
|
314
|
+
* Context information to attach to the event.
|
|
315
|
+
*/
|
|
316
|
+
context?: EmitterContext;
|
|
317
|
+
/**
|
|
318
|
+
* Integration specific options.
|
|
319
|
+
* Controls which destinations receive the event.
|
|
320
|
+
*/
|
|
321
|
+
integrations?: Record<string, IntegrationConfig>;
|
|
322
|
+
/**
|
|
323
|
+
* Timestamp when the event occurred.
|
|
324
|
+
* Defaults to current time if not provided.
|
|
325
|
+
*/
|
|
326
|
+
timestamp?: Date | string;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Integrations configuration (destination control).
|
|
331
|
+
*
|
|
332
|
+
* @remarks
|
|
333
|
+
* Controls which analytics destinations receive events. Use `All: false` to
|
|
334
|
+
* disable all destinations by default, then enable specific ones.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const integrations: EmitterIntegrations = {
|
|
339
|
+
* All: false,
|
|
340
|
+
* Mixpanel: true,
|
|
341
|
+
* GoogleAnalytics: { customOption: 'value' }
|
|
342
|
+
* };
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
export interface EmitterIntegrations {
|
|
346
|
+
/**
|
|
347
|
+
* Individual destination settings.
|
|
348
|
+
*/
|
|
349
|
+
[destination: string]: IntegrationConfig | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* Special key that applies when no specific destination key is found.
|
|
352
|
+
*/
|
|
353
|
+
All?: boolean;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Base payload that all events extend from (Common Fields).
|
|
358
|
+
*
|
|
359
|
+
* @remarks
|
|
360
|
+
* All analytics events share these common fields. Specific event types
|
|
361
|
+
* extend this interface with their own fields.
|
|
362
|
+
*/
|
|
363
|
+
export interface EmitterBasePayload {
|
|
364
|
+
/**
|
|
365
|
+
* Type of message, corresponding to the API method.
|
|
366
|
+
*/
|
|
367
|
+
type: 'identify' | 'track' | 'page' | 'screen' | 'group' | 'alias';
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Anonymous ID if user is not identified.
|
|
371
|
+
*/
|
|
372
|
+
anonymousId?: string;
|
|
373
|
+
/**
|
|
374
|
+
* User ID (at least one of userId or anonymousId required).
|
|
375
|
+
*/
|
|
376
|
+
userId?: string;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Original timestamp when the event occurred (before any processing).
|
|
380
|
+
*/
|
|
381
|
+
originalTimestamp?: Date | string;
|
|
382
|
+
/**
|
|
383
|
+
* Timestamp when the event was received by the server.
|
|
384
|
+
*/
|
|
385
|
+
receivedAt?: Date | string;
|
|
386
|
+
/**
|
|
387
|
+
* Timestamp when the event was sent to destinations.
|
|
388
|
+
*/
|
|
389
|
+
sentAt?: Date | string;
|
|
390
|
+
/**
|
|
391
|
+
* Timestamp when the event occurred.
|
|
392
|
+
*/
|
|
393
|
+
timestamp?: Date | string;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Context and control fields.
|
|
397
|
+
*/
|
|
398
|
+
context?: EmitterContext;
|
|
399
|
+
/**
|
|
400
|
+
* Integration-specific options.
|
|
401
|
+
*/
|
|
402
|
+
integrations?: EmitterIntegrations;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* System fields (set by Segment or analytics providers).
|
|
406
|
+
*/
|
|
407
|
+
messageId?: string;
|
|
408
|
+
/**
|
|
409
|
+
* Protocol version.
|
|
410
|
+
*/
|
|
411
|
+
version?: number;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Payload for identify events.
|
|
416
|
+
*
|
|
417
|
+
* @remarks
|
|
418
|
+
* Ties a user to their actions and records traits about them.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* const payload: EmitterIdentifyPayload = {
|
|
423
|
+
* type: 'identify',
|
|
424
|
+
* userId: 'user-123',
|
|
425
|
+
* traits: { email: 'user@example.com', name: 'John Doe' }
|
|
426
|
+
* };
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
export interface EmitterIdentifyPayload extends EmitterBasePayload {
|
|
430
|
+
/**
|
|
431
|
+
* Free-form dictionary of traits about the user.
|
|
432
|
+
*/
|
|
433
|
+
traits?: UserTraits;
|
|
434
|
+
type: 'identify';
|
|
435
|
+
userId: string;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Payload for track events.
|
|
440
|
+
*
|
|
441
|
+
* @remarks
|
|
442
|
+
* Records any actions your users perform, along with properties that describe the action.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const payload: EmitterTrackPayload = {
|
|
447
|
+
* type: 'track',
|
|
448
|
+
* event: 'Button Clicked',
|
|
449
|
+
* properties: { buttonName: 'Sign Up', location: 'header' }
|
|
450
|
+
* };
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
export interface EmitterTrackPayload extends EmitterBasePayload {
|
|
454
|
+
/**
|
|
455
|
+
* Name of the action that a user has performed.
|
|
456
|
+
*/
|
|
457
|
+
event: string;
|
|
458
|
+
/**
|
|
459
|
+
* Free-form dictionary of properties of the event.
|
|
460
|
+
*/
|
|
461
|
+
properties?: Properties;
|
|
462
|
+
type: 'track';
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Payload for page events.
|
|
467
|
+
*
|
|
468
|
+
* @remarks
|
|
469
|
+
* Records whenever a user views a page of your website.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* const payload: EmitterPagePayload = {
|
|
474
|
+
* type: 'page',
|
|
475
|
+
* name: 'Dashboard',
|
|
476
|
+
* properties: { path: '/dashboard', title: 'Dashboard' }
|
|
477
|
+
* };
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
export interface EmitterPagePayload extends EmitterBasePayload {
|
|
481
|
+
/**
|
|
482
|
+
* Category of the page (optional).
|
|
483
|
+
*/
|
|
484
|
+
category?: string;
|
|
485
|
+
/**
|
|
486
|
+
* Name of the page.
|
|
487
|
+
*/
|
|
488
|
+
name?: string;
|
|
489
|
+
/**
|
|
490
|
+
* Free-form dictionary of properties of the page.
|
|
491
|
+
*/
|
|
492
|
+
properties?: Properties;
|
|
493
|
+
type: 'page';
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Payload for screen events.
|
|
498
|
+
*
|
|
499
|
+
* @remarks
|
|
500
|
+
* Records whenever a user views a screen in your mobile app.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const payload: EmitterScreenPayload = {
|
|
505
|
+
* type: 'screen',
|
|
506
|
+
* name: 'Home',
|
|
507
|
+
* properties: { screenClass: 'HomeScreen' }
|
|
508
|
+
* };
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
export interface EmitterScreenPayload extends EmitterBasePayload {
|
|
512
|
+
/**
|
|
513
|
+
* Name of the screen.
|
|
514
|
+
*/
|
|
515
|
+
name?: string;
|
|
516
|
+
/**
|
|
517
|
+
* Free-form dictionary of properties of the screen.
|
|
518
|
+
*/
|
|
519
|
+
properties?: Properties;
|
|
520
|
+
type: 'screen';
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Payload for group events.
|
|
525
|
+
*
|
|
526
|
+
* @remarks
|
|
527
|
+
* Associates an identified user with a group.
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* const payload: EmitterGroupPayload = {
|
|
532
|
+
* type: 'group',
|
|
533
|
+
* groupId: 'org-456',
|
|
534
|
+
* traits: { name: 'Acme Corp', industry: 'Technology' }
|
|
535
|
+
* };
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
export interface EmitterGroupPayload extends EmitterBasePayload {
|
|
539
|
+
/**
|
|
540
|
+
* Unique identifier for the group.
|
|
541
|
+
*/
|
|
542
|
+
groupId: string;
|
|
543
|
+
/**
|
|
544
|
+
* Free-form dictionary of traits about the group.
|
|
545
|
+
*/
|
|
546
|
+
traits?: GroupTraits;
|
|
547
|
+
type: 'group';
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Payload for alias events.
|
|
552
|
+
*
|
|
553
|
+
* @remarks
|
|
554
|
+
* Associates one identity with another. Useful when a user signs up or logs in.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```typescript
|
|
558
|
+
* const payload: EmitterAliasPayload = {
|
|
559
|
+
* type: 'alias',
|
|
560
|
+
* userId: 'user-123',
|
|
561
|
+
* previousId: 'anon-456'
|
|
562
|
+
* };
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
export interface EmitterAliasPayload extends EmitterBasePayload {
|
|
566
|
+
/**
|
|
567
|
+
* The previous ID of the user (usually the anonymousId).
|
|
568
|
+
*/
|
|
569
|
+
previousId: string;
|
|
570
|
+
type: 'alias';
|
|
571
|
+
userId: string;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Union type for all possible payloads.
|
|
576
|
+
*
|
|
577
|
+
* @remarks
|
|
578
|
+
* Use this type when you need to handle any analytics event payload.
|
|
579
|
+
*/
|
|
580
|
+
export type EmitterPayload =
|
|
581
|
+
| EmitterIdentifyPayload
|
|
582
|
+
| EmitterTrackPayload
|
|
583
|
+
| EmitterPagePayload
|
|
584
|
+
| EmitterScreenPayload
|
|
585
|
+
| EmitterGroupPayload
|
|
586
|
+
| EmitterAliasPayload;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Common traits that are recognized by many analytics destinations.
|
|
590
|
+
*
|
|
591
|
+
* @remarks
|
|
592
|
+
* These traits are commonly used across analytics platforms. You can also
|
|
593
|
+
* include custom traits as needed.
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```typescript
|
|
597
|
+
* const traits: EmitterUserTraits = {
|
|
598
|
+
* email: 'user@example.com',
|
|
599
|
+
* name: 'John Doe',
|
|
600
|
+
* company: { name: 'Acme Corp', industry: 'Technology' }
|
|
601
|
+
* };
|
|
602
|
+
* ```
|
|
603
|
+
*/
|
|
604
|
+
export interface EmitterUserTraits {
|
|
605
|
+
/** User's email address */
|
|
606
|
+
email?: string;
|
|
607
|
+
/** User's first name */
|
|
608
|
+
firstName?: string;
|
|
609
|
+
/** User's last name */
|
|
610
|
+
lastName?: string;
|
|
611
|
+
/** User's full name */
|
|
612
|
+
name?: string;
|
|
613
|
+
/** User's phone number */
|
|
614
|
+
phone?: string;
|
|
615
|
+
/** User's username */
|
|
616
|
+
username?: string;
|
|
617
|
+
|
|
618
|
+
/** User's age */
|
|
619
|
+
age?: number;
|
|
620
|
+
/** User's birthday */
|
|
621
|
+
birthday?: Date | string;
|
|
622
|
+
/** User's gender */
|
|
623
|
+
gender?: string;
|
|
624
|
+
|
|
625
|
+
/** User's address */
|
|
626
|
+
address?: {
|
|
627
|
+
/** Street address */
|
|
628
|
+
street?: string;
|
|
629
|
+
/** City */
|
|
630
|
+
city?: string;
|
|
631
|
+
/** State or province */
|
|
632
|
+
state?: string;
|
|
633
|
+
/** Postal or ZIP code */
|
|
634
|
+
postalCode?: string;
|
|
635
|
+
/** Country */
|
|
636
|
+
country?: string;
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
/** User's company information */
|
|
640
|
+
company?: {
|
|
641
|
+
/** Company name */
|
|
642
|
+
name?: string;
|
|
643
|
+
/** Company ID */
|
|
644
|
+
id?: string;
|
|
645
|
+
/** Industry */
|
|
646
|
+
industry?: string;
|
|
647
|
+
/** Number of employees */
|
|
648
|
+
employee_count?: number;
|
|
649
|
+
/** Company plan */
|
|
650
|
+
plan?: string;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
/** User's avatar URL */
|
|
654
|
+
avatar?: string;
|
|
655
|
+
/** When the user was created */
|
|
656
|
+
createdAt?: Date | string;
|
|
657
|
+
/** User description */
|
|
658
|
+
description?: string;
|
|
659
|
+
/** User ID */
|
|
660
|
+
id?: string;
|
|
661
|
+
/** User's website */
|
|
662
|
+
website?: string;
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Custom traits (strongly typed).
|
|
666
|
+
* Can include any additional properties as needed.
|
|
667
|
+
*/
|
|
668
|
+
[key: string]:
|
|
669
|
+
| PropertyValue
|
|
670
|
+
| PropertyValue[]
|
|
671
|
+
| EmitterUserTraits['address']
|
|
672
|
+
| EmitterUserTraits['company']
|
|
673
|
+
| undefined;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Product information in an ecommerce event.
|
|
678
|
+
*
|
|
679
|
+
* @remarks
|
|
680
|
+
* Used in e-commerce tracking events like "Product Viewed", "Product Added",
|
|
681
|
+
* "Order Completed", etc.
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```typescript
|
|
685
|
+
* const product: EmitterProduct = {
|
|
686
|
+
* id: 'prod-123',
|
|
687
|
+
* name: 'Widget',
|
|
688
|
+
* price: 29.99,
|
|
689
|
+
* quantity: 2,
|
|
690
|
+
* category: 'Electronics',
|
|
691
|
+
* brand: 'Acme'
|
|
692
|
+
* };
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
export interface EmitterProduct {
|
|
696
|
+
/** Product ID */
|
|
697
|
+
id?: string;
|
|
698
|
+
/** Product name */
|
|
699
|
+
name?: string;
|
|
700
|
+
/** Product price */
|
|
701
|
+
price?: number;
|
|
702
|
+
/** Product quantity */
|
|
703
|
+
quantity?: number;
|
|
704
|
+
/** Product category */
|
|
705
|
+
category?: string;
|
|
706
|
+
/** Product brand */
|
|
707
|
+
brand?: string;
|
|
708
|
+
/** Product variant */
|
|
709
|
+
variant?: string;
|
|
710
|
+
/**
|
|
711
|
+
* Custom product properties.
|
|
712
|
+
* Can include any additional properties as needed.
|
|
713
|
+
*/
|
|
714
|
+
[key: string]: PropertyValue | PropertyValue[] | undefined;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Common properties for track events.
|
|
719
|
+
*
|
|
720
|
+
* @remarks
|
|
721
|
+
* These properties are commonly used across analytics platforms for
|
|
722
|
+
* e-commerce, content, and search tracking.
|
|
723
|
+
*
|
|
724
|
+
* @example
|
|
725
|
+
* ```typescript
|
|
726
|
+
* const properties: EmitterEventProperties = {
|
|
727
|
+
* revenue: 29.99,
|
|
728
|
+
* currency: 'USD',
|
|
729
|
+
* products: [{ id: 'prod-123', name: 'Widget', price: 29.99 }]
|
|
730
|
+
* };
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
export interface EmitterEventProperties {
|
|
734
|
+
/** Currency code (e.g., 'USD', 'EUR') */
|
|
735
|
+
currency?: string;
|
|
736
|
+
/** Revenue amount */
|
|
737
|
+
revenue?: number;
|
|
738
|
+
/** Event value */
|
|
739
|
+
value?: number;
|
|
740
|
+
|
|
741
|
+
/** Array of products (for e-commerce events) */
|
|
742
|
+
products?: EmitterProduct[];
|
|
743
|
+
|
|
744
|
+
/** Event category */
|
|
745
|
+
category?: string;
|
|
746
|
+
/** Event description */
|
|
747
|
+
description?: string;
|
|
748
|
+
/** Event title */
|
|
749
|
+
title?: string;
|
|
750
|
+
|
|
751
|
+
/** Search query */
|
|
752
|
+
query?: string;
|
|
753
|
+
|
|
754
|
+
/** Recipient (for sharing events) */
|
|
755
|
+
recipient?: string;
|
|
756
|
+
/** Share method (for sharing events) */
|
|
757
|
+
share_via?: string;
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Custom properties (strongly typed).
|
|
761
|
+
* Can include any additional properties as needed.
|
|
762
|
+
*/
|
|
763
|
+
[key: string]: PropertyValue | PropertyValue[] | EmitterProduct[] | undefined;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Common group traits.
|
|
768
|
+
*
|
|
769
|
+
* @remarks
|
|
770
|
+
* These traits are commonly used when associating users with groups or organizations.
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* ```typescript
|
|
774
|
+
* const traits: EmitterGroupTraits = {
|
|
775
|
+
* name: 'Acme Corp',
|
|
776
|
+
* industry: 'Technology',
|
|
777
|
+
* employees: 100,
|
|
778
|
+
* plan: 'enterprise'
|
|
779
|
+
* };
|
|
780
|
+
* ```
|
|
781
|
+
*/
|
|
782
|
+
export interface EmitterGroupTraits {
|
|
783
|
+
/** Group avatar URL */
|
|
784
|
+
avatar?: string;
|
|
785
|
+
/** When the group was created */
|
|
786
|
+
createdAt?: Date | string;
|
|
787
|
+
/** Group description */
|
|
788
|
+
description?: string;
|
|
789
|
+
/** Number of employees */
|
|
790
|
+
employees?: number;
|
|
791
|
+
/** Industry */
|
|
792
|
+
industry?: string;
|
|
793
|
+
/** Group name */
|
|
794
|
+
name?: string;
|
|
795
|
+
/** Group plan */
|
|
796
|
+
plan?: string;
|
|
797
|
+
/** Group website */
|
|
798
|
+
website?: string;
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Custom traits (strongly typed).
|
|
802
|
+
* Can include any additional properties as needed.
|
|
803
|
+
*/
|
|
804
|
+
[key: string]: PropertyValue | PropertyValue[] | undefined;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Emitter interface that all analytics providers should implement.
|
|
809
|
+
*
|
|
810
|
+
* @remarks
|
|
811
|
+
* This interface defines the contract for analytics providers. All providers
|
|
812
|
+
* must implement these methods to ensure consistent behavior across the
|
|
813
|
+
* analytics system.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```typescript
|
|
817
|
+
* class MyProvider implements AnalyticsEmitter {
|
|
818
|
+
* async track(event: string, properties?: Properties, options?: EmitterOptions) {
|
|
819
|
+
* // Send event to analytics service
|
|
820
|
+
* }
|
|
821
|
+
* // ... implement other methods
|
|
822
|
+
* }
|
|
823
|
+
* ```
|
|
824
|
+
*/
|
|
825
|
+
export interface AnalyticsEmitter {
|
|
826
|
+
/**
|
|
827
|
+
* Alias one identity with another.
|
|
828
|
+
*
|
|
829
|
+
* @param userId - The new user ID
|
|
830
|
+
* @param previousId - The previous user ID (usually anonymousId)
|
|
831
|
+
* @param options - Optional event options
|
|
832
|
+
* @param callback - Optional callback (client-side only)
|
|
833
|
+
*/
|
|
834
|
+
alias(
|
|
835
|
+
userId: string,
|
|
836
|
+
previousId?: string,
|
|
837
|
+
options?: EmitterOptions,
|
|
838
|
+
callback?: (...args: unknown[]) => void,
|
|
839
|
+
): void | Promise<void>;
|
|
840
|
+
/**
|
|
841
|
+
* Associate an identified user with a group.
|
|
842
|
+
*
|
|
843
|
+
* @param groupId - Unique identifier for the group
|
|
844
|
+
* @param traits - Free-form dictionary of traits about the group
|
|
845
|
+
* @param options - Optional event options
|
|
846
|
+
* @param callback - Optional callback (client-side only)
|
|
847
|
+
*/
|
|
848
|
+
group(
|
|
849
|
+
groupId: string,
|
|
850
|
+
traits?: GroupTraits,
|
|
851
|
+
options?: EmitterOptions,
|
|
852
|
+
callback?: (...args: unknown[]) => void,
|
|
853
|
+
): void | Promise<void>;
|
|
854
|
+
/**
|
|
855
|
+
* Identify a user and record traits about them.
|
|
856
|
+
*
|
|
857
|
+
* @param userId - Unique identifier for the user
|
|
858
|
+
* @param traits - Free-form dictionary of traits about the user
|
|
859
|
+
* @param options - Optional event options
|
|
860
|
+
* @param callback - Optional callback (client-side only)
|
|
861
|
+
*/
|
|
862
|
+
identify(
|
|
863
|
+
userId: string,
|
|
864
|
+
traits?: UserTraits,
|
|
865
|
+
options?: EmitterOptions,
|
|
866
|
+
callback?: (...args: unknown[]) => void,
|
|
867
|
+
): void | Promise<void>;
|
|
868
|
+
/**
|
|
869
|
+
* Record a page view.
|
|
870
|
+
*
|
|
871
|
+
* @param category - Category of the page (optional)
|
|
872
|
+
* @param name - Name of the page (optional)
|
|
873
|
+
* @param properties - Free-form dictionary of properties of the page
|
|
874
|
+
* @param options - Optional event options
|
|
875
|
+
* @param callback - Optional callback (client-side only)
|
|
876
|
+
*/
|
|
877
|
+
page(
|
|
878
|
+
category?: string,
|
|
879
|
+
name?: string,
|
|
880
|
+
properties?: Properties,
|
|
881
|
+
options?: EmitterOptions,
|
|
882
|
+
callback?: (...args: unknown[]) => void,
|
|
883
|
+
): void | Promise<void>;
|
|
884
|
+
/**
|
|
885
|
+
* Record a screen view (mobile apps).
|
|
886
|
+
*
|
|
887
|
+
* @param name - Name of the screen
|
|
888
|
+
* @param properties - Free-form dictionary of properties of the screen
|
|
889
|
+
* @param options - Optional event options
|
|
890
|
+
* @param callback - Optional callback (client-side only)
|
|
891
|
+
*/
|
|
892
|
+
screen(
|
|
893
|
+
name?: string,
|
|
894
|
+
properties?: Properties,
|
|
895
|
+
options?: EmitterOptions,
|
|
896
|
+
callback?: (...args: unknown[]) => void,
|
|
897
|
+
): void | Promise<void>;
|
|
898
|
+
/**
|
|
899
|
+
* Record an action a user performed.
|
|
900
|
+
*
|
|
901
|
+
* @param event - Name of the action
|
|
902
|
+
* @param properties - Free-form dictionary of properties of the event
|
|
903
|
+
* @param options - Optional event options
|
|
904
|
+
* @param callback - Optional callback (client-side only)
|
|
905
|
+
*/
|
|
906
|
+
track(
|
|
907
|
+
event: string,
|
|
908
|
+
properties?: Properties,
|
|
909
|
+
options?: EmitterOptions,
|
|
910
|
+
callback?: (...args: unknown[]) => void,
|
|
911
|
+
): void | Promise<void>;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Configuration for analytics emitters.
|
|
916
|
+
*
|
|
917
|
+
* @remarks
|
|
918
|
+
* This configuration object allows you to customize emitter behavior,
|
|
919
|
+
* including batching, debugging, and default context.
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```typescript
|
|
923
|
+
* const config: EmitterConfig = {
|
|
924
|
+
* apiKey: 'your-api-key',
|
|
925
|
+
* batching: true,
|
|
926
|
+
* batchSize: 20,
|
|
927
|
+
* flushInterval: 5000,
|
|
928
|
+
* debug: true,
|
|
929
|
+
* defaultContext: { app: { name: 'MyApp' } }
|
|
930
|
+
* };
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
933
|
+
export interface EmitterConfig {
|
|
934
|
+
/**
|
|
935
|
+
* API key or write key for the analytics service.
|
|
936
|
+
*/
|
|
937
|
+
apiKey?: string;
|
|
938
|
+
/**
|
|
939
|
+
* Whether to batch events before sending.
|
|
940
|
+
*/
|
|
941
|
+
batching?: boolean;
|
|
942
|
+
/**
|
|
943
|
+
* Maximum number of events to batch before flushing.
|
|
944
|
+
*/
|
|
945
|
+
batchSize?: number;
|
|
946
|
+
/**
|
|
947
|
+
* Whether to enable debug logging.
|
|
948
|
+
*/
|
|
949
|
+
debug?: boolean;
|
|
950
|
+
/**
|
|
951
|
+
* Default context to include with all events.
|
|
952
|
+
*/
|
|
953
|
+
defaultContext?: Partial<EmitterContext>;
|
|
954
|
+
/**
|
|
955
|
+
* Custom endpoint for sending events.
|
|
956
|
+
*/
|
|
957
|
+
endpoint?: string;
|
|
958
|
+
/**
|
|
959
|
+
* Time to wait before flushing batch (milliseconds).
|
|
960
|
+
*/
|
|
961
|
+
flushInterval?: number;
|
|
962
|
+
/**
|
|
963
|
+
* Default integrations settings.
|
|
964
|
+
*/
|
|
965
|
+
integrations?: Record<string, IntegrationConfig>;
|
|
966
|
+
/**
|
|
967
|
+
* Whether to track clicks automatically.
|
|
968
|
+
*/
|
|
969
|
+
trackClicks?: boolean;
|
|
970
|
+
/**
|
|
971
|
+
* Whether to track page views automatically.
|
|
972
|
+
*/
|
|
973
|
+
trackPages?: boolean;
|
|
974
|
+
}
|