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).

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 Events

  • osano-cm-initialized - called when the page has loaded regardless of whether the user has interacted with the consent dialog. Also called on page load if the user has previously granted consent.
  • osano-cm-consent-changed - called when the user preferences are changed
  • osano-cm-consent-saved - called when the user saves their consent preferences
  • osano-cm-script-blocked - called when a script is blocked (useful for debugging)

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 object is available immediately after the script in the document, you do not need to wait for the object to become available.

Example event after Osano has initialized"osano-cm-initialized", function (consentObject) {
  if (consentObject.MARKETING === "ACCEPT") {
	//run marketing scripts

Example event after a visitor changes their consent"osano-cm-consent-saved", function (consentObject) {
  if (consentObject.PERSONALIZATION === "ACCEPT") {
	//run personalization scripts

Consent object format

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.