Cookiebot callbacks and event listeners
In our Developer documentation we have listed a number of events which you can hook into that are fired during the execution of the uc.js script:
You can use these events in an event listener similar to this:
Similarly, we also have a list of callback functions which are called when the corresponding events are fired:
You can define a callback function similar to this:
As the Cookiebot script is loading, it will check if these functions have been defined, and call them at the appropriate time if this is the case.
Confusion surrouding the CookiebotOnLoad event and the CookiebotCallback_OnLoad callback
The purpose of both the CookiebotOnLoad event and the CookiebotCallback_OnLoad callback is often misunderstood. The "load" implied here doesn't refer to the loading of the Cookiebot script. It refers to the loading of consent.
Therefore, these events occur when a visitor submits consent on the banner, or when the Cookiebot script determines the visitor's consent from the CookieConsent cookie during the loading of the Cookiebot script.
It is completely unrelated to when the Cookiebot script (uc.js) finishes loading and none of the events or callbacks listed above tell you when this occurs.
Determining when the Cookiebot (uc.js) script is finished loading
There may be situations where you want to know when the uc.js script has finished loading, and as we determined above, there are no Cookiebot events or callback that help us in that regard.
To be able to determine when the uc.js script has finished loading, we can create an event and a callback of our own though. You can do this using the script below.
Enter your own Domain Group ID here to update the snippet:
This will fire a new event "CookiebotLoaded" and also call the callback function "CookiebotCallback_Loaded".
Keep in mind that if you want to use the callback, then you need to have defined it before the above script loads, otherwise the function won't exist at the time the script wants to call it.