Concepts
Handlers
Handlers are executed by effects, when certain conditions are met.
The actual execution logic of handlers come from modules that are installed in your application.
Defining an effect with a handler#
Handlers are referenced inside the steps of an effect:
effects/myEffect.yml
# ...steps: - handler: module-name-here params: key: valueLearn more in effects page.
Module setup#
We can install the module module-pixel in our application to give a demo:
Command
$ npm install --save @eventvisor/module-pixelAnd then set it up when initializing the SDK:
import { createInstance } from "@eventvisor/sdk";import { createInjectScriptModule } from "@eventvisor/module-pixel";const eventvisor = createInstance({ modules: [ createPixelModule(), ],});Usage example#
From any of our effects, we can use this handler to inject a script into the page:
effects/myEffect.yml
# ...steps: - handler: pixel params: snippet: | <script> console.log("Hello world!"); </script> selector: bodyCreating custom handlers#
To create a custom handler, you can create a new custom module with at least the handle method implemented:
Defining module#
your-app/custom.ts
export function createCustomModule() { return { name: "custom", handle: async ({ effectName, step }) => { const { params } = step; console.log("Custom handler called for effect:", effectName); }, };};SDK setup#
And then set it up when initializing the SDK:
your-app/index.js
import { createInstance } from "@eventvisor/sdk";import { createCustomModule } from "./custom";const eventvisor = createInstance({ modules: [ createCustomModule(), ],});Handler usage#
Now from the effects, we can use the custom handler like this:
effects/myEffect.yml
# ...steps: - handler: custom params: key: value
