Widget Javascript API

Open Widget from a Button

JavaScript method: mtr_conversion.OpenWidgetById(widgetId)

"widgetId" is found in Triggerbee while editing your Widget (parameter called bannerId in the URL)

Example:

mtr_conversion.OpenWidgetById(1426948364)

<a href="javascript:void(0)" onclick="mtr_conversion.OpenWidgetById(1426948364)">Open Widget (click me!)</a>

 

Open widget (click me!)

 

 

Listening to Events

If you choose not to use our templates and instead code the banners yourself there are a few events to which you can subscribe. This will not work in Internet Explorer 8 or earlier versions.

Add your own code to the following examples:

onWidgetOpened

The event is fired when a widget is opened. The event argument contains the following parameters:

  • widget_id - ID of the widget in Triggerbee
  • widget_title - Title of the widget in Triggerbee
if(document.addEventListener){
document.addEventListener("onWidgetOpened", function(event) {
// add your own code
console.log(event.widget_id);
});
}

onWidgetClosed

The event is fired when a widget is closed. The event argument contains the following parameters:

  • widget_id - ID of the widget in Triggerbee
  • widget_title - Title of the widget in Triggerbee
if(document.addEventListener){
document.addEventListener("onWidgetClosed", function(event) {
// add your own code
console.log(event.widget_id);
});
}

onWidgetMinimized

The event is fired when a widget is minimized. The event argument contains the following parameters:

  • widget_id - ID of the widget in Triggerbee
  • widget_title - Title of the widget in Triggerbee
if(document.addEventListener){
document.addEventListener("onWidgetMinimized", function(event) {
// add your own code
console.log(event.widget_id);
});
}

onWidgetMaximized

The event is fired when a widget is maximized. The event argument contains the following parameters:

  • widget_id - ID of the widget in Triggerbee
  • widget_title - Title of the widget in Triggerbee
if(document.addEventListener){
document.addEventListener("onWidgetMaximized", function(event) {
// add your own code
console.log(event.widget_id);
});
}

onWidgetBeforeFormSubmit

The event is fired before the form in your widget is submitted (when form input is valid according to eventual validation).
In the callback parameter there is a property "details" that contains information about the converted visitor's input values (see example below).
Some fields are going to be null since values are based on the fields in your widget. Exmaple: If your widget has an input for email, you would get a value in console.log(e.details.email)

The event argument contains the following parameters:

  • widget_id (number) - ID of the widget in Triggerbee
  • widget_title (string) - Title of the widget in Triggerbee
  • details (object) - Data from the form that is submitted. Available properties are: name, email, organization, telephone, goal
document.addEventListener("onWidgetBeforeFormSubmit", function(e) { 
// add your own code
console.log(event.details);

/* Example output:
e.details = {
name:'Erlich Bachman',
email:'erlich@piedpiper.com',
organization:'Piedpiper'
telephone:'0123456789',
goal:'Order' // Name of the goal for this conversion
}
*/
});

 

Global settings

Disable hash in URL

By default Triggerbee Widgets adds a hash to the URL when a Widget is opened. This allows a visitor to re-open the widget using the browser history (go back and forth). You can disable this behavior using the mtrDisableHashtags setting.

window.mtrDisableHashtags = true;