secureprivacy.ai

Secure Privacy Support Center

Search for any help questions or topics.

Developer guide for JavaScript methods

The Secure Privacy script loads a client-side JavaScript object named 'sp' which exposes the following public methods, use these methods for advanced implementations
Avatar
Andrew Sidorkin
Updated 5 months ago

The Secure privacy script loads a client-side JavaScript object named 'sp' which exposes the following public methods.
Use these methods optionally to trigger your banners.


Name

Parameters

Description

sp.showPrivacyBanner();

None

Forces the privacy banner to show.

sp.hidePrivacyBanner();

None

Forces the privacy banner to hide.

sp.showTrustWidget(true);

true

Forces the trust widget to show.  

sp.hideTrustWidget();

None

Forces the trust widget to hide

sp.showCookieBanner();

None

Forces the cookie banner to show

sp.hideCookieBanner();

None

Forces the cookie banner to hide

sp.hidePrivacyPolicy();

None

Forces the privacy policy popup to hide

sp.showPrivacyPolicy();

None

Forces the privacy policy popup to show

sp.switchLanguage('lang_code');

None

This method changes the language of all the banners. You need to pass 2 character language code, for example, 'en' or 'sv'. lang_code must be any language code that is activated for that domain.

sp.switchLanguage('lang_code',
'cookieBanner');

None

This method changes the language of the cookie banner. It overrides all the default settings and forces the cookie banner to show.

window.addEventListener(
"sp_init",
function (evt) {
console.log(evt.detail);
}, false);

NA

This method is used to add a listener to the window, that will get fired when secure privacy is all initialized.

window.addEventListener(
"sp_trust_badge_shown",
function (evt) {
console.log( evt);
});

NA

This method is used to add a listener to the window, that will get fired when trust badge is shown or hidden
the data which listener will get is {detail : true/false } here "detail: true" will be for trust badge is shown and "detail: false" will be for trust badge is hidden

window.addEventListener(
"sp_cookie_banner_shown",
function (evt) {
console.log(evt);
});

NA

This method is used to add a listener to the window, that will get fired when cookie banner is shown or hidden. the data which listener will get is
detail: { true/false }
here "detail: true" will be for cookie banner is shown and "detail: false " will be for cookie banner is hidden.

window.addEventListener(
"sp_cookie_banner_click",
function (evt) {
console.log(evt);
});

 

NA

This method is used to add a listener to the window, that will get fired when cookie banner's buttons is clicked. the data which listener will get is
detail: { accept/reject }
here "detail: accept" will be for user has clicked on cookie banner's accept button and "detail: reject" will be for user clicked on cookie banner's reject button.

window.addEventListener(
"sp_cookie_banner_save",
function (evt) {
console.log(evt);
});

NA

This method is used to add a listener to the window, that will get fired when cookie banner's buttons is clicked and it is saved. the data which listener will get is
detail: { accept/reject }
here "detail: accept" will be for user has clicked on cookie banner's accept button and it is saved and "detail: reject" will be for user clicked on cookie banner's reject button and it is saved.

window.addEventListener(
"sp_privacy_banner_shown",
function (evt) {
console.log(evt);
});

 

NA

This method is used to add a listener to the window, that will get fired when privacy banner is shown or hidden. the data which listener will get is detail: { true/false } here "detail: true" will be for privacy banner is shown and "detail: false" will be for privacy banner is hidden.

window.addEventListener(
"sp_privacy_banner_click",
function (evt) {
console.log(evt);
});

 

 

NA

This method is used to add a listener to the window, that will get fired when privacy banner's buttons is clicked. the data which listener will get is
detail: { accept/reject }
here "detail: accept" will be for user has clicked on privacy banner's accept button and "detail: reject" will be for user clicked on privacy banner's reject button.

window.addEventListener(
"sp_privacy_banner_save",
function (evt) {
console.log(evt);
});

 

NA

This method is used to add a listener to the window, that will get fired when privacy banner's buttons is clicked and it is saved. the data which listener will get is
detail: { accept/reject }
here "detail: accept" will be for user has clicked on privacy banner's accept button and it is saved and "detail: reject" will be for user did clicked on privacy banner's reject button and it is saved.

window.addEventListener(
"sp_switch_lang",
function (evt) {
console.log(evt);
});

NA

This method is used to add a listener to the window, that will get fired when user changed language in privacy banner
the data which listener will get is
detail: { useLang: "en", category: "privacy-banner" }
here useLang is language name and category is on which banner language change has fired.

sp.cookieBannerVisible(); 

NA

This function will return true when the cookie banner is visible on the screen, otherwise, it will return false.

sp.savePluginConsent(pluginName);
 

pluginName

This method can be used to save consent for any particular plugin. The pluginName parameter expects a plugin name of type string.

sp.allGivenConsents

NAThis object can be used to get all the consent of any user. This value is available on the window after the user has given consent.

This JS object can be used to check the status of user consent and pass it to the Server
 window.addEventListener( "sp_unblock_Adobe", function (evt) { console.log(evt); },false); 
NAThis event listener can be used to listen to unblock events of each Service name.

The name of the event listener can be changed to reflect the Service name that you want to listen to.

The Service names should be exactly the same as shown on the Scan Report.

In case of spaces, replace it with an underscore (_)

For example -

To listen to Google Analytics you can use

sp_unblock_Google_Analytics


sp.checkConsent(pluginName) {}

pluginName

This method can be used to check consent for any particular plugin. The pluginName parameter expects a plugin name of type string.


The return type of this function is boolean.


 

Was this article helpful?
😞 😐 😃