Skip to content

Commit 3f90ee7

Browse files
committed
feat: Add Mixpanel Session Replay settings support
1 parent 8143b92 commit 3f90ee7

File tree

2 files changed

+677
-7
lines changed

2 files changed

+677
-7
lines changed

src/MixpanelEventForwarder.js

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,88 @@ var constructor = function () {
6262
if (!testMode) {
6363
renderSnippet();
6464
}
65-
mixpanel.init(
66-
settings.token,
67-
{
68-
api_host: forwarderSettings.baseUrl,
69-
},
70-
'mparticle'
71-
);
65+
// Build init options object
66+
var initOptions = {
67+
api_host: forwarderSettings.baseUrl,
68+
};
69+
70+
if (forwarderSettings.recordSessionsPercent != null) {
71+
var sessionPercent = parseInt(
72+
forwarderSettings.recordSessionsPercent,
73+
10
74+
);
75+
if (
76+
!isNaN(sessionPercent) &&
77+
sessionPercent >= 0 &&
78+
sessionPercent <= 100
79+
) {
80+
initOptions.record_sessions_percent = sessionPercent;
81+
}
82+
}
83+
84+
if (forwarderSettings.recordHeatmapData != null) {
85+
initOptions.record_heatmap_data =
86+
forwarderSettings.recordHeatmapData === 'True';
87+
}
88+
89+
if (forwarderSettings.autocapture != null) {
90+
initOptions.autocapture =
91+
forwarderSettings.autocapture === 'True';
92+
}
93+
94+
// Privacy and masking settings
95+
if (forwarderSettings.recordMaskTextSelector) {
96+
initOptions.record_mask_text_selector =
97+
forwarderSettings.recordMaskTextSelector;
98+
}
99+
100+
if (forwarderSettings.recordBlockSelector) {
101+
initOptions.record_block_selector =
102+
forwarderSettings.recordBlockSelector;
103+
}
104+
105+
if (forwarderSettings.recordBlockClass) {
106+
initOptions.record_block_class =
107+
forwarderSettings.recordBlockClass;
108+
}
109+
110+
if (forwarderSettings.recordMaskTextClass) {
111+
initOptions.record_mask_text_class =
112+
forwarderSettings.recordMaskTextClass;
113+
}
114+
115+
// Canvas recording (experimental)
116+
if (forwarderSettings.recordCanvas != null) {
117+
initOptions.record_canvas =
118+
forwarderSettings.recordCanvas === 'True';
119+
}
120+
121+
// Timing settings
122+
if (forwarderSettings.recordIdleTimeoutMs != null) {
123+
var idleTimeoutMs = parseInt(
124+
forwarderSettings.recordIdleTimeoutMs,
125+
10
126+
);
127+
if (!isNaN(idleTimeoutMs)) {
128+
initOptions.record_idle_timeout_ms = idleTimeoutMs;
129+
}
130+
}
131+
132+
if (forwarderSettings.recordMaxMs != null) {
133+
var maxMs = parseInt(forwarderSettings.recordMaxMs, 10);
134+
if (!isNaN(maxMs)) {
135+
initOptions.record_max_ms = maxMs;
136+
}
137+
}
138+
139+
if (forwarderSettings.recordMinMs != null) {
140+
var minMs = parseInt(forwarderSettings.recordMinMs, 10);
141+
if (!isNaN(minMs)) {
142+
initOptions.record_min_ms = minMs;
143+
}
144+
}
145+
146+
mixpanel.init(settings.token, initOptions, 'mparticle');
72147

73148
isInitialized = true;
74149

0 commit comments

Comments
 (0)