Triggering of events

 

Questo articolo è attualmente disponibile in inglese e spagnolo. Puoi fare riferimento a questa documentazione mentre arriva nella tua lingua.

Connectif's JavaScript triggers the "conectif.loaded" and "connectif.managed.initialized" events throughout its lifecycle, which serve to determine when the JavaScript has been loaded on the page or when it has been successfully initialized.

 

How to use them

The "connectif.loaded" event is triggered when the Connectif JavaScript finishes loading on the page. So, after this event is triggered, the "window.connectif".

The "connectif.managed.initialized" event will trigger when Connectif JavaScript has initialized. At this point, the "window.connectif.managed" object will be available.

 

Examples

The "connectif.loaded" event will look like this:

document.addEventListener('connectif.loaded', function onConnectifLoaded() {
console.log('Connectif is loaded');
}); 

The "connectif.managed.initialized" event will look like this:

document.addEventListener('connectif.managed.initialized', function onConnectifInitialized() {

console.log('Connectif is initialized');
console.log(window.connectif.managed.isInitialized()) // this prints true

// now I can start tracking events
window.connectif.managed.sendEvents([{ type: 'page-visit' }]);
});

Its main use is to know when Connectif is ready to track events. Below is a more complete example for sending events to Connectif:

function trackPageVisit() {
window.connectif.managed.sendEvents([{ type: 'page-visit' }]);
}

if (window.connectif &&
window.connectif.managed &&
window.connectif.managed.isInitialized()) {
trackPageVisit();
} else {
document.addEventListener("connectif.managed.initialized", function onConnectifInitialized() {
trackPageVisit();
},
{ once: true });
}
 

Congratulations!
You’ve reached the end of the tutorial.

  

Do you have questions?
Don’t forget, our Connectif specialists are here to help you. To contact them, just open a Support ticket by clicking the blue “Help” button on your dashboard.


Keep learning!

To make the most of your Connectif account, we recommend reading these articles next:

Questo articolo ti è stato utile?
Utenti che ritengono sia utile: 0 su 0