Developer guide for JavaScript methods

Avatar

By Manish Gautam

updated 6 days 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.

 

NameParametersDescription
sp.showPrivacyBanner();NoneForces the privacy banner to show.
sp.hidePrivacyBanner();NoneForces the privacy banner to hide.
sp.showTrustWidget(true);trueForces the trust widget to show.  
sp.hideTrustWidget();NoneForces the trust widget to hide
sp.showCookieBanner();NoneForces the cookie banner to show
sp.hideCookieBanner();NoneForces the cookie banner to hide
sp.hidePrivacyPolicy();NoneForces the privacy policy popup to hide
sp.showPrivacyPolicy();NoneForces 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);
NAThis 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", 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: { show : true/false } here "show: true" will be for trust badge is shown and show: false " will be for trust badge is hidden
 window.addEventListener("sp_cookie_banner", function (evt) { console.log(evt); }); 
NAThis method is used to add a listener to the window, that will get fired when cookie banner is shown,hidden, accepted or declined
the data which listener will get is
detail: { show : true/false, clicked: accept/reject }
here "show: true" will be for cookie banner is shown and "show: false " will be for cookie banner is hidden. here "clicked: accept" will be for user has clicked on cookie banner's accept button and "clicked: reject" will be for user did not clicked on cookie banner's accept button.
window.addEventListener("sp_privacy_banner", 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,hidden, saved or cancelled
the data which listener will get is
detail: { show : true/false, clicked: accept/reject }
here "show: true" will be for privacy banner is shown and "show: false " will be for privacy banner is hidden. here "clicked: accept" will be for user has clicked on privacy banner's Save button and "clicked: reject " will be for user clicked on privacy banners cancel button.
 window.addEventListener("sp_switch_lang", function (evt) { console.log(evt); }); 
NAThis 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 userLag is language name and category is on which banner language change has fired.
sp.cookieBannerVisible(); 
NAThis function will return true when the cookie banner is visible on the screen, otherwise, it will return false.


Did this answer your question?