SDK Extension Points - API Event Hooks


Event hooks allow you to run your own code during different stages of the ForeSee® Trigger Code lifecycle, as well as request a Boolean about whether a particular ForeSee® Trigger Code lifecycle event has been executed.


Sample API Hook Use Cases

  • You want to alert a Thank You message once the customer accepts the ForeSee invite.
  • You want to know whether an invite has already been presented.

Available Event Hooks:

  • onLoaded - Fired after trigger code has been loaded.
  • onInitialized - Fired after trigger code base been initialized.
  • onInviteShown - Fired after the invite has been presented.
  • onInviteAccepted - Fired if the invite has been accepted.
  • onInviteDeclined - Fired if the invite has been declined.
  • onTrackerShown - Fired after the tracker window is shown.
  • onFeedbackSubmitted - Fired when a Feedback Survey is submitted, and contains the data object including scores and comments.

Event Hook API:

  • .didFire – Checks if the event has happened. Returns a Boolean true or false.
  • .subscribe(cb, once, stragglers) – Executes your callback function once the event has happened. Returns a subscription object.
    • cb – Optional parameter. A function that is executed once the event fires. Is also executed immediately if the event has fired and the stragglers flag is set to true.
    • once – Optional parameter. Defaults to false. If set to true, creates a one time subscription that is removed once the event has fired.
    • stragglers – Optional parameter. Defaults to false. If set to true, fires the event again for this callback if it has already fired once before.

Sample Usage:

The code below can be used to present an alert after the invite has been accepted. Since the once flag is set to true, the subscription is deleted after the event has fired once. Since the stragglers flag has been set to true, the callback is executed even if the invite has already been accepted by the time the subscription is created.

// This should appear below the ForeSee Embed Snippet

fsReady(function(){
  FSR.onInviteAccepted.subscribe(
    function() {
      alert('Thank you for accepting our invite!');
    }, true, true
  );	
});

Other articles in this section:

  1. Getting Invitation Status
  2. API Event Hooks (current article)