Javascript API
In this article, we will learn how to use the JavaScript API to interact with Cactusbanner.
The JavaScript API allows you to interact with Cactusbanner programmatically.
Befor being able to use the JavaScript API, you need to add the Cactusbanner JavaScript code to your website. To do that, you need to load the Cactusbanner JavaScript code in the <head>
section of your website.
<head>
<script src="https://js.cactusbanner.com/cactusbanner.js"></script>
</head>
The API exposes different methods. We will describe each method in this article.
boot()
The boot()
method allows you to bootstrap Cactusbanner on your website. You need to call this method to initialize Cactusbanner on your website.
The minimum option you need to provide is the appId
. The appId
is the unique identifier of your website. You can find the appId
in the website dashboard or in the settings.
window.cactusbanner('boot', {
appId: 'app_4Od0pRRJ'
});
The boot method also accepts the options:
option | type | default value | description |
---|---|---|---|
language | string | "auto" | The language of the banner. The default value is the language of the browser. |
properties | object | {} | Any properties you would like to pass to the banner. For example, you can pass if the user is under a specific plan. These properties will allow you to target specific banners to specific users. |
destroy()
The destroy()
method allows you to destroy Cactusbanner on your website. You need to call this method to unload Cactusbanner from your website. Your banners will not be displayed anymore.
window.cactusbanner('destroy');
update()
The update()
method allows you to update the options of the banner. You can update the language or the properties of the banner.
window.cactusbanner('update', {
language: 'en',
properties: {
trial: true
}
});
refresh()
The refresh()
method allows you to refresh the banner.
window.cactusbanner('refresh');