Building blocks
Destinations
Destinations are where the tracked events using Eventvisor SDKs are sent to. The means of reaching there are called transports, which are made available as modules.
Examples#
Depending on the type of your application, examples of destinations can be:
- Console (browser's or node.js server's console)
or integration with third-party services:
- GA4 (Google Analytics 4)
- Google Tag Manager
- Sentry
- Segment
- Datadog
- ...etc
or your own custom backend service.
Defining destinations#
If we choose to define a new destination called browser
, we can create a new file called browser.yml
in the destinations
directory:
description: Print to browser consoletags: - webtransport: console
Transports#
Above, browser
is nothing but a name for the destination. To reach that destination, we defined console
as the transport.
Transports are available as modules, and we already have one for browser and node.js console.
You are of course free to create your own transports as modules too.
Installing console module#
We will install the desired console module in our application(s):
$ npm install --save @eventvisor/module-console
Setting up console module#
And then set it up when initializing the SDK:
import { createInstance } from "@eventvisor/sdk";import { createConsoleModule } from "@eventvisor/module-console";const eventvisor = createInstance({ modules: [ createConsoleModule(), ],});
Viewing tracked events#
As you track events in your application using Eventvisor SDKs, you will see the events being printed to the console.
Conditions#
Conditions defined at individual destination level helps control which events are transported to the that destination.
This will act as a filter:
# ...conditions: - source: eventName operator: equals value: pageView
Learn more about sources and conditions to make the most of it.
Transforms#
Transforms defined at individual destination level helps manipulate the event payloads before they are transported.
Besides the event payload itself, there are certain variables that are available as sources in the transformation layer that you can make use of. Some of them are:
payload
: the tracked event's payloadeventName
: the name of the tracked eventattributes
: all the accumulated attributes set using the SDKdestinationName
: the name of the destination
If we were to prepare the JSON body for the destination, we could do something like this:
# ...transforms: # start with an empty object - type: set value: {} # spread the event's payload - source: payload type: spread # spread the current attributes - source: attributes type: spread # set the event's name - source: eventName type: set target: event
Doing above is the equivalent of running this in JavaScript:
// sourcesconst attributes = { userId: "user-123", deviceId: "device-456" };const payload = { url: "https://www.yoursite.com/home" };const eventName = "pageView";// transformslet body = {};body = { ...body, ...payload };body = { ...body, ...attributes, };body.event = eventName;
The resulting body will then look like this in the end when it is handled by the relevant transport:
{ "url": "https://www.yoursite.com/home", "userId": "user-123", "deviceId": "device-456", "event": "pageView"}
Learn more in transforms page for complex use cases.
Sample#
Instead of sending all tracked events to the individual destination, you can sample a certain percentage of your events based on certain criteria..
Defining sampling rules is how you can achieve that:
# ...sample: by: attributes.deviceId percentage: 10 # 10% of the unique devices
See more advanced sampling rules in sampling page.
Archiving#
You can archive a destination by adding archived: true
to the destination definition:
# ...archived: true