Skip to main content
The BlueConic Event API
Updated this week

This article explains how to work with custom events in BlueConic, covering two key scenarios: triggering dialogues with events created via the JavaScript API, and using the event.publish method for tracking custom interactions. Both methods empower you to capture a wider range of user behavior and use that data to personalize the visitor experience.

Using the event.publish method for customer events

The BlueConic JavaScript API provides the event.publish method to create custom events. While standard HTML events (like clicks) can often be tracked using built-in BlueConic features (e.g., "Click" rules in Behavior Listeners), many user interactions don't trigger these standard events. Examples include interactions with video players (e.g., pressing "Play") or social media buttons (e.g., "Facebook Like").

The event.publish method addresses this gap, allowing developers to define and track these custom interactions.

Example Scenario:

You want to track when a visitor watches a specific video. The video player's developer can use event.publish to create a custom event when the "Play" button is clicked:

window.blueConicClient.event.publish('play_button_clicked',['my Homevideo']);

This code publishes an event named play_button_clicked with the parameter my Homevideo indicating which video was played.

Once an event is published using event.publish, you can configure a Behavior Listener within the BlueConic UI to subscribe to it. This allows you to capture information about the event and use it to enrich visitor profiles.

How to use the BlueConic JavaScript API to publish and subscribe to custom events in BlueConic

In the video playback example, you could configure a Behavior Listener to subscribe to the play_button_clicked event and then set a profile property indicating that the visitor watched "my Homevideo."

See the BlueConic JavaScript API reference for events for details.

Triggering Dialogues with JavaScript-Created Events

While you can use the JavaScript API to throw events (by using the createEvent() method), these events must also be defined within the platform's UI via an Event Trigger Listener before they can be used to trigger dialogues or other actions.

Example Scenario:

You call the createEvent() method to trigger a custom event named myCustomEvent:

this.blueConicClient.createEvent('myCustomEvent', this, function(result) { console.log('event successfully registered'); });

Then, you attempt to use myCustomEvent to trigger a dialogue but cannot find it in the dialogue's "When" tab event list.

The solution is to create a temporary Event Trigger Listener. In the "define event" input box, type the exact name of your custom event (e.g., myCustomEvent). This action registers the event within the UI. Save the Event Trigger Listener to officially create the event within the platform.

You can now select myCustomEvent in the dialogue's "When" tab.

Once the event is associated with the dialogue, you can delete the temporary Event Trigger Listener if desired.

Did this answer your question?