mixpanel-browser 2.70.0 → 2.71.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 (37) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build.sh +1 -0
  3. package/dist/mixpanel-core.cjs.d.ts +440 -0
  4. package/dist/mixpanel-core.cjs.js +847 -50
  5. package/dist/mixpanel-recorder.js +5 -3
  6. package/dist/mixpanel-recorder.min.js +1 -1
  7. package/dist/mixpanel-recorder.min.js.map +1 -1
  8. package/dist/mixpanel-with-async-recorder.cjs.d.ts +440 -0
  9. package/dist/mixpanel-with-async-recorder.cjs.js +847 -50
  10. package/dist/mixpanel-with-recorder.d.ts +440 -0
  11. package/dist/mixpanel-with-recorder.js +851 -52
  12. package/dist/mixpanel-with-recorder.min.d.ts +440 -0
  13. package/dist/mixpanel-with-recorder.min.js +1 -1
  14. package/dist/mixpanel.amd.d.ts +440 -0
  15. package/dist/mixpanel.amd.js +851 -52
  16. package/dist/mixpanel.cjs.d.ts +440 -0
  17. package/dist/mixpanel.cjs.js +851 -52
  18. package/dist/mixpanel.globals.js +847 -50
  19. package/dist/mixpanel.min.js +170 -153
  20. package/dist/mixpanel.module.d.ts +440 -0
  21. package/dist/mixpanel.module.js +851 -52
  22. package/dist/mixpanel.umd.d.ts +440 -0
  23. package/dist/mixpanel.umd.js +851 -52
  24. package/dist/rrweb-compiled.js +4 -2
  25. package/package.json +2 -19
  26. package/rollup.config.mjs +28 -4
  27. package/src/autocapture/deadclick.js +254 -0
  28. package/src/autocapture/index.js +237 -41
  29. package/src/autocapture/shadow-dom-observer.js +100 -0
  30. package/src/autocapture/utils.js +230 -3
  31. package/src/config.js +1 -1
  32. package/src/flags/index.js +32 -12
  33. package/src/index.d.ts +16 -3
  34. package/src/loaders/loader-module-core.d.ts +1 -0
  35. package/src/loaders/loader-module-with-async-recorder.d.ts +1 -0
  36. package/src/loaders/loader-module.d.ts +1 -0
  37. package/src/utils.js +15 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ **2.71.0** (2 Oct 2025)
2
+ - adds Dead Click ($mp_dead_click) autocapture event: when a click occurs but there is no DOM mutation afterwards
3
+ - adds Page Leave ($mp_page_leave) autocapture event: when a page is "left" either by navigation or leaving the tab
4
+ - adds additional properties to experiment exposure events for feature flags
5
+ - upgrades rrweb fork to fix a hidden input masking issue
6
+ - gets rid of package.json exports feature to be less restrictive of what can be imported
7
+ - adds type definitions for each build option
8
+
1
9
  **2.70.0** (4 Sep 2025)
2
10
  - Feature flags requests now send params on query string with GET instead of POST for easier caching
3
11
 
package/build.sh CHANGED
@@ -23,6 +23,7 @@ if [ ! -z "$FULL" ]; then
23
23
  pushd examples/commonjs-browserify; npm install && npm run build; popd
24
24
  pushd examples/es2015-babelify; npm install && npm run build; popd
25
25
  pushd examples/umd-webpack; npm install && npm run build; popd
26
+ pushd examples/typescript; npm install && npm run build; popd
26
27
  fi
27
28
 
28
29
  if [ ! -z "$DIST" ]; then
