addEventListener

Sourcepoint has implemented its own addEventListener command which can be used as an alternative to the callback functions.

Stub function

The following stub function ensures that the addEventListener command exists before calling it later on. Insert the following stub function onto your property:

<script type="text/javascript">
  //stub function to check if _sp_.addEventListener is loaded
  function checkExist() {
    console.log("checkExist()")
    var checkIt =  setInterval(function() {
      if (typeof ( window._sp_.addEventListener) == 'function') {
        clearInterval(checkIt);
        setListeners();
      }else{
        console.log('wait for _sp_')
      }
  	}, 100);
  }
  checkExist();	
</script>

Command

Once the stub function is implemented on your property, your organization can call the setListeners function and define all listeners you wish to listen to using the window._sp_.addEventListener command.

<script type="text/javascript">
  function setListeners(){
    window._sp_.addEventListener('onConsentReady',(e)=>{
      console.log("onConsentReady Listener Fired!")
    })
  }
</script>