@eventvisor/sdk
v1.0.0
Published
Event governance SDK for browsers, Node.js, and React Native
Maintainers
Readme
@eventvisor/sdk
The universal Eventvisor SDK for Node.js and browsers.
npm install @eventvisor/sdkimport { createEventvisor } from "@eventvisor/sdk";
const eventvisor = createEventvisor({
datafile,
initialAttributes: { userId: "123" },
});
await eventvisor.onReady();
await eventvisor.track("checkout.completed", { orderId: "order-1" });Attributes
await eventvisor.setAttribute("country", "NL");
eventvisor.getAttributeValue("country");
eventvisor.getAttributes();
await eventvisor.removeAttribute("country");Modules and diagnostics
Modules provide lookups, transports, handlers, and storage. They can subscribe to diagnostics during setup and clean up resources when closed.
const eventvisor = createEventvisor({
modules: [myModule],
onDiagnostic(diagnostic) {
reportDiagnostic(diagnostic);
},
});
const removeModule = eventvisor.addModule(anotherModule);
await removeModule?.();Modules can also be removed by name with await eventvisor.removeModule(anotherModule.name).
Updating datafiles
Datafiles merge by default. Pass true to replace the current datafile.
await eventvisor.setDatafile(nextDatafile);
await eventvisor.setDatafile(nextDatafile, true);Invalid JSON reports an invalid_datafile diagnostic containing the phrase Could not parse datafile.
Events and lifecycle
const unsubscribe = eventvisor.on("event_tracked", ({ eventName, value }) => {});
const child = eventvisor.spawn({ initialAttributes: { surface: "checkout" } });
unsubscribe();
await child.close();
await eventvisor.close();Closing an instance releases module, event, and diagnostic subscriptions. See the JavaScript SDK documentation for the complete API.
License
MIT © Fahad Heylaal
