Developer Documentation

The Osano consent management platform makes events available to developers so that you can easily implement additional logic based on the visitor's consent status (e.g. programmatically load scripts or 3rd parties once consent is received). 

Please note that utilizing these functions and events to modify or disrupt Osano's intended functionality could result in breaking changes in future iterations. 

Important: Osano.js must be the very first script in the document. Loading or injecting any other script prior to Osano may result in Osano being unable to ensure compliance with regional consent laws.

Available Functions

  • window.Osano.cm.addEventListener()
  • window.Osano.cm.removeEventListener()
  • window.Osano.cm.showWidget() 
  • window.Osano.cm.hideWidget() 
  • window.Osano.cm.showDialog() 
  • window.Osano.cm.hideDialog() 
  • window.Osano.cm.showDrawer() 
  • window.Osano.cm.hideDrawer()
  • window.Osano.cm.analytics // true or false 
  • window.Osano.cm.marketing // true or false 
  • window.Osano.cm.personalization // true or false 
  • window.Osano.cm.optOut // true or false
  • window.Osano.cm.getConsent() // { ESSENTIAL: ACCEPT ... etc. }
  • Osano.cm.mode

Events for the addEventListener function

  • osano-cm-initialized 
    • This event will dispatch when the CMP is initialized. The callback function receives a ConsentObject that indicates the current user's provided consent, or undefined when a user has not yet given consent. If the CMP has already initialized by the time a listener is added for this event, the callback is immediately fired with the appropriate argument.
  • osano-cm-consent-changed 
    • This event will dispatch when a user toggles a consent category. The callback function receives a ConsentObject with a single {key: value} pair indicating the category the user toggled. This event only indicates that a user has changed this option, and does not reflect the consent being saved. 
  • osano-cm-consent-saved 
    • This event will dispatch when the user saved their consent preferences. The callback function receives a ConsentObject that indicates the current user's provided consent.
  • osano-cm-script-blocked 
    • This event will dispatch when the CMP has blocked a script from being run in the user's browser. The callback function receives a string that indicates src of the script file that was blocked.
  • osano-cm-cookie-blocked 
    • This event will dispatch when the CMP has blocked a cookie from being set on the user's browser. The callback function receives a string that indicates name of the cookie that was blocked.

Using Events

Osano automatically prevents scripts with an src tag from loading until those scripts have been approved and categorized by the Osano administrator. Although Osano does prevent inline code from creating new scripts and iframes based on consent status and object categorization, Osano does not prevent inline code from executing, therefore it is generally recommended that developers do not implement event listening unless inline code needs to be triggered depending upon consent status.

Examples of situations that might require event listening are:

  • Your inline code writes an object such as a script or iframe to the document and expects that object to be immediately available.
  • Your inline code depends upon the availability of a script that might be blocked by Osano in certain regions until the consent has been granted by the visitor.
  • Your company loads content via AJAX/XHR or makes other content decisions dependent upon whether the user has granted consent (e.g. the text of the article should not be loaded until the visitors has accepted of denied)

The Osano.cm object is available immediately after the script in the document, you do not need to wait for the Osano.cm object to become available.

Example event after Osano has initialized

window.Osano.cm.addEventListener("osano-cm-initialized", function (consentObject) {
  if (consentObject.MARKETING === "ACCEPT") {
	//run marketing scripts
  }
});

Example event after a visitor changes their consent

window.Osano.cm.addEventListener("osano-cm-consent-saved", function (consentObject) {
  if (consentObject.PERSONALIZATION === "ACCEPT") {
	//run personalization scripts
  }
});

Consent object format

{  
	ANALYTICS: "ACCEPT",  
	MARKETING: "DENY",  
	PERSONALIZATION: "DENY",  
	ESSENTIAL: "ACCEPT"
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.