Initializing Connectif JavaScript

 

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

Connectif JavaScript initializes by default after loading in the page. In some cases, you may want to control when the script performs this process.

 

This article explains how to initialize Connectif JavaScript

  

Implementation time: 5 minutes.
Difficulty: Medium
When to use it: After adding Connectif JavaScript in custom integrations, via tags or JavaScript.

  

You can disable this default behavior of the script via the web configuration in Connectif.

 

STEP 1. JavaScript call

  1. Make the following call to initialize Connectif JavaScript..
initializeConnectif(connectifConfiguration);
  

In this call, initializeConnectif and connectifConfiguration are two global variables that are defined by Connectif Javascript when it loads on the page.

  1. The initializeConnectif function will launch the connectif.managed.initialized event at the end of the initialization process.
  2. From then on you will be able to use all the functions of window.connectif.managed.
document.addEventListener('connectif.managed.initialized', function onConnectifInitialized() {
console.log('Connectif is initialized');
// now I can start tracking events
connectif.managed.sendEvents([{ type: 'page-visit' }]);
});

 

1.1. InitializeConnectif Function Definition

(This section explains how to avoid calling the initializeConnectif function when it is not already defined in the global variables).

  1. To initialize Connectif JavaScript, use the connectif.loaded event.
document.addEventListener('connectif.loaded', function onConnectifLoaded() {
console.log('Connectif is loaded');
// now I can call initializeConnectif
initializeConnectif(connectifConfiguration);
});

 

 

 Success!
The Connectif JavaScript has now been initialized.


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