@@ -0,0 +1,440 @@
1
+ export type Persistence = "cookie" | "localStorage";
2
+
3
+ export type ApiPayloadFormat = "base64" | "json";
4
+
5
+ export type PushItem = Array<string | Dict>;
6
+
7
+ export type Query = string | Element | Element[];
8
+
9
+ export interface Dict {
10
+ [key: string]: any;
11
+ }
12
+
13
+ export interface RequestOptions {
14
+ transport?: "xhr" | "sendBeacon" | undefined;
15
+ send_immediately?: boolean | undefined;
16
+ }
17
+
18
+ export interface XhrHeadersDef {
19
+ [header: string]: any;
20
+ }
21
+
22
+ export interface HasOptedInOutOptions {
23
+ persistence_type: Persistence;
24
+ cookie_prefix: string;
25
+ }
26
+
27
+ export interface ClearOptOutInOutOptions extends HasOptedInOutOptions {
28
+ cookie_expiration: number;
29
+ cross_subdomain_cookie: boolean;
30
+ secure_cookie: boolean;
31
+ }
32
+
33
+ export interface InTrackingOptions extends ClearOptOutInOutOptions {
34
+ track: () => void;
35
+ track_event_name: string;
36
+ track_properties: Dict;
37
+ }
38
+
39
+ export interface OutTrackingOptions extends ClearOptOutInOutOptions {
40
+ delete_user: boolean;
41
+ }
42
+
43
+ export type RageClickConfig =
44
+ | boolean
45
+ | {
46
+ /** Distance threshold in pixels for clicks to be considered within the same area (default: 30) */
47
+ threshold_px?: number;
48
+ /** Time window in milliseconds for clicks to be considered rapid (default: 1000) */
49
+ timeout_ms?: number;
50
+ /** Number of clicks required to trigger a rage click event (default: 3) */
51
+ click_count?: number;
52
+ };
53
+
54
+ export type DeadClickConfig =
55
+ | boolean
56
+ | {
57
+ /** Time in milliseconds to wait after a click before qualifying it as dead (default: 500) */
58
+ timeout_ms?: number;
59
+ };
60
+
61
+ export interface RegisterOptions {
62
+ persistent: boolean;
63
+ }
64
+
65
+ export type TrackPageView =
66
+ | boolean
67
+ | "url-with-path"
68
+ | "url-with-path-and-query-string"
69
+ | "full-url";
70
+
71
+ export interface AutocaptureConfig {
72
+ /**
73
+ * When set to `true`, Mixpanel will track element clicks. It will not track textContent unless `capture_text_content` is also set to `true`.
74
+ * @default true
75
+ */
76
+ click?: boolean;
77
+ /**
78
+ * When set to `true`, Mixpanel will track when an input is provided. It will not capture input content.
79
+ * @default true
80
+ */
81
+ input?: boolean;
82
+ /**
83
+ * When set, Mixpanel will collect pageviews when some components of the URL change — including UTM parameters.
84
+ * @default 'full-url'
85
+ */
86
+ pageview?: TrackPageView;
87
+ /**
88
+ * When set to `true`, Mixpanel will track rage clicks (multiple clicks in a short time on the same element).
89
+ * Can also be configured as an object to customize rage click detection parameters.
90
+ * @default true
91
+ */
92
+ rage_click?: RageClickConfig;
93
+ /**
94
+ * When set to `true`, Mixpanel will track dead clicks (clicks that produce no response).
95
+ * Can also be configured as an object to customize dead click detection parameters.
96
+ * @default true
97
+ */
98
+ dead_click?: DeadClickConfig;
99
+ /**
100
+ * When set, Mixpanel will collect page scrolls at specified scroll intervals.
101
+ * @default true
102
+ */
103
+ scroll?: boolean;
104
+ /**
105
+ * When set to `true`, Mixpanel will track form submissions (but not submission content).
106
+ * @default true
107
+ */
108
+ submit?: boolean;
109
+ /**
110
+ * When set to `true`, Mixpanel will capture the textContent of any element.
111
+ * @default false
112
+ */
113
+ capture_text_content?: boolean;
114
+ /** Enables specification of additional attributes to track. */
115
+ capture_extra_attrs?: string[];
116
+ /**
117
+ * Establishes the scroll depth intervals which trigger `Page Scroll` event.
118
+ * @default [25, 50, 75, 100]
119
+ */
120
+ scroll_depth_percent_checkpoints?: number[];
121
+ /**
122
+ * When set to true, overrides `scroll_depth_percentage_checkpoints` and captures all scroll events.
123
+ * @default false
124
+ */
125
+ scroll_capture_all?: boolean;
126
+ /** Opts out specific pages from Autocapture. */
127
+ block_url_regexes?: RegExp[];
128
+ /** Opts in specific pages to Autocapture. */
129
+ allow_url_regexes?: RegExp[];
130
+ /** Opts out specific classes from Autocapture. */
131
+ block_selectors?: string[];
132
+ /** Opts in specific classes to Autocapture. */
133
+ allow_selectors?: string[];
134
+ /** Opts out specific attributes from Autocapture. */
135
+ block_attrs?: string[];
136
+ /**
137
+ * A user-provided function that determines whether a specific element should be
138
+ * tracked via Autocapture or not. The function receives the element as its first
139
+ * argument, and the DOM event as its second argument, and should return `true` if
140
+ * the element should be tracked (otherwise the element will NOT be tracked).
141
+ */
142
+ allow_element_callback?: (element: Element, event: Event) => boolean;
143
+ /**
144
+ * A user-provided function that determines whether a specific element should be
145
+ * blocked from tracking via Autocapture or not. The function receives the element
146
+ * as its first argument, and the DOM event as its second argument, and should
147
+ * return `true` if the element should be blocked.
148
+ */
149
+ block_element_callback?: (element: Element, event: Event) => boolean;
150
+ }
151
+
152
+ export interface Config {
153
+ api_host: string;
154
+ api_routes: {
155
+ track?: string;
156
+ engage?: string;
157
+ groups?: string;
158
+ };
159
+ api_method: string;
160
+ api_transport: string;
161
+ app_host: string;
162
+ api_payload_format: ApiPayloadFormat;
163
+ autotrack: boolean;
164
+ cdn: string;
165
+ cookie_domain: string;
166
+ cross_site_cookie: boolean;
167
+ cross_subdomain_cookie: boolean;
168
+ persistence: Persistence;
169
+ persistence_name: string;
170
+ cookie_name: string;
171
+ loaded: (mixpanel: Mixpanel) => void;
172
+ store_google: boolean;
173
+ stop_utm_persistence: boolean;
174
+ save_referrer: boolean;
175
+ test: boolean;
176
+ verbose: boolean;
177
+ img: boolean;
178
+ /**
179
+ * @default false
180
+ * @see https://github.com/mixpanel/mixpanel-js/blob/master/doc/readme.io/javascript-full-api-reference.md#mixpanelset_config
181
+ */
182
+ debug: boolean;
183
+ track_links_timeout: number;
184
+ track_pageview: TrackPageView;
185
+ autocapture: boolean | AutocaptureConfig;
186
+ skip_first_touch_marketing: boolean;
187
+ cookie_expiration: number;
188
+ upgrade: boolean;
189
+ disable_persistence: boolean;
190
+ disable_cookie: boolean;
191
+ disable_notifications: boolean;
192
+ secure_cookie: boolean;
193
+ ip: boolean;
194
+ property_blacklist: string[];
195
+ xhr_headers: XhrHeadersDef;
196
+ opt_out_tracking_by_default: boolean;
197
+ opt_out_persistence_by_default: boolean;
198
+ opt_out_tracking_persistence_type: Persistence;
199
+ opt_out_tracking_cookie_prefix: string;
200
+ inapp_protocol: string;
201
+ inapp_link_new_window: boolean;
202
+ ignore_dnt: boolean;
203
+ batch_requests: boolean;
204
+ batch_size: number;
205
+ batch_flush_interval_ms: number;
206
+ batch_request_timeout_ms: number;
207
+ record_block_class: string | RegExp;
208
+ record_block_selector: string;
209
+ record_collect_fonts: boolean;
210
+ record_idle_timeout_ms: number;
211
+ record_inline_images: boolean;
212
+ record_mask_text_class: string | RegExp;
213
+ record_mask_text_selector: string;
214
+ record_min_ms: number;
215
+ record_max_ms: number;
216
+ record_sessions_percent: number;
217
+ record_canvas: boolean;
218
+ record_heatmap_data: boolean;
219
+ }
220
+
221
+ export type VerboseResponse =
222
+ | {
223
+ status: 1;
224
+ error: null;
225
+ }
226
+ | {
227
+ status: 0;
228
+ error: string;
229
+ };
230
+
231
+ export type NormalResponse = 1 | 0;
232
+
233
+ export type Response = VerboseResponse | NormalResponse;
234
+
235
+ export type Callback = (response: Response) => void;
236
+
237
+ export interface People {
238
+ set(prop: string, to: any, callback?: Callback): void;
239
+ set(prop: Dict, callback?: Callback): void;
240
+ set_once(prop: string, to: any, callback?: Callback): void;
241
+ set_once(prop: Dict, callback?: Callback): void;
242
+ unset(prop: string[] | string, callback?: Callback): void;
243
+ increment(prop: string | Dict, callback?: Callback): void;
244
+ increment(prop: string, by: number, callback?: Callback): void;
245
+ remove(prop: string, value: any, callback?: Callback): void;
246
+ remove(prop: Dict, callback?: Callback): void;
247
+ append(prop: string, value: any, callback?: Callback): void;
248
+ append(prop: Dict, callback?: Callback): void;
249
+ union(prop: string, value: any, callback?: Callback): void;
250
+ union(prop: Dict, callback?: Callback): void;
251
+ track_charge(
252
+ amount: number,
253
+ propertiesOrCallback?: Dict | Callback,
254
+ callback?: Callback
255
+ ): void;
256
+ clear_charges(callback?: Callback): void;
257
+ delete_user(): void;
258
+ }
259
+
260
+ export interface Group {
261
+ remove(list_name: string, value: string, callback?: Callback): Group;
262
+ set<Prop extends string | Dict>(
263
+ prop: Prop,
264
+ to?: Prop extends string ? string : undefined,
265
+ callback?: Callback
266
+ ): Group;
267
+ set_once<Prop extends string | Dict>(
268
+ prop: Prop,
269
+ to?: Prop extends string ? string : undefined,
270
+ callback?: Callback
271
+ ): Group;
272
+ union(
273
+ list_name: string,
274
+ values: Array<string | number>,
275
+ callback?: Callback
276
+ ): Group;
277
+ unset(prop: string, callback?: Callback): void;
278
+ }
279
+
280
+ export interface Mixpanel {
281
+ add_group(group_key: string, group_id: string, callback?: Callback): void;
282
+ alias(alias: string, original?: string): void;
283
+ clear_opt_in_out_tracking(options?: Partial<ClearOptOutInOutOptions>): void;
284
+ disable(events?: string[]): void;
285
+ get_config(prop_name?: string): any;
286
+ get_distinct_id(): any;
287
+ get_group(group_key: string, group_id: string): Group;
288
+ get_property(property_name: string): any;
289
+ has_opted_in_tracking(options?: Partial<HasOptedInOutOptions>): boolean;
290
+ has_opted_out_tracking(options?: Partial<HasOptedInOutOptions>): boolean;
291
+ identify(unique_id?: string): any;
292
+ init(token: string, config: Partial<Config>, name: string): Mixpanel;
293
+ opt_in_tracking(options?: Partial<InTrackingOptions>): void;
294
+ opt_out_tracking(options?: Partial<OutTrackingOptions>): void;
295
+ push(item: PushItem): void;
296
+ register(
297
+ props: Dict,
298
+ days_or_options?: number | Partial<RegisterOptions>
299
+ ): void;
300
+ register_once(
301
+ props: Dict,
302
+ default_value?: any,
303
+ days_or_options?: number | Partial<RegisterOptions>
304
+ ): void;
305
+ remove_group(
306
+ group_key: string,
307
+ group_ids: string | string[] | number | number[],
308
+ callback?: Callback
309
+ ): void;
310
+ reset(): void;
311
+ set_config(config: Partial<Config>): void;
312
+ set_group(
313
+ group_key: string,
314
+ group_ids: string | string[] | number | number[],
315
+ callback?: Callback
316
+ ): void;
317
+ time_event(event_name: string): void;
318
+ track(
319
+ event_name: string,
320
+ properties?: Dict,
321
+ optionsOrCallback?: RequestOptions | Callback,
322
+ callback?: Callback
323
+ ): void;
324
+ track_forms(
325
+ query: Query,
326
+ event_name: string,
327
+ properties?: Dict | (() => void)
328
+ ): void;
329
+ track_links(
330
+ query: Query,
331
+ event_name: string,
332
+ properties?: Dict | (() => void)
333
+ ): void;
334
+ track_pageview(
335
+ properties?: Dict,
336
+ options?: { event_name?: string | undefined }
337
+ ): void;
338
+ track_with_groups(
339
+ event_name: string,
340
+ properties: Dict,
341
+ groups: Dict,
342
+ callback?: Callback
343
+ ): void;
344
+ unregister(property: string, options?: Partial<RegisterOptions>): void;
345
+ people: People;
346
+ start_session_recording(): void;
347
+ stop_session_recording(): void;
348
+ get_session_recording_properties(): { $mp_replay_id?: string } | {};
349
+ }
350
+
351
+ export interface OverridedMixpanel extends Mixpanel {
352
+ init(token: string, config: Partial<Config>, name: string): Mixpanel;
353
+ init(token: string, config?: Partial<Config>): undefined;
354
+ }
355
+
356
+ export function add_group(
357
+ group_key: string,
358
+ group_id: string,
359
+ callback?: Callback
360
+ ): void;
361
+ export function alias(alias: string, original?: string): void;
362
+ export function clear_opt_in_out_tracking(
363
+ options?: Partial<ClearOptOutInOutOptions>
364
+ ): void;
365
+ export function disable(events?: string[]): void;
366
+ export function get_config(prop_name?: string): any;
367
+ export function get_distinct_id(): any;
368
+ export function get_group(group_key: string, group_id: string): Group;
369
+ export function get_property(property_name: string): any;
370
+ export function has_opted_in_tracking(
371
+ options?: Partial<HasOptedInOutOptions>
372
+ ): boolean;
373
+ export function has_opted_out_tracking(
374
+ options?: Partial<HasOptedInOutOptions>
375
+ ): boolean;
376
+ export function identify(unique_id?: string): any;
377
+ export function init(
378
+ token: string,
379
+ config: Partial<Config>,
380
+ name: string
381
+ ): Mixpanel;
382
+ export function init(token: string, config?: Partial<Config>): undefined;
383
+ export function opt_in_tracking(options?: Partial<InTrackingOptions>): void;
384
+ export function opt_out_tracking(options?: Partial<OutTrackingOptions>): void;
385
+ export function push(item: PushItem): void;
386
+ export function register(
387
+ props: Dict,
388
+ days_or_options?: number | Partial<RegisterOptions>
389
+ ): void;
390
+ export function register_once(
391
+ props: Dict,
392
+ default_value?: any,
393
+ days_or_options?: number | Partial<RegisterOptions>
394
+ ): void;
395
+ export function remove_group(
396
+ group_key: string,
397
+ group_ids: string | string[] | number | number[],
398
+ callback?: Callback
399
+ ): void;
400
+ export function reset(): void;
401
+ export function set_config(config: Partial<Config>): void;
402
+ export function set_group(
403
+ group_key: string,
404
+ group_ids: string | string[] | number | number[],
405
+ callback?: Callback
406
+ ): void;
407
+ export function time_event(event_name: string): void;
408
+ export function track(
409
+ event_name: string,
410
+ properties?: Dict,
411
+ optionsOrCallback?: RequestOptions | Callback,
412
+ callback?: Callback
413
+ ): void;
414
+ export function track_forms(
415
+ query: Query,
416
+ event_name: string,
417
+ properties?: Dict | (() => void)
418
+ ): void;
419
+ export function track_links(
420
+ query: Query,
421
+ event_name: string,
422
+ properties?: Dict | (() => void)
423
+ ): void;
424
+ export function track_with_groups(
425
+ event_name: string,
426
+ properties: Dict,
427
+ groups: Dict,
428
+ callback?: Callback
429
+ ): void;
430
+ export function unregister(
431
+ property: string,
432
+ options?: Partial<RegisterOptions>
433
+ ): void;
434
+ export const people: People;
435
+ export function get_session_recording_properties():
436
+ | { $mp_replay_id?: string }
437
+ | {};
438
+
439
+ declare const mixpanel: OverridedMixpanel;
440
+ export default mixpanel;