The current version of the Promoboxx Javascript API is:

0.6.5

Please use the latest API version on new projects to ensure all known bugs are fixed and all documented features are available. See the Initialization chapter for API link code syntax.

(Note: Live projects should be thoroughly tested when upgrading.)

Initialization

Basic initialization of the Promoboxx JSAPI on a web page requires linking to the jsapi endpoint for the current version and executing a few commands in javascript. The annotated code snippet below illustrates basic initialization.

<!-- Push JSAPI initialization commands into a buffer -->
<script>
  // Assign a blank array to the _pbxx variable to act as a command buffer
  var _pbxx = _pbxx || [];
  // Push the Facebook-supplied encoded hash that is passed when this
  // page is loaded within a Facebook Tab (PHP version)
  _pbxx.push([
    'fbSignedRequest',
    '<?=isset($_POST["signed_request"])?$_POST["signed_request"]:"" ?>'
  ]);
  // Initiate campaign data retrieval with the 'load' command and campaign key
  _pbxx.push(['load','xxxxxxxxxxxx']);
  // Instruct the JSAPI to track the page view
  _pbxx.push(['track','view']);
</script>
<!-- Load the Promoboxx JSAPI script -->
<script src="https://www.promoboxx.com/jsapi/0.6.5/pbxx.js"></script>

This code sample features two html script tags. The first contains javascript statements that initialize the JSAPI script. This script block could also be located after the second script tag.

var _pbxx = _pbxx || [];

The second included javascript statement passes Facebook information from server variables to the Promoboxx script.

_pbxx.push(['fbSignedRequest','<?= isset($_POST["signed_request"]) ? $_POST["signed_request"] : "" ?>']);"

This line is necessary for identifying retailers when the page is loaded within a Facebook page tab. The second argument in this statement contains a php snippet that should be altered if the page is hosted on a server that doesn't support php. The second statement may be omitted altogether if the page won't be distributed as a Facebook Tab.

The third statement instructs the object to load campaign-specific data. It should contain the relevant campaign key (in place of xxxxxxxxxxxx), which is available from the Promoboxx Control Panel.

_pbxx.push(['load','xxxxxxxxxxxx']);

The second script tag loads the Promoboxx JSAPI library. When designing new campaign pages, be sure to adjust the version number (0.6.5 in this example) to pull the latest stable version.

<script src="https://www.promoboxx.com/jsapi/0.6.5/pbxx.js"></script>