EXPAND CAPABILITIES WITH API

You can use this type of event even with leads created through API from your forms. In order to link the lead with a particular visitor of the site, you need to get the ID of this visitor and transfer it through the API along with the data of the created lead.

Retrieving the visitor ID

To get a visitor ID, you need to put the following code on your website:

&ltscript type="text/javascript" id="kommo_pixel_identifier_js" async="async" src="https://piper.kommo.com/pixel/js/identifier/pixel_identifier.js"&gt&lt/script&gt

This code will create a global KOMMOPIXEL_IDENTIFIER object. Using the “getVisitorUid” method of this object, you can get a unique visitor ID:

var visitor_uid = KOMMOPIXEL_IDENTIFIER.getVisitorUid();

The KOMMOPIXEL_IDENTIFIER object is available only after it is fully downloaded and initialized.
You can specify the callback function to be called after the KOMMOPIXEL_IDENTIFIER object is fully initialized.
To specify the callback function, you need to create a global KOMMOPIXEL_IDENTIFIER_PARAMS object, where the “onload” field specifies the callback function.
The first argument to this function will be passed to the KOMMOPIXEL_IDENTIFIER object itself, but you can access it through the global window object, i.e. window.KOMMOPIXEL_IDENTIFIER.

window.KOMMOPIXEL_IDENTIFIER_PARAMS = window.KOMMOPIXEL_IDENTIFIER_PARAMS || {};
window.KOMMOPIXEL_IDENTIFIER_PARAMS.onload = function (pixel_identifier) {
    var visitor_uid = pixel_identifier.getVisitorUid(); // Reciving visitor_uid
    console.log('visitor_uid', visitor_uid);
    if (visitor_uid) {
      // Write it to the hidden form field 'visitor_uid'
      document.getElementById('visitor_uid').value = visitor_uid;
   }
};

The received identifier can be written to the hidden field of your form, transferred to your server, and then create a deal through the Kommo API with the indication “visitor_uid”:

Method URL

POST / api / v2 / leads

{
    "add": [
          {
              "name": "Request from site",
              "status_id": 142,
              "visitor_uid": "12345678-52d2-44c2-9e16-ba0052d9f6d6"
          }
     ]
}

On the Kommo side, the visitor ID of the visitor_uid will be linked to the id of the created lead.

Further, when the client enters the monitored page, the lead associated with it will automatically go to the configured stage.

Note: you can use only the ID received from KOMMOPIXEL_IDENTIFIER as the value of the “visitor_uid” field. The format of the identifier corresponds to the UUID. If you pass an incorrect value, it will be ignored.