mixpanel-browser 2.73.0 → 2.75.0

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 (55) hide show
  1. package/.eslintrc.json +7 -4
  2. package/.github/workflows/integration-tests.yml +52 -0
  3. package/.github/workflows/unit-tests.yml +40 -0
  4. package/CHANGELOG.md +12 -0
  5. package/README.md +3 -3
  6. package/build.sh +1 -5
  7. package/dist/mixpanel-core.cjs.d.ts +12 -1
  8. package/dist/mixpanel-core.cjs.js +432 -34
  9. package/dist/mixpanel-recorder.js +5364 -684
  10. package/dist/mixpanel-recorder.min.js +1 -1
  11. package/dist/mixpanel-recorder.min.js.map +1 -1
  12. package/dist/mixpanel-targeting.js +2576 -0
  13. package/dist/mixpanel-targeting.min.js +2 -0
  14. package/dist/mixpanel-targeting.min.js.map +1 -0
  15. package/dist/mixpanel-with-async-modules.cjs.d.ts +522 -0
  16. package/dist/mixpanel-with-async-modules.cjs.js +9700 -0
  17. package/dist/mixpanel-with-async-recorder.cjs.d.ts +12 -1
  18. package/dist/mixpanel-with-async-recorder.cjs.js +432 -34
  19. package/dist/mixpanel-with-recorder.d.ts +12 -1
  20. package/dist/mixpanel-with-recorder.js +7889 -2839
  21. package/dist/mixpanel-with-recorder.min.d.ts +12 -1
  22. package/dist/mixpanel-with-recorder.min.js +1 -1
  23. package/dist/mixpanel.amd.d.ts +12 -1
  24. package/dist/mixpanel.amd.js +8446 -2813
  25. package/dist/mixpanel.cjs.d.ts +12 -1
  26. package/dist/mixpanel.cjs.js +8446 -2813
  27. package/dist/mixpanel.globals.js +432 -34
  28. package/dist/mixpanel.min.js +182 -173
  29. package/dist/mixpanel.module.d.ts +12 -1
  30. package/dist/mixpanel.module.js +8446 -2813
  31. package/dist/mixpanel.umd.d.ts +12 -1
  32. package/dist/mixpanel.umd.js +8446 -2813
  33. package/dist/rrweb-bundled.js +4434 -596
  34. package/dist/rrweb-compiled.js +5078 -646
  35. package/package.json +33 -7
  36. package/rollup.config.mjs +286 -224
  37. package/src/autocapture/utils.js +15 -7
  38. package/src/config.js +1 -1
  39. package/src/flags/index.js +269 -8
  40. package/src/globals.js +14 -0
  41. package/src/index.d.ts +12 -1
  42. package/src/loaders/loader-module.js +1 -0
  43. package/src/mixpanel-core.js +101 -8
  44. package/src/recorder/index.js +2 -1
  45. package/src/recorder/masking.js +197 -0
  46. package/src/recorder/rrweb-entrypoint.js +2 -1
  47. package/src/recorder/session-recording.js +43 -4
  48. package/src/recorder/utils.js +5 -1
  49. package/src/targeting/event-matcher.js +97 -0
  50. package/src/targeting/index.js +11 -0
  51. package/src/targeting/loader.js +36 -0
  52. package/src/utils.js +12 -10
  53. package/testServer.js +51 -7
  54. package/.github/workflows/tests.yml +0 -25
  55. /package/src/loaders/{loader-module-with-async-recorder.js → loader-module-with-async-modules.js} +0 -0
