Use cases
Routing
Tracked events can be routed conditionally to multiple different destinations based on conditions in Eventvisor.
Challenges#
It is not uncommon that some applications may use multiple third-party analytics services or own custom backend services for tracking events serving different purposes.
For example, a web application may have these events:
Event | Intended destination |
---|---|
page_view | GA4 |
button_click | Google Tag Manager |
experiment_activation | Optimizely |
image_load_error | Sentry or Datadog |
It can grow out of hand pretty quickly, especially for a fast evolving application with a lot of events involving multiple teams.
Eventvisor destinations#
When using Eventvisor, we can define these destinations in a central place.
For example, we can define a destination called ga4
which will be used to track all the page_view
events:
description: GA4tags: - webtransport: ga4conditions: - source: eventName operator: equals value: page_view
We can also define a destination called gtm
for Google Tag Manager which will be used to track all the button_click
events:
description: Google Tag Managertags: - webtransport: gtmconditions: - source: eventName operator: equals value: button_click
Setting up transports#
In our application, when initializing the SDK, we can set up the right modules so that destinations can use them as transports.
Install them first:
$ npm install --save @eventvisor/module-ga4 @eventvisor/module-gtm
And then set them up when initializing the SDK:
import { createInstance } from "@eventvisor/sdk";import { createGA4Module } from "@eventvisor/module-ga4";import { createGTMModule } from "@eventvisor/module-gtm";const eventvisor = createInstance({ datafile: { ... }, modules: [ createGA4Module(), createGTMModule(), ],});
Here, we set up two modules:
- module-ga4 for GA4
- module-gtm for Google Tag Manager
Learn more in modules page, so you can also create your own custom integrations with other first or third-party services.
Tracking events#
Now it's just a matter of tracking the events from anywhere in the application, and the SDK will automatically handle the conditions and routing for you:
eventvisor.track("page_view", { url: "https://www.example.com",});
This will be routed to GA4 automatically.