Access the Javascript SDK on your website
When loaded on your website, Axeptio exposes a JS instance of our SDK class, which contains useful methods and information. With this object, you can customize properties at runtime or display any widget configured in your project.
Use a callback function to get a reference to the SDK
Since the SDK is loaded asynchronously, it may not be available when you execute your own code. To be notified when the axeptioSDK object is ready, you should use a variable named _axcb (for Axeptio Callbacks). Here is a code snippet:
window._axcb = window._axcb || [];window._axcb.push(function(sdk){ // here, you will be able to access the methods and properties // of the Axeptio SDK instance.});On the first line, we access the _axcb array if it already exists, or we create it. This is a shorthand technique for "access or create" a variable in JavaScript.
Then, we add a callback function to this array using the push() method. The contents of this function will be executed only once the Axeptio script is loaded and the project configuration has been retrieved from our CDN. Don't worry if Axeptio is already loaded, your callback function will then be called immediately.
Alternative: use the window.axeptioSDK object
When Axeptio is ready, it creates several methods and objects directly in the global scope window.
axeptioSDK: instance of the SDK object.
axeptioBuildTimestamp: date and time of the SDK script build. Used to resolve cache issues.
openAxeptioCookies(settings): call this function to open the cookies widget. You can pass an object with additional parameters, such as
currentStepIndex,onComplete,onEvent,userChoices. If you need help using these parameters, contact us.showAxeptioButton(): this function displays the Axeptio button in the corner of the page, if it is hidden.
hideAxeptioButton(): this function hides the Axeptio button in the corner of the page, if it is visible.
Since the Axeptio SDK may not be loaded when you execute your own code, we recommend using the callback function method.
Anatomy of the Axeptio SDK
Methods
sdk.openCookies(settings)
Alias of openAxeptioCookies, this method opens the consent widget for the current cookiesVersion.
sdk.createConsentCheckbox()
Creates a checkbox for a corresponding data processing widget.
sdk.createConsentButton()
Creates a consent button for a corresponding data processing widget.
sdk.setCookiesVersion(version)
Specifies the version of cookies to use. This method can be used at runtime to change language, for example.
sdk.setToken(token)
Specifies the user token to use for subsequent consent collections.
sdk.getToken()
Returns the Axeptio user token for the current session.
sdk.hasAcceptedVendor(vendor)
Returns a boolean indicating whether the user has accepted the use of a specific service.
Note: the service is a string identifier that you can define in the Axeptio administration.
sdk.requestConsent(vendor, onConsent)
Requests consent for a specific service. Returns a promise that resolves when consent is granted and is rejected when it is not.
Properties
sdk.settings
An object containing SDK settings (related to the website).
sdk.userPreferencesManager
An object containing preferences and utility methods for managing user preferences.
sdk.config
The complete configuration generated by our API when the project is published.
sdk.template
The template project used if Axeptio is integrated with a specific service (Typeform, etc.).
