Skip to main content

Dynamic Loading of Configurations via Custom Code

Written by Manon Manso

This article is part of the series Adapt your banner to each version of your site.

Before following the guide below, make sure you have reviewed the general introduction article Choose the appropriate method to load the correct Axeptio banner.

  • Via the browser language:

// Replace the value 000000000000000 with your id 
window.axeptioSettings = { clientId: '000000000000000', cookiesVersion: { type: "browser_locale", cases: {
default: "-en", "fr-FR": "-fr",
"it-IT": "-it", } }};(function(d, s) { var t = d.getElementsByTagName(s)[0], e = d.createElement(s); e.async = true; e.src = "//static.axept.io/sdk.js"; t.parentNode.insertBefore(e, t);})(document, "script");
  • Via a custom function:
    For example, based on the "lang" parameter of the page

// Replace the value 000000000000000 with your id 
window.axeptioSettings = {
clientId: '000000000000000',
cookiesVersion: {
type: "custom_function",
config: {
function: () => {
return document.documentElement.lang;
}
},
cases: {
default: "-en",
"fr-FR": "-fr",
"it-IT": "-it",
}
}
};

(function(d, s) {
var t = d.getElementsByTagName(s)[0], e = d.createElement(s);
e.async = true; e.src = "//static.axept.io/sdk.js";
t.parentNode.insertBefore(e, t);
})(document, "script");

The name of the version to enter for each case (in the examples above: "-en", "-fr", "-it") can be found here:

Special case for sites without page reload: managing dynamic update of Axeptio configuration

On certain modern sites, such as single-page applications (SPAs) where changing the language does not reload the page, the Axeptio banner remains frozen in the initial language.

To handle this case, you can use a JavaScript function from the Axeptio SDK that allows you to change the widget language on the fly, without reloading the page.

This manipulation requires some code and is intended for an audience with technical knowledge. For most traditional sites where the language is linked to the URL and triggers a reload, this step is not necessary.

Where you perform your language change in JavaScript, you will need to add the Axeptio function axeptioSDK.setCookiesVersion(), to change the widget version dynamically.

This function takes as a parameter the identifier of the version to load.

For example, I have three versions here:

Capture_d_e_cran_2022-08-25_a__15.34.42.png

The identifiers of my three versions are "it-version", "fr-version", and "en-version".

If I translate my site into Italian, I just need to call the function axeptioSDK.setCookiesVersion('it-version').

Did this answer your question?