|
| 1 | +# Snowplow Event Specifications Plugin |
| 2 | + |
| 3 | +[![npm version][npm-image]][npm-url] |
| 4 | +[![License][license-image]](LICENSE) |
| 5 | + |
| 6 | +Browser Plugin to be used with `@snowplow/browser-tracker`. |
| 7 | + |
| 8 | +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](https://console.snowplowanalytics.com). |
| 9 | + |
| 10 | +## Maintainer quick start |
| 11 | + |
| 12 | +Part of the Snowplow JavaScript Tracker monorepo. |
| 13 | +Build with [Node.js](https://nodejs.org/en/) (14 or 16) and [Rush](https://rushjs.io/). |
| 14 | + |
| 15 | +### Setup repository |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install -g @microsoft/rush |
| 19 | +git clone https://github.com/snowplow/snowplow-javascript-tracker.git |
| 20 | +rush update |
| 21 | +``` |
| 22 | + |
| 23 | +## Package Installation |
| 24 | + |
| 25 | +With npm: |
| 26 | + |
| 27 | +```bash |
| 28 | +npm install @snowplow/browser-plugin-event-specifications |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +Initialize your tracker with the `EventSpecificationsPlugin`: |
| 34 | + |
| 35 | +```js |
| 36 | +import { newTracker } from '@snowplow/browser-tracker'; |
| 37 | +import { EventSpecificationsPlugin } from '@snowplow/browser-plugin-event-specifications'; |
| 38 | + |
| 39 | +newTracker('sp1', '{{collector}}', { plugins: [ EventSpecificationsPlugin(/* pluginOptions */) ] }); |
| 40 | + |
| 41 | +/* |
| 42 | + * Available plugin options `EventSpecificationsPluginOptions`: |
| 43 | + * { |
| 44 | + * [k in AvailablePlugins]: Keys for available plugins that have been added as integrations. |
| 45 | + * } |
| 46 | + */ |
| 47 | +``` |
| 48 | + |
| 49 | +### Getting the expected Event Specification options input |
| 50 | + |
| 51 | +The expected Event Specification option input can be retrieved directly from your Data Product in the [Snowplow BDP Console](https://console.snowplowanalytics.com) and would be similar to the following example: |
| 52 | + |
| 53 | +```js |
| 54 | +EventSpecificationsPlugin( |
| 55 | + SnowplowMediaPlugin: { play_event: 'event_specification_id' } |
| 56 | +); |
| 57 | +``` |
| 58 | + |
| 59 | +### Adding a new integration |
| 60 | + |
| 61 | +Every integration needs to satisfy the following interface: |
| 62 | + |
| 63 | +```ts |
| 64 | +export type Integration = { |
| 65 | + /** |
| 66 | + * Find a matching event for the integration with a plugin and an event specification id map. |
| 67 | + * The returned string should match what we expect as key coming from the configuration object on this specific plugin integration. |
| 68 | + */ |
| 69 | + detectMatchingEvent: (payloadBuilder: PayloadBuilder) => string | undefined |
| 70 | +} |
| 71 | +``` |
| 72 | +
|
| 73 | +The `detectMatchingEvent` function should return the key expected for the Event Specification input option of the integration. |
| 74 | +
|
| 75 | +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. |
| 76 | +
|
| 77 | +## Copyright and license |
| 78 | +
|
| 79 | +Licensed and distributed under the [BSD 3-Clause License](LICENSE) ([An OSI Approved License][osi]). |
| 80 | +
|
| 81 | +Copyright (c) 2024 Snowplow Analytics Ltd. |
| 82 | +
|
| 83 | +All rights reserved. |
| 84 | +
|
| 85 | +[npm-url]: https://www.npmjs.com/package/@snowplow/browser-plugin-event-specifications |
| 86 | +[npm-image]: https://img.shields.io/npm/v/@snowplow/browser-plugin-event-specifications |
| 87 | +[docs]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/javascript-tracker/ |
| 88 | +[osi]: https://opensource.org/licenses/BSD-3-Clause |
| 89 | +[license-image]: https://img.shields.io/npm/l/@snowplow/browser-plugin-event-specifications |
0 commit comments