Skip to content

Commit a9a926b

Browse files
fix(session-replay-browser): support disabling batching for interaction events (#853)
1 parent ddf3e70 commit a9a926b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

packages/session-replay-browser/src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface SamplingConfig {
88
export interface InteractionConfig {
99
trackEveryNms?: number;
1010
enabled: boolean; // defaults to false
11+
batch: boolean; // defaults to false
1112
}
1213

1314
export type SessionReplayRemoteConfig = {

packages/session-replay-browser/src/session-replay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ export class SessionReplay implements AmplitudeSessionReplay {
105105
managers.push({ name: 'replay', manager: rrwebEventManager });
106106

107107
if (this.config.interactionConfig?.enabled) {
108+
const payloadBatcher = this.config.interactionConfig.batch ? clickBatcher : undefined;
108109
const interactionEventManager = await createEventsManager<'interaction'>({
109110
config: this.config,
110111
sessionId: this.identifiers.sessionId,
111112
type: 'interaction',
112113
minInterval: this.config.interactionConfig.trackEveryNms ?? INTERACTION_MIN_INTERVAL,
113114
maxInterval: INTERACTION_MAX_INTERVAL,
114-
payloadBatcher: clickBatcher,
115+
payloadBatcher,
115116
});
116117
managers.push({ name: 'interaction', manager: interactionEventManager });
117118
}

packages/session-replay-browser/test/session-replay.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ describe('SessionReplay', () => {
201201
},
202202
async (config: SessionReplayJoinedConfig) => {
203203
expect(config.interactionConfig?.enabled).toBe(true);
204+
expect(config.interactionConfig?.batch).toBeUndefined();
204205
expect(config.interactionConfig?.trackEveryNms).toBe(500);
205206
},
206207
],
@@ -210,6 +211,7 @@ describe('SessionReplay', () => {
210211
},
211212
async (config: SessionReplayJoinedConfig) => {
212213
expect(config.interactionConfig?.enabled).toBe(true);
214+
expect(config.interactionConfig?.batch).toBeUndefined();
213215
expect(config.interactionConfig?.trackEveryNms).toBeUndefined();
214216
},
215217
],
@@ -220,13 +222,37 @@ describe('SessionReplay', () => {
220222
},
221223
async (config: SessionReplayJoinedConfig) => {
222224
expect(config.interactionConfig?.enabled).toBe(false);
225+
expect(config.interactionConfig?.batch).toBeUndefined();
223226
expect(config.interactionConfig?.trackEveryNms).toBe(1_000);
224227
},
225228
],
226229
[
227230
undefined,
228231
async (config: SessionReplayJoinedConfig) => {
229232
expect(config.interactionConfig?.enabled).toBeUndefined();
233+
expect(config.interactionConfig?.batch).toBeUndefined();
234+
expect(config.interactionConfig?.trackEveryNms).toBeUndefined();
235+
},
236+
],
237+
[
238+
{
239+
enabled: true,
240+
batch: true,
241+
},
242+
async (config: SessionReplayJoinedConfig) => {
243+
expect(config.interactionConfig?.enabled).toBe(true);
244+
expect(config.interactionConfig?.batch).toBe(true);
245+
expect(config.interactionConfig?.trackEveryNms).toBeUndefined();
246+
},
247+
],
248+
[
249+
{
250+
enabled: true,
251+
batch: false,
252+
},
253+
async (config: SessionReplayJoinedConfig) => {
254+
expect(config.interactionConfig?.enabled).toBe(true);
255+
expect(config.interactionConfig?.batch).toBe(false);
230256
expect(config.interactionConfig?.trackEveryNms).toBeUndefined();
231257
},
232258
],

0 commit comments

Comments
 (0)