Multiple OptanonConsent or OptanonAlertBoxClosed on Site (Delete Duplicate OneTrust Cookies)

Implement this script to delete all OneTrust cookies on all users' machines and require users to consent again. Once consent has been granted, the cookie will function as expected.

In the example below, replace .yourdomain.com with your organization's domain, including the . in front of the domain.

<script type="text/javascript">
var now = new Date();
now.setTime(now.getTime() + 1 * 3600 * 1000 * 24 * 365);
delete_cookie();

function delete_cookie() {

    if ( !getCookie('cleared-onetrust-cookies')) {
console.log("entered");
    document.cookie = "OptanonAlertBoxClosed" + "=" + "; path=/" + "; domain=.yourdomain.com" + '; expires=Thu, 01 Jan 1970 00:00:01 GMT';

    document.cookie = "OptanonConsent" + "=" + "; path=/" + "; domain=.yourdomain.com" + '; expires=Thu, 01 Jan 1970 00:00:01 GMT';
console.log("exit");
    }                          

    document.cookie = "cleared-onetrust-cookies" + "=" + "; path=/" + "; domain=.yourdomain.com" + "; expires="+now;
    console.log("test");

}

 

function getCookie( cookieName ) {

    var value = '; ' + document.cookie;

    var parts = value.split( '; ' + cookieName + '=' );     

    if ( parts.length == 2 ) {

    return true;

  }

}
</script>