@malleon/replay
v1.0.12
Published
A JavaScript SDK for capturing and replaying user interactions on web pages
Downloads
1,239
Maintainers
Readme
Replay SDK
A JavaScript SDK for capturing and replaying user interactions on web pages.
Compile
Dev
clear && npm run dist
Prod
clear && npm run dist:prod
Basic Usage
// Initialize replay for an app
initReplay('your-app-id');
// Add tags to the current replay
addTagToReplay('userType', 'premium', 'STR');
addTagToReplay('sessionId', 'abc123', 'STR');
addTagToReplay('isLoggedIn', true, 'BOOL');
addTagToReplay('loginTime', new Date(), 'DATETIME');
addTagToReplay('score', 95, 'NUM');
// Add multiple tags at once
addTagsToReplay([
{ name: 'browser', value: 'chrome', type: 'STR' },
{ name: 'device', value: 'desktop', type: 'STR' },
{ name: 'timestamp', value: new Date(), type: 'DATETIME' },
{ name: 'version', value: 2.1, type: 'NUM' }
]);
// Update user data for the replay
updateReplayUserData({
userId: 'user123',
username: 'john_doe',
userEmail: '[email protected]',
userRole: 'admin',
userStatus: 'active'
});API Reference
initReplay(appId: string): void
Initializes the replay system for the specified app ID. Must be called before using other functions.
addTagToReplay(name: string, value: string | number | boolean | Date, type: TagType): Promise<void>
Adds a single tag to the current replay. The type parameter is required and must match one of the supported tag types.
addTagsToReplay(tags: ReplayTag[]): Promise<void>
Adds multiple tags to the current replay at once. Each tag must include a name, value, and type.
updateReplayUserData(userData: ReplayUserData): Promise<void>
Updates user metadata for the current replay. All fields are optional.
Types and Interfaces
All types and interfaces are exported from ./types/replay-types and can be imported for use in TypeScript projects:
import { TagType, ReplayTag, ReplayUserData } from './types/replay-types';TagType
type TagType = 'STR' | 'LARGE_STR' | 'NUM' | 'DATETIME' | 'BOOL';ReplayTag
interface ReplayTag {
name: string;
value: string | number | boolean | Date;
type: TagType;
}ReplayUserData
interface ReplayUserData {
userId?: string;
username?: string;
userEmail?: string;
userRole?: string;
userStatus?: string;
}Tag Types
The following tag types are supported:
'STR'- Short string values'LARGE_STR'- Long string values'NUM'- Numeric values'DATETIME'- Date and time values'BOOL'- Boolean values (true/false)
Note: The ReplayTag interface now uses name instead of key to match the backend TagInput class exactly, eliminating the need for field mapping.
Requirements
- Must call
initReplay()first to initialize the replay system - Functions will warn if called before initialization
- All functions are asynchronous and return promises
- Functions are also available globally on the
windowobject - Tag functions require a
typeparameter to specify the data type
