This article describes how to fire an event from your digital experience using the Evolv Javascript SDK.
Implementing events in the project code
There are two ways to implement events in your project using the Javascript SDK.
- Adding code to a context or variant using the Web Editor
- Adding code to a Custom Integration
Code added through the Web Editor will only be available to the project is it is added to. Whereas, code added through a custom integration is available to all projects.
In your code, use the SDK `client.emit` method to fire an event in your code, like this:
evolv.client.emit('event-name')
Example of a page interaction event:
var heroBtn = document.querySelector('.btn.homepageHero__button');
heroBtn.addEventListener("click", function() {
window.evolv.client.emit('youre-my-hero');
});
Example of a page view event:
// Send event on Product landing page load
window.evolv.client.emit('page.product_landing.loaded');
Implementing an event in Web Editor
- Open a project in the Web Editor.
- Select the context where you want to add the event.
- Events can also be added to a variant. However, events measuring a project's performance must be available to all variants, including Control.
- Add the code to the JavaScript panel.
Remember to check your events are firing correctly.