@@ -0,0 +1,522 @@
1
+ export type Persistence = "cookie" | "localStorage";
2
+
3
+ export type ApiPayloadFormat = "base64" | "json";
4
+
5
+ export type PushItem = Array<string | Dict | ((this: Mixpanel) => void)>;
6
+
7
+ export type Query = string | Element | Element[];
8
+
9
+ export type RemoteSettingType = "disabled" | "fallback" | "strict";
10
+
11
+ export interface Dict {
12
+ [key: string]: any;
13
+ }
14
+
15
+ export interface RequestOptions {
16
+ transport?: "xhr" | "sendBeacon" | undefined;
17
+ send_immediately?: boolean | undefined;
18
+ }
19
+
20
+ export interface XhrHeadersDef {
21
+ [header: string]: any;
22
+ }
23
+
24
+ export interface HasOptedInOutOptions {
25
+ persistence_type: Persistence;
26
+ cookie_prefix: string;
27
+ }
28
+
29
+ export interface ClearOptOutInOutOptions extends HasOptedInOutOptions {
30
+ cookie_expiration: number;
31
+ cross_subdomain_cookie: boolean;
32
+ secure_cookie: boolean;
33
+ }
34
+
35
+ export interface InTrackingOptions extends ClearOptOutInOutOptions {
36
+ track: () => void;
37
+ track_event_name: string;
38
+ track_properties: Dict;
39
+ }
40
+
41
+ export interface OutTrackingOptions extends ClearOptOutInOutOptions {
42
+ delete_user: boolean;
43
+ }
44
+
45
+ export type RageClickConfig =
46
+ | boolean
47
+ | {
48
+ /** Distance threshold in pixels for clicks to be considered within the same area (default: 30) */
49
+ threshold_px?: number;
50
+ /** Time window in milliseconds for clicks to be considered rapid (default: 1000) */
51
+ timeout_ms?: number;
52
+ /** Number of clicks required to trigger a rage click event (default: 3) */
53
+ click_count?: number;
54
+ /** Whether to only track rage clicks on interactive elements like buttons, links, inputs (default: false) */
55
+ interactive_elements_only?: boolean;
56
+ };
57
+
58
+ export type DeadClickConfig =
59
+ | boolean
60
+ | {
61
+ /** Time in milliseconds to wait after a click before qualifying it as dead (default: 500) */
62
+ timeout_ms?: number;
63
+ };
64
+
65
+ export interface RegisterOptions {
66
+ persistent: boolean;
67
+ }
68
+
69
+ export type TrackPageView =
70
+ | boolean
71
+ | "url-with-path"
72
+ | "url-with-path-and-query-string"
73
+ | "full-url";
74
+
75
+ export interface AutocaptureConfig {
76
+ /**
77
+ * When set to `true`, Mixpanel will track element clicks. It will not track textContent unless `capture_text_content` is also set to `true`.
78
+ * @default true
79
+ */
80
+ click?: boolean;
81
+ /**
82
+ * When set to `true`, Mixpanel will track when an input is provided. It will not capture input content.
83
+ * @default true
84
+ */
85
+ input?: boolean;
86
+ /**
87
+ * When set, Mixpanel will collect pageviews when some components of the URL change — including UTM parameters.
88
+ * @default 'full-url'
89
+ */
90
+ pageview?: TrackPageView;
91
+ /**
92
+ * When set to `true`, Mixpanel will track rage clicks (multiple clicks in a short time on the same element).
93
+ * Can also be configured as an object to customize rage click detection parameters.
94
+ * @default true
95
+ */
96
+ rage_click?: RageClickConfig;
97
+ /**
98
+ * When set to `true`, Mixpanel will track dead clicks (clicks that produce no response).
99
+ * Can also be configured as an object to customize dead click detection parameters.
100
+ * @default true
101
+ */
102
+ dead_click?: DeadClickConfig;
103
+ /**
104
+ * When set, Mixpanel will collect page scrolls at specified scroll intervals.
105
+ * @default true
106
+ */
107
+ scroll?: boolean;
108
+ /**
109
+ * When set to `true`, Mixpanel will track form submissions (but not submission content).
110
+ * @default true
111
+ */
112
+ submit?: boolean;
113
+ /**
114
+ * When set to `true`, Mixpanel will capture the textContent of any element.
115
+ * @default false
116
+ */
117
+ capture_text_content?: boolean;
118
+ /** Enables specification of additional attributes to track. */
119
+ capture_extra_attrs?: string[];
120
+ /**
121
+ * Establishes the scroll depth intervals which trigger `Page Scroll` event.
122
+ * @default [25, 50, 75, 100]
123
+ */
124
+ scroll_depth_percent_checkpoints?: number[];
125
+ /**
126
+ * When set to true, overrides `scroll_depth_percentage_checkpoints` and captures all scroll events.
127
+ * @default false
128
+ */
129
+ scroll_capture_all?: boolean;
130
+ /** Opts out specific pages from Autocapture. */
131
+ block_url_regexes?: RegExp[];
132
+ /** Opts in specific pages to Autocapture. */
133
+ allow_url_regexes?: RegExp[];
134
+ /** Opts out specific classes from Autocapture. */
135
+ block_selectors?: string[];
136
+ /** Opts in specific classes to Autocapture. */
137
+ allow_selectors?: string[];
138
+ /** Opts out specific attributes from Autocapture. */
139
+ block_attrs?: string[];
140
+ /**
141
+ * A user-provided function that determines whether a specific element should be
142
+ * tracked via Autocapture or not. The function receives the element as its first
143
+ * argument, and the DOM event as its second argument, and should return `true` if
144
+ * the element should be tracked (otherwise the element will NOT be tracked).
145
+ */
146
+ allow_element_callback?: (element: Element, event: Event) => boolean;
147
+ /**
148
+ * A user-provided function that determines whether a specific element should be
149
+ * blocked from tracking via Autocapture or not. The function receives the element
150
+ * as its first argument, and the DOM event as its second argument, and should
151
+ * return `true` if the element should be blocked.
152
+ */
153
+ block_element_callback?: (element: Element, event: Event) => boolean;
154
+ }
155
+
156
+ export interface FlagsConfig {
157
+ context: Dict;
158
+ }
159
+
160
+ export interface BeforeSendHookPayload {
161
+ event: string;
162
+ properties: Record<string, any>;
163
+ }
164
+
165
+ export interface Config {
166
+ api_host: string;
167
+ api_routes: {
168
+ track?: string;
169
+ engage?: string;
170
+ groups?: string;
171
+ record?: string;
172
+ flags?: string;
173
+ };
174
+ api_method: string;
175
+ api_transport: string;
176
+ app_host: string;
177
+ api_payload_format: ApiPayloadFormat;
178
+ autotrack: boolean;
179
+ batch_autostart: boolean;
180
+ batch_requests: boolean;
181
+ cdn: string;
182
+ cookie_domain: string;
183
+ cross_site_cookie: boolean;
184
+ cross_subdomain_cookie: boolean;
185
+ error_reporter: (msg: string, err?: Error) => void;
186
+ flags: boolean | FlagsConfig;
187
+ persistence: Persistence;
188
+ persistence_name: string;
189
+ cookie_name: string;
190
+ loaded: (mixpanel: Mixpanel) => void;
191
+ store_google: boolean;
192
+ stop_utm_persistence: boolean;
193
+ save_referrer: boolean;
194
+ test: boolean;
195
+ verbose: boolean;
196
+ img: boolean;
197
+ /**
198
+ * @default false
199
+ * @see https://github.com/mixpanel/mixpanel-js/blob/master/doc/readme.io/javascript-full-api-reference.md#mixpanelset_config
200
+ */
201
+ debug: boolean;
202
+ track_links_timeout: number;
203
+ track_pageview: TrackPageView;
204
+ autocapture: boolean | AutocaptureConfig;
205
+ skip_first_touch_marketing: boolean;
206
+ cookie_expiration: number;
207
+ upgrade: boolean;
208
+ disable_persistence: boolean;
209
+ disable_cookie: boolean;
210
+ disable_notifications: boolean;
211
+ secure_cookie: boolean;
212
+ ip: boolean;
213
+ property_blacklist: string[];
214
+ xhr_headers: XhrHeadersDef;
215
+ opt_out_tracking_by_default: boolean;
216
+ opt_out_persistence_by_default: boolean;
217
+ opt_out_tracking_persistence_type: Persistence;
218
+ opt_out_tracking_cookie_prefix: string;
219
+ inapp_protocol: string;
220
+ inapp_link_new_window: boolean;
221
+ ignore_dnt: boolean;
222
+ batch_size: number;
223
+ batch_flush_interval_ms: number;
224
+ batch_request_timeout_ms: number;
225
+ recorder_src: string;
226
+ record_block_class: string | RegExp;
227
+ record_block_selector: string;
228
+ record_collect_fonts: boolean;
229
+ record_idle_timeout_ms: number;
230
+ record_inline_images: boolean;
231
+ record_mask_text_class: string | RegExp;
232
+ record_mask_text_selector: string | string[];
233
+ record_unmask_text_selector: string | string[];
234
+ record_mask_all_text: boolean;
235
+ record_mask_input_selector: string | string[];
236
+ record_unmask_input_selector: string | string[];
237
+ record_mask_all_inputs: boolean;
238
+ record_min_ms: number;
239
+ record_max_ms: number;
240
+ record_sessions_percent: number;
241
+ record_canvas: boolean;
242
+ record_heatmap_data: boolean;
243
+ remote_settings_mode: RemoteSettingType;
244
+ hooks: {
245
+ before_identify?: (new_distinct_id: string) => string | null;
246
+ before_register?: (
247
+ props: Dict,
248
+ days_or_options?: number | Partial<RegisterOptions>
249
+ ) => Dict | Array<Dict | number | Partial<RegisterOptions>> | null;
250
+ before_register_once?: (
251
+ props: Dict,
252
+ default_value?: any,
253
+ days_or_options?: number | Partial<RegisterOptions>
254
+ ) => Dict | Array<any | Dict | number | Partial<RegisterOptions>> | null;
255
+ before_send_events?: (
256
+ event: BeforeSendHookPayload
257
+ ) => BeforeSendHookPayload | null;
258
+ before_track?: (
259
+ event_name: string,
260
+ properties: Dict
261
+ ) => string | Array<string | Dict> | null;
262
+ before_unregister?: (
263
+ property: string,
264
+ options?: Partial<RegisterOptions>
265
+ ) => string | Partial<RegisterOptions> | null;
266
+ };
267
+ }
268
+
269
+
270
+ export type VerboseResponse =
271
+ | {
272
+ status: 1;
273
+ error: null;
274
+ }
275
+ | {
276
+ status: 0;
277
+ error: string;
278
+ };
279
+
280
+ export type NormalResponse = 1 | 0;
281
+
282
+ export type Response = VerboseResponse | NormalResponse;
283
+
284
+ export type Callback = (response: Response) => void;
285
+
286
+ export interface People {
287
+ set(prop: string, to: any, callback?: Callback): void;
288
+ set(prop: Dict, callback?: Callback): void;
289
+ set_once(prop: string, to: any, callback?: Callback): void;
290
+ set_once(prop: Dict, callback?: Callback): void;
291
+ unset(prop: string[] | string, callback?: Callback): void;
292
+ increment(prop: string | Dict, callback?: Callback): void;
293
+ increment(prop: string, by: number, callback?: Callback): void;
294
+ remove(prop: string, value: any, callback?: Callback): void;
295
+ remove(prop: Dict, callback?: Callback): void;
296
+ append(prop: string, value: any, callback?: Callback): void;
297
+ append(prop: Dict, callback?: Callback): void;
298
+ union(prop: string, value: any, callback?: Callback): void;
299
+ union(prop: Dict, callback?: Callback): void;
300
+ track_charge(
301
+ amount: number,
302
+ propertiesOrCallback?: Dict | Callback,
303
+ callback?: Callback
304
+ ): void;
305
+ clear_charges(callback?: Callback): void;
306
+ delete_user(): void;
307
+ }
308
+
309
+ export interface Group {
310
+ remove(list_name: string, value: string, callback?: Callback): Group;
311
+ set<Prop extends string | Dict>(
312
+ prop: Prop,
313
+ to?: Prop extends string ? string : undefined,
314
+ callback?: Callback
315
+ ): Group;
316
+ set_once<Prop extends string | Dict>(
317
+ prop: Prop,
318
+ to?: Prop extends string ? string : undefined,
319
+ callback?: Callback
320
+ ): Group;
321
+ union(
322
+ list_name: string,
323
+ values: Array<string | number>,
324
+ callback?: Callback
325
+ ): Group;
326
+ unset(prop: string, callback?: Callback): void;
327
+ }
328
+
329
+ export interface FlagsVariant {
330
+ key: string;
331
+ value: any;
332
+ experiment_id?: string;
333
+ is_experiment_active?: boolean;
334
+ is_qa_tester?: boolean;
335
+ }
336
+
337
+ export interface FlagsUpdateContextOptions {
338
+ replace?: boolean;
339
+ }
340
+
341
+ export interface FlagsManager {
342
+ are_flags_ready(): boolean;
343
+ get_variant(
344
+ featureName: string,
345
+ fallback: FlagsVariant
346
+ ): Promise<FlagsVariant>;
347
+ get_variant_sync(featureName: string, fallback: FlagsVariant): FlagsVariant;
348
+ get_variant_value(featureName: string, fallbackValue: any): Promise<any>;
349
+ get_variant_value_sync(featureName: string, fallbackValue: any): any;
350
+ is_enabled(featureName: string, fallbackValue?: boolean): Promise<boolean>;
351
+ is_enabled_sync(featureName: string, fallbackValue?: boolean): boolean;
352
+ update_context(
353
+ context: Dict,
354
+ options?: FlagsUpdateContextOptions
355
+ ): Promise<void>;
356
+ }
357
+
358
+ export interface Mixpanel {
359
+ add_group(group_key: string, group_id: string, callback?: Callback): void;
360
+ alias(alias: string, original?: string): void;
361
+ clear_opt_in_out_tracking(options?: Partial<ClearOptOutInOutOptions>): void;
362
+ disable(events?: string[]): void;
363
+ flags: FlagsManager;
364
+ get_config(prop_name?: string): any;
365
+ get_distinct_id(): any;
366
+ get_group(group_key: string, group_id: string): Group;
367
+ get_property(property_name: string): any;
368
+ get_session_replay_url(): string;
369
+ has_opted_in_tracking(options?: Partial<HasOptedInOutOptions>): boolean;
370
+ has_opted_out_tracking(options?: Partial<HasOptedInOutOptions>): boolean;
371
+ identify(unique_id?: string): any;
372
+ init(token: string, config: Partial<Config>, name?: string): Mixpanel;
373
+ opt_in_tracking(options?: Partial<InTrackingOptions>): void;
374
+ opt_out_tracking(options?: Partial<OutTrackingOptions>): void;
375
+ push(item: PushItem): void;
376
+ register(
377
+ props: Dict,
378
+ days_or_options?: number | Partial<RegisterOptions>
379
+ ): void;
380
+ register_once(
381
+ props: Dict,
382
+ default_value?: any,
383
+ days_or_options?: number | Partial<RegisterOptions>
384
+ ): void;
385
+ remove_group(
386
+ group_key: string,
387
+ group_ids: string | string[] | number | number[],
388
+ callback?: Callback
389
+ ): void;
390
+ reset(): void;
391
+ set_config(config: Partial<Config>): void;
392
+ set_group(
393
+ group_key: string,
394
+ group_ids: string | string[] | number | number[],
395
+ callback?: Callback
396
+ ): void;
397
+ start_batch_senders(): void;
398
+ time_event(event_name: string): void;
399
+ track(
400
+ event_name: string,
401
+ properties?: Dict,
402
+ optionsOrCallback?: RequestOptions | Callback,
403
+ callback?: Callback
404
+ ): void;
405
+ track_forms(
406
+ query: Query,
407
+ event_name: string,
408
+ properties?: Dict | (() => void)
409
+ ): void;
410
+ track_links(
411
+ query: Query,
412
+ event_name: string,
413
+ properties?: Dict | (() => void)
414
+ ): void;
415
+ track_pageview(
416
+ properties?: Dict,
417
+ options?: { event_name?: string | undefined }
418
+ ): void;
419
+ track_with_groups(
420
+ event_name: string,
421
+ properties: Dict,
422
+ groups: Dict,
423
+ callback?: Callback
424
+ ): void;
425
+ unregister(property: string, options?: Partial<RegisterOptions>): void;
426
+ people: People;
427
+ start_batch_senders(): void;
428
+ start_session_recording(): void;
429
+ stop_session_recording(): void;
430
+ get_session_recording_properties(): { $mp_replay_id?: string } | {};
431
+ }
432
+
433
+ export interface OverridedMixpanel extends Mixpanel {
434
+ init(token: string, config: Partial<Config>, name: string): Mixpanel;
435
+ init(token: string, config?: Partial<Config>): undefined;
436
+ }
437
+
438
+ export function add_group(
439
+ group_key: string,
440
+ group_id: string,
441
+ callback?: Callback
442
+ ): void;
443
+ export function alias(alias: string, original?: string): void;
444
+ export function clear_opt_in_out_tracking(
445
+ options?: Partial<ClearOptOutInOutOptions>
446
+ ): void;
447
+ export function disable(events?: string[]): void;
448
+ export function get_config(prop_name?: string): any;
449
+ export function get_distinct_id(): any;
450
+ export function get_group(group_key: string, group_id: string): Group;
451
+ export function get_property(property_name: string): any;
452
+ export function has_opted_in_tracking(
453
+ options?: Partial<HasOptedInOutOptions>
454
+ ): boolean;
455
+ export function has_opted_out_tracking(
456
+ options?: Partial<HasOptedInOutOptions>
457
+ ): boolean;
458
+ export function identify(unique_id?: string): any;
459
+ export function init(
460
+ token: string,
461
+ config: Partial<Config>,
462
+ name: string
463
+ ): Mixpanel;
464
+ export function init(token: string, config?: Partial<Config>): undefined;
465
+ export function opt_in_tracking(options?: Partial<InTrackingOptions>): void;
466
+ export function opt_out_tracking(options?: Partial<OutTrackingOptions>): void;
467
+ export function push(item: PushItem): void;
468
+ export function register(
469
+ props: Dict,
470
+ days_or_options?: number | Partial<RegisterOptions>
471
+ ): void;
472
+ export function register_once(
473
+ props: Dict,
474
+ default_value?: any,
475
+ days_or_options?: number | Partial<RegisterOptions>
476
+ ): void;
477
+ export function remove_group(
478
+ group_key: string,
479
+ group_ids: string | string[] | number | number[],
480
+ callback?: Callback
481
+ ): void;
482
+ export function reset(): void;
483
+ export function set_config(config: Partial<Config>): void;
484
+ export function set_group(
485
+ group_key: string,
486
+ group_ids: string | string[] | number | number[],
487
+ callback?: Callback
488
+ ): void;
489
+ export function time_event(event_name: string): void;
490
+ export function track(
491
+ event_name: string,
492
+ properties?: Dict,
493
+ optionsOrCallback?: RequestOptions | Callback,
494
+ callback?: Callback
495
+ ): void;
496
+ export function track_forms(
497
+ query: Query,
498
+ event_name: string,
499
+ properties?: Dict | (() => void)
500
+ ): void;
501
+ export function track_links(
502
+ query: Query,
503
+ event_name: string,
504
+ properties?: Dict | (() => void)
505
+ ): void;
506
+ export function track_with_groups(
507
+ event_name: string,
508
+ properties: Dict,
509
+ groups: Dict,
510
+ callback?: Callback
511
+ ): void;
512
+ export function unregister(
513
+ property: string,
514
+ options?: Partial<RegisterOptions>
515
+ ): void;
516
+ export const people: People;
517
+ export function get_session_recording_properties():
518
+ | { $mp_replay_id?: string }
519
+ | {};
520
+
521
+ declare const mixpanel: OverridedMixpanel;
522
+ export default mixpanel;