javascriptcookiessession-cookiesthird-party-cookiesone-trust

How is the OneTrust SDK installed in Javascript


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?


Solution

  • 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>