Onsite Campaigns Javascript API

Javascript API

Open a widget

This snippet allows you to open a certain widget by its ID. 

triggerbee.widgets.api.open(widgetId)

Close a widget

This snippet allows you to close a certain widget by its ID. 

triggerbee.widgets.api.close(widgetId)

Initiate the widgets

This snippet allows you to initiate the widget script.

triggerbee.widgets.api.init()

Note: This is done by default on page load. The snippet is only required for SPA sites.


Javascript Events

This is a list of the current Javascript Events for Onsite Campaign widgets. These are useful for creating your own functions and action based on events in widgets. 

For each event, there are different output data that you can use in your code. These 3 are available for all events. See what other output data is available under each event.

  • id: ID of the widget triggering the event
  • campaignName: Name of the campaign of the widget triggering the event
  • campaignId: ID of the campaign of the widget triggering the event

onTriggerbeeWidgetOpened

The event is fired when an Onsite Campaign widget is opened. 

document.addEventListener("onTriggerbeeWidgetOpened", function (event) {
    console.log(event.detail);
    // Example output: 
    /*
        {
            id: 1103,
            campaignName: "Newsletter sign up",
            campaignId: 1059
        }
    */
});

onTriggerbeeWidgetClosed

The event is fired when an Onsite Campaign widget is closed. 

document.addEventListener("onTriggerbeeWidgetClosed", function (event) {
    console.log(event.detail);
    // Example output: 
    /*
        {
            id: 1103,
            campaignName: "Newsletter sign up",
            campaignId: 1059
        }
    */
});

onBeforeTriggerbeeFormSubmitted

The event is fired  before a form in an Onsite Campaign widget is submitted. 

document.addEventListener("onBeforeTriggerbeeFormSubmitted", function (event) {
    console.log(event.detail);
    // Example output:
    /*
        {
            id: 1103,
            campaignName: "Newsletter sign up",
            campaignId: 1059
        }
    */
});

onAfterTriggerbeeFormSubmitted

The event is fired  after a form in an Onsite Campaign widget is submitted.

document.addEventListener("onAfterTriggerbeeFormSubmitted", function (event) {
    console.log(event.detail);
    // Example output:
    /*
        {
            id: 1103,
            campaignName: "Newsletter sign up",
            campaignId: 1059
        }
    */
});

onTriggerbeeWidgetButtonClicked

The event is fired when a button in an Onsite Campaign widget is clicked.

document.addEventListener("onTriggerbeeWidgetButtonClicked", function (event) {
    console.log(event.detail);
    // Example output:
    /*
        {
            id: 1103,
            campaignName: "Newsletter sign up",
            campaignId: 1059,
            url: "http://example.com?utm_custom=Newsletter+sign+up"
        }
    */
});

onTriggerbeeWidgetStateSwitched

The event is fired when there's a change of slide in an Onsite Campaign widget. 

document.addEventListener("onTriggerbeeWidgetStateSwitched", function (event) {
    console.log(event.detail);
    // Example output:
    /*
        {
            id: 1103,
            campaignName: "Newsletter sign up",
            campaignId: 1059,
            stateId: 1213
        }
    */
});

triggerbeeTagAdded

The event is fired when a tag has been added to the session.

document.addEventListener("triggerbeeTagAdded", function (event) {
        console.log('tag: ' + event.detail.name);    
});

triggerbeeGoalAdded

The event is fired when a goal has been set on the session.

document.addEventListener("triggerbeeGoalAdded", function (event) {
        console.log('goal: ' + event.detail.name);    
});
Did this answer your question? Thanks for the feedback! Please reach out to [email protected] if there's anything you'd like to add. There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us