Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing session replay click events with current location #607

Draft
wants to merge 1 commit into
base: v1.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion packages/session-replay-browser/src/session-replay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAnalyticsConnector, getGlobalScope } from '@amplitude/analytics-client-common';
import { BaseTransport, Logger, returnWrapper } from '@amplitude/analytics-core';
import { Logger as ILogger, ServerZone, Status } from '@amplitude/analytics-types';
import { RecordPlugin } from '@rrweb/types';
import * as IDBKeyVal from 'idb-keyval';
import { pack, record } from 'rrweb';
import { SessionReplayConfig } from './config';
Expand All @@ -18,7 +19,7 @@ import {
STORAGE_PREFIX,
defaultSessionStore,
} from './constants';
import { isSessionInSample, maskInputFn, getCurrentUrl } from './helpers';
import { getCurrentUrl, isSessionInSample, maskInputFn } from './helpers';
import {
MAX_RETRIES_EXCEEDED_MESSAGE,
MISSING_API_KEY_MESSAGE,
Expand All @@ -40,6 +41,29 @@ import {
} from './typings/session-replay';
import { VERSION } from './version';

const heatmapPlugin: RecordPlugin = {
name: 'amplitude/rrweb-heatmap',

eventProcessor: (event) => {
const isIncrementalSnapShot = event.type === 3;
if (isIncrementalSnapShot) {
const isMouseInteraction = event.data.source === 2;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const isMouseClick = event.data.type === 2;
if (isMouseInteraction && isMouseClick) {
console.log('event', event, 'document.location', document.location);
return {
...event,
href: document.location.href,
};
}
}
return event;
},
options: {},
};

export class SessionReplay implements AmplitudeSessionReplay {
name = '@amplitude/session-replay-browser';
config: ISessionReplayConfig | undefined;
Expand Down Expand Up @@ -275,6 +299,7 @@ export class SessionReplay implements AmplitudeSessionReplay {

return true;
},
plugins: [heatmapPlugin],
});
}

Expand Down