Browser Plugin to be used with @snowplow/browser-tracker
.
The plugin allows you to integrate with Event Specifications for a selected set of plugins. The plugin will automatically add an Event Specification context to the events matching the configuration added on the plugin. This configuration should be retrieved directly from your Data Product in the Snowplow BDP Console.
Part of the Snowplow JavaScript Tracker monorepo.
Build with Node.js (18 - 20) and Rush.
npm install -g @microsoft/rush
git clone https://github.com/snowplow/snowplow-javascript-tracker.git
rush update
With npm:
npm install @snowplow/browser-plugin-event-specifications
Initialize your tracker with the EventSpecificationsPlugin
:
import { newTracker } from '@snowplow/browser-tracker';
import { EventSpecificationsPlugin } from '@snowplow/browser-plugin-event-specifications';
newTracker('sp1', '{{collector}}', { plugins: [ EventSpecificationsPlugin(/* pluginOptions */) ] });
/*
* Available plugin options `EventSpecificationsPluginOptions`:
* {
* [k in AvailablePlugins]: Keys for available plugins that have been added as integrations.
* }
*/
The expected Event Specification option input can be retrieved directly from your Data Product in the Snowplow BDP Console and would be similar to the following example:
EventSpecificationsPlugin(
SnowplowMediaPlugin: { play_event: 'event_specification_id' }
);
Every integration needs to satisfy the following interface:
export type Integration = {
/**
* Find a matching event for the integration with a plugin and an event specification id map.
* The returned string should match what we expect as key coming from the configuration object on this specific plugin integration.
*/
detectMatchingEvent: (payloadBuilder: PayloadBuilder) => string | undefined
}
The detectMatchingEvent
function should return the key expected for the Event Specification input option of the integration.
To add a new integration, add the required code under src/integrations
and export it accordingly on the integrations
object on the src/integrations/index.ts
file.
Licensed and distributed under the BSD 3-Clause License (An OSI Approved License).
Copyright (c) 2024 Snowplow Analytics Ltd.
All rights reserved.