Eventvisor

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:

events/pageView.yml
description: Print to browser console
tags:
- web
transport: 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):

Command
$ npm install --save @eventvisor/module-console

Setting up console module

And then set it up when initializing the SDK:

your-app/index.js
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:

destinations/browser.yml
# ...
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 payload
  • eventName: the name of the tracked event
  • attributes: all the accumulated attributes set using the SDK
  • destinationName: the name of the destination

If we were to prepare the JSON body for the destination, we could do something like this:

destinations/browser.yml
# ...
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:

// sources
const attributes = { userId: "user-123", deviceId: "device-456" };
const payload = { url: "https://www.yoursite.com/home" };
const eventName = "pageView";
// transforms
let 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:

events/pageView.yml
# ...
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:

destinations/myDestination.yml
# ...
archived: true
Previous
Events