Skip to main content

API Javascript

The Framework integrated within Avacy provides a series of Javascript APIs that can be called if necessary in the code or through the console of your browser. These functions allow interaction between the tools used by a publisher and the banner.

An example of use could be the creation of a button or link to reopen the preferences panel, if a user wants to review the preferences expressed:

<a href="#" onclick="AVACY.showPreferenceCenter('absolute');">Show preferences</a> 

It is also possible, during the testing and integration phases, to manually recall some events relating to the banner such as opt-in, opt-out and others, without there necessarily being user interaction.

The AVACY object is present within the window scope and, within it, there are the methods listed in the following table:

Event NameDescription
AVACY.triggerOptIn();Provides opt-in as if the user had accepted the Cookie Banner.
AVACY.triggerOptOut()Removes all set cookies and performs opt-out.
AVACY.reload()Reloads the configuration described in the initial object. Should be used after AVACY.triggerOptOut().
AVACY.showPreferenceCenter()Displays the Cookie Control Panel according to the mode chosen during banner configuration. The panel can be displayed in two modes: absolute: Shows the Control Panel in the same style and position as the initial Cookie Banner. In this case, there is no need to specify the div tag with id #oil-preference-center. inline: Shows the Control Panel exactly where the div tag is inserted. If no parameter is provided, the method defaults to “inline” and will show the Control Panel as the last visible element of the body if the div tag with id #oil-preference-center is present.
AVACY.getPurposeConsents()This method returns an object mapping the purposes given or not given. A promise is returned.
AVACY.hasConsents([purposeID_1, purposeID_2, ...])This method accepts an array as a parameter (default = []). It returns a boolean value: true: All provided purpose IDs have been accepted by the user; false: At least one of the provided purpose IDs has NOT been accepted by the user. A promise is returned.
AVACY.getLegalText(legalTextName = "cookie")This method returns an array containing the body and version of a legal text saved in the AVACY configuration object. It accepts (privacy or cookie). A promise is returned.
AVACY.changeLanguage(lang_code)Receives the language code of the desired language as a parameter and dynamically changes the language of the texts in the banner. If texts are not present in the configuration, default texts are used.

Change banner language

Another example of use of the API concerns the dynamic modification of the language, via the language attribute, which indicates the current language of the banner. The modification can be done statically, by modifying the configuration object with the desired lang code (in ISO 639-1) format (e.g. language: "en") or dynamic, via the AVACY.changeLanguage() function. If the selected language is not present in the configuration, the one set on the SaaS is used.

The autolanguage flag is a boolean value which, if set to true, automatically launches AVACY.changeLanguage() when the page loads, taking as parameter the value assigned to the language key.

The texts relating to the vendors and the legal texts are taken from a JSON present on the default CDN. This means that even if the selected language may not be present in the configuration object, these texts will still be translated (provided they are present on the CDN).