InviteBox Javascript API

Hooks

InviteBox provides several hooks that can be used to perform actions when certain events occur in the widget:

  1. preInit event is triggered after InviteBox javascript is fully loaded, but before any initialization occurs. This hook is useful for altering configuration parameters (for example on per-page basis).

    Example: 

    var __ibq = __ibq || [];
    __ibq.push(['bind', 'preInit', function(){
        invitebox.setMessage('100 Christmas cocktails http://example.com/books/100-christmas-cocktails/');
    }]);
    __ibq.push(['bind', 'preInit', function(){ invitebox.setUrl('http://example.com/books/100-christmas-cocktails/'); }]);

    The first line in the example above is needed to make sure that the code executes correctly regardless of the script loading order (InviteBox javascript is loaded asynchronously so depending on where you place your hook code and on the browser, "invitebox" variable may or may not be already defined when your script executes).

  2. postInit event is triggered after the widget was initialized and possibly rendered (if applicable). This hook is useful when you want to programmatically alter the widget appearance or trigger a certain action.

    Example:

    var __ibq = __ibq || [];
    __ibq.push(['bind', 'postInit', function(){
         invitebox.show(); //Display invitebox right away when page is loaded rather than on button click.
    }]);

Labeling user with additional information

If you are implementing an automated reward mechanism in your own application using server-side reward callback API (see below), it's often useful to annotate every InviteBox user with additional information that would allow your application to identify the corresponding user record (such as your internal user id) when the reward mechanism is triggered. 

This is achieved using invitebox.setExtraVar(key, value) javascript call.

Code example:

var __ibq = __ibq || [];
__ibq.push(['bind', 'preInit', function(){
    invitebox.setExtraVar('user_id', '<user id from your application>');
}]);

SSO (Single Sign-On)

For goal-based and contest campaigns, InviteBox widget requires that the user “signs in” with their email address before participating (or to see their status). If your website already has user authentication in place (i.e. by the time the user gets to see InviteBox widget they’ve already entered their email/login) you can sign them in to InviteBox automatically by using invitebox.setEmail call.

Example:

var __ibq = __ibq || [];
__ibq.push(['bind', 'postInit', function(){invitebox.setEmail('example@example.com', 'name');}]);