Callbacks

You can register named global functions that are called on certain events.

On User Has Access

If, according to our records, a user should have access to the current article, this callback function is called.

Example:

<meta property="laterpay:connector:callbacks:on_user_has_access" content="myGlobalCallbackFunction">

<script type="text/javascript">
  function myGlobalCallbackFunction() {
    alert("Congratulations, you have access to this content!");
  }
</script>

In this example, the function myGlobalCallbackFunction() function will be called if the user has access to the paid content on the current page.

On Access Denied

If, according to our records, a user should be denied access to the current article, this callback function is called.

The function receives two parameters:

  • done Callback function
  • context Either “Paid Content” or “AdVantage”

The done callback allows for asynchronous continuation control of Connector Script: In most cases, you should call it eventually to allow Connector Script to continue. However, you can choose not to call it and thus prevent the rendering of either the Paid Content Replacement or the AdVantage Overlay.

Access can be denied in two contexts:

  • Paid Content: The user has not purchased a Single Purchase, Time Pass or Subscription.
  • AdVantage: AdVantage is active and an adblocker has been detected.

Example:

<meta property="laterpay:connector:callbacks:on_access_denied" content="myGlobalCallbackFunction">

<script type="text/javascript">
  function myGlobalCallbackFunction(done, context) {
    alert("Access was denied in the context of "+context);
    done();
  }
</script>

In this example, the function myGlobalCallbackFunction() function will be called if the user is denied access to the current page.

On Tracking Event

Deprecated since version 2.12.0.

Warning

This callback is deprecated, because it has been renamed to On Analytics Event.

It will be removed in the next major release of Connector Script (version 3).

On Analytics Event

This callback function is called when analytics events are triggered. It allows for a Custom Analytics Integration.

The function receives two or three parameters:

  • eventAction The Event Action, for example “AdVantage Show”
  • done Callback function
  • data (Optional) Additional Event Data, for example details of a purchase item. Only passed for some Event Actions, see section Event Actions for details.

By default, Connector Script sends a triggered Event Action to all detected analytics services (see Automatic Analytics Integration). Return false to suppress the default behavior.

Note

When suppressing the default behavior (by returning false), you should call the done callback eventually. Otherwise, Connector Script will not be able to continue to current task, for example redirect to the purchase page after a user has clicked a purchase button.

Example:

<meta property="laterpay:connector:callbacks:on_analytics_event" content="handleConnectorAnalyticsEvent">

<script>
  function handleConnectorAnalyticsEvent(eventAction, done, data) {
    console.log("Received event action from Connector: "+eventAction);
    console.log(data);
    setTimeout(done, 1000); // Symbolic for "do some asynchronous task"
    return false;
  }
</script>

In this example, the function handleConnectorAnalyticsEvent() will be called when analytics events are triggered. The function logs the Event Action and all additional Event Data.

By returning false, the function suppresses Connector Script’s default behavior. The continuation of Connector Script is triggered after one second, which is symbolic in this example for “do some asynchronous task”.