3

I am trying to run the following line of code

  OneTrust.OnConsentChanged(() => {
        alert("consent changed");
    });

As expected, I am getting the error message: 'OneTrust' is not defined.

However I cannot find anywhere in the OneTrust docs that explain how to import the OneTrust object.

The function above is found in these docs.

Please could someone explain how to import the OneTrust object?

WhatThe22
  • 33
  • 5

1 Answers1

2

Try

window.OneTrust.OnConsentChanged(() => {
        alert("consent changed");
    });

SDK starting to be available after the scripts of OneTrust were loaded inside <head> tag as :

<head>
    <script type="text/javascript" charset="UTF-8" data-domain-script="xxxxx-xxxxx-xxxxx-xxxxx" src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"></script>
    <script type="text/javascript">function OptanonWrapper() {}</script>
// rest of the elements inside head tag
</head>
Pv-Viana
  • 632
  • 7
  • 25
  • 1
    Thank you, this was my solution in the end, however as I was implementing this into a BigCommerce store, I added this code to the scripts within the BigCommerce admin panel. – WhatThe22 Jan 06 '23 at 10:14