Customize Events
Reshape events before they're sent with the event mapper, and attach properties to every event with super properties.
There are two ways to shape what Logspot records:
eventMapper— a hook that runs on every event, just before it's sent, so you can rewrite or redact fields.- Super properties — values you register once that get merged into every event automatically.
eventMapper
Pass a callback to init that receives the outgoing event and returns a
modified one. Use it to anonymize, drop, or add fields:
import Logspot from '@logspot/web';
Logspot.init({
publicKey: 'YOUR_PUBLIC_KEY',
eventMapper: (payload) => ({
...payload,
hostname: anonymizeHostname(payload.hostname),
}),
});The callback can be async (e.g. to look something up before sending):
Logspot.init({
publicKey: 'YOUR_PUBLIC_KEY',
eventMapper: async (payload) => ({
...payload,
hostname: await anonymizeHostname(payload.hostname),
}),
});Event Payload
The mapper receives — and must return — this shape:
type EventPayload = {
name: string;
message?: string | null;
notify?: boolean | null;
user_id?: string | null;
anonymous_id?: string | null;
metadata?: Record<string, unknown> | null;
// Page context
hostname?: string | null;
url?: string | null;
referrer?: string | null;
language?: string | null;
screen?: string | null;
// Revenue (set by revenue(), or a track call that passes them):
value?: number | null; // amount in major units, e.g. dollars
currency?: string | null; // ISO-4217, e.g. "USD"
};Consent stamps are not mappable. The SDK adds the visitor's consent categories and privacy signals to the payload after
eventMapperruns, so your hook can never see or accidentally clobber them. See Consent Management.
Query-param stripping is applied after the mapper too, so a mapper can't
reintroduce parameters you asked Logspot to remove from url and referrer.
Super Properties
To attach the same fields to every event without touching each track
call, register them once:
Logspot.register({ plan: 'pro', appVersion: '2.1.0' });Registered properties are merged into the metadata of every subsequent event
and persist in a first-party cookie for 30 days. See
Super properties in the JS SDK reference for
register, getProperties, unregister, and reset.
Related Ways to Shape Tracking
- Autocapture —
enableAutoClicks/enableAutoPageviewsand thelgspt-class convention capture interactions automatically. See JS SDK. - Identifying users and campaign tracking enrich events with who the user is and where they came from.
Limitations
nameis required.screenshould be inWIDTHxHEIGHTformat, e.g.1240x1200— it's what the device class is derived from.location,browser, andosare derived server-side and can't be overridden in the mapper.