Skip to content

Customize Events

Sometimes you may want to customize how Logspot tracks events. You can achieve that by using the event mapper.

You can pass a callback function which will be executed before sending the event to the API.

import Logspot from "@logspot/web";
const annonymizeHostname = (hostname) => ...;
Logspot.init({ ...,
eventMapper: (payload) => {
return {
...payload,
hostname: annonymizeHostname(payload.hostname)
};
}
});

eventMapper callback can be asynchronous e.g.:

import Logspot from "@logspot/web";
const annonymizeHostname = async (hostname) => ...;
Logspot.init({ ...,
eventMapper: async (payload) => {
return {
...payload,
hostname: await annonymizeHostname(payload.hostname)
};
}
});

Event payload

type EventPayload = {
name: string;
message?: string | null;
notify?: boolean | null;
user_id?: string;
metadata?: any | null;
hostname?: string | null;
url?: string | null;
referrer?: string | null;
language?: string | null;
screen?: string | null;
};

Limitations

There are two requirements:

  • name is a required field
  • screen needs to be in format numberxnumber e.g. 1240x1200

location, browser and os cannot be overriden yet.