Skip to main content
POST
/
addPrivacyConsentListener
Add privacy consent listener
curl --request POST \
  --url https://js.hs-scripts.com/addPrivacyConsentListener \
  --header 'Content-Type: application/javascript' \
  --data @- <<EOF
"_hsq.push(['addPrivacyConsentListener', function(consent) { console.log('Consent status:', consent); }]);"
EOF
Check the consent status of the visitor when using the privacy consent banner.

Usage

var _hsq = (window._hsq = window._hsq || []);
_hsq.push([
  "addPrivacyConsentListener",
  function (consent) {
    // Handle consent status
    if (consent.allowed) {
      console.log("Consent granted");
      // Enable additional tracking or analytics
    } else {
      console.log("Consent denied");
      // Disable additional tracking
    }
  },
]);

Parameters

The callback function receives a consent object with information about the visitor’s consent status:
  • allowed (boolean): Whether the visitor has granted consent
  • Additional properties may be available depending on the consent banner configuration

Use Cases

  • Conditionally enable third-party analytics based on consent
  • Show/hide certain features that require tracking
  • Customize user experience based on privacy preferences
  • Comply with GDPR and other privacy regulations

Body

application/javascript

Consent listener callback

callback
string

Callback function to handle consent status

Response

200

Consent listener added successfully