Using Our SDK
The OptiPub SDK exposes a global "optipub()" function that is available on any page where it is installed. This function allows for you to perform some basic commands that will report back to your installation of OptiPub.
All of the commands follow the same basic structure:
optipub('action', 'command');
optipub('action', 'command', 'parameter');
Advanced Usage
All of the OptiPub SDK commands return a Promise. See the Advanced Usage section for more information.
Available Commands
Command | Parameters | Description |
---|---|---|
"email" | Email Address | Associates an email address with the tracking identifier that is generated from the SDK. |
"sale" | Revenue | Records a sale with the revenue amount for revenue reporting. |
The "Email" Command
optipub('record', 'email', '[email protected]');
You are encouraged to use the "email" command any time that you are able to identify an email address for the user that is accessing your website. While users are visiting your website, we assign them a temporary identifier. When an email gets recorded, the tracking system updates their identifier and makes the appropriate association with the old identifiers.
The "Sale" Command
optipub('record', 'sale', 299.99)
OptiPub allows you to record revenue from your email marketing campaigns through the "sale" command.
In order to use revenue tracking through OptiPub, you need to make sure this command reports all of the sales as they occur.
This command requires that a user have a "message_id" and "link_id" be set before being considered a valid sale.
Fraud Protection
In order to be as accurate as possible, OptiPub records the following information about a sale: "link_id," "message_id," "revenue," and "tracking_identifier."
If all of these values are identical between two reported sales, OptiPub discards the new information. This prevents a single user from firing multiple sale events with the same information.
Fractions
The sale command is designed to be used for monetary transactions. Fractions of a penny will be rounded to the nearest penny.
Multiple Transactions
It is not impossible for a user to make more than one purchase after following a single link. The user will have only a single "message_id" and "link_id" for the session. In order to ensure that additional valid sales are recorded, it is recommended to pass a different revenue "amount" in the third parameter of the command for each transaction a user might encounter.
Advanced Usage
All of the OptiPub SDK Commands return a Promise after the SDK has finished loading on the page. To verify that the SDK has been loaded, an "OptiPubSdkReady" CustomEvent is available on the "window" DOM interface.
This allows for you to add an event listener on the "OptiPubSdkReady" event in order to reliably return a Promise called synchronously during page load.
We recommend that you call the OptiPub SDK Commands asynchronously from the page load.
// Embedded script that fires on page load.
window.addEventListener('OptiPubSdkReady', () => {
optipub('record', 'sale', 299.99).then(() => {
// success
console.log('Sale has been recorded. Redirect to another page.');
}, () => {
// error
console.log('An error occured when recording the sale.');
});
});
// Script that fires from an event after the page has loaded.
optipub('record', 'sale', 299.99).then(() => {
// success
console.log('Sale has been recorded. Redirect to another page.');
}, () => {
// error
console.log('An error occured when recording the sale.');
});
Polyfills Not Provided
The OptiPub SDK does not have any polyfills for Promises nor CustomEvents, both of which currently are not supported in Internet Explorer. If you would like to leverage this advanced functionality, and have greater browser support, you will need to provide your own polyfills.
Updated 11 months ago