Skip to content

Commit 9835151

Browse files
authored
🤖 Merge PR DefinitelyTyped#72311 [mixpanel-browser] Add autocapture configuration by @levrik
1 parent 532f6fd commit 9835151

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

‎types/mixpanel-browser/index.d.ts‎

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,81 @@ export interface RegisterOptions {
4444
persistent: boolean;
4545
}
4646

47+
export type TrackPageView =
48+
| boolean
49+
| "url-with-path"
50+
| "url-with-path-and-query-string"
51+
| "full-url";
52+
53+
export interface AutocaptureConfig {
54+
/**
55+
* When set to `true`, Mixpanel will track element clicks. It will not track textContent unless `capture_text_content` is also set to `true`.
56+
* @default true
57+
*/
58+
click?: boolean;
59+
/**
60+
* When set to `true`, Mixpanel will track when an input is provided. It will not capture input content.
61+
* @default true
62+
*/
63+
input?: boolean;
64+
/**
65+
* When set, Mixpanel will collect pageviews when some components of the URL change — including UTM parameters.
66+
* @default 'full-url'
67+
*/
68+
pageview?: TrackPageView;
69+
/**
70+
* When set, Mixpanel will collect page scrolls at specified scroll intervals.
71+
* @default true
72+
*/
73+
scroll?: boolean;
74+
/**
75+
* When set to `true`, Mixpanel will track form submissions (but not submission content).
76+
* @default true
77+
*/
78+
submit?: boolean;
79+
/**
80+
* When set to `true`, Mixpanel will capture the textContent of any element.
81+
* @default false
82+
*/
83+
capture_text_content?: boolean;
84+
/** Enables specification of additional attributes to track. */
85+
capture_extra_attrs?: string[];
86+
/**
87+
* Establishes the scroll depth intervals which trigger `Page Scroll` event.
88+
* @default [25, 50, 75, 100]
89+
*/
90+
scroll_depth_percent_checkpoints?: number[];
91+
/**
92+
* When set to true, overrides `scroll_depth_percentage_checkpoints` and captures all scroll events.
93+
* @default false
94+
*/
95+
scroll_capture_all?: boolean;
96+
/** Opts out specific pages from Autocapture. */
97+
block_url_regexes?: RegExp[];
98+
/** Opts in specific pages to Autocapture. */
99+
allow_url_regexes?: RegExp[];
100+
/** Opts out specific classes from Autocapture. */
101+
block_selectors?: string[];
102+
/** Opts in specific classes to Autocapture. */
103+
allow_selectors?: string[];
104+
/** Opts out specific attributes from Autocapture. */
105+
block_attrs?: string[];
106+
/**
107+
* A user-provided function that determines whether a specific element should be
108+
* tracked via Autocapture or not. The function receives the element as its first
109+
* argument, and the DOM event as its second argument, and should return `true` if
110+
* the element should be tracked (otherwise the element will NOT be tracked).
111+
*/
112+
allow_element_callback?: (element: Element, event: Event) => boolean;
113+
/**
114+
* A user-provided function that determines whether a specific element should be
115+
* blocked from tracking via Autocapture or not. The function receives the element
116+
* as its first argument, and the DOM event as its second argument, and should
117+
* return `true` if the element should be blocked.
118+
*/
119+
block_element_callback?: (element: Element, event: Event) => boolean;
120+
}
121+
47122
export interface Config {
48123
api_host: string;
49124
api_routes: {
@@ -76,11 +151,8 @@ export interface Config {
76151
*/
77152
debug: boolean;
78153
track_links_timeout: number;
79-
track_pageview:
80-
| boolean
81-
| "url-with-path"
82-
| "url-with-path-and-query-string"
83-
| "full-url";
154+
track_pageview: TrackPageView;
155+
autocapture: boolean | AutocaptureConfig;
84156
skip_first_touch_marketing: boolean;
85157
cookie_expiration: number;
86158
upgrade: boolean;

‎types/mixpanel-browser/mixpanel-browser-tests.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ mixpanel.init("token", {
3838
mixpanel.init("token", {
3939
track_pageview: "full-url",
4040
});
41+
mixpanel.init("token", {
42+
autocapture: true,
43+
});
44+
mixpanel.init("token", {
45+
autocapture: {
46+
pageview: "url-with-path-and-query-string",
47+
capture_extra_attrs: ["id"],
48+
allow_element_callback: () => false,
49+
scroll_depth_percent_checkpoints: [20],
50+
block_url_regexes: [/\/login\/?$/],
51+
},
52+
});
4153
mixpanel.push(["register", { a: "b" }]);
4254
mixpanel.disable();
4355
mixpanel.track("Registered", { Gender: "Male", Age: 21 });

‎types/mixpanel-browser/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/mixpanel-browser",
4-
"version": "2.54.9999",
4+
"version": "2.60.9999",
55
"projects": [
66
"https://github.com/mixpanel/mixpanel-js"
77
],

0 commit comments

Comments
 (0)