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:

  1. <script type="text/javascript" id="amo_pixel_identifier_js" async="async" src="https://piper.amocrm.ru/pixel/js/identifier/pixel_identifier.js"></script>

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

  1. var visitor_uid = AMOPIXEL_IDENTIFIER.getVisitorUid();

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

  1. window.AMOPIXEL_IDENTIFIER_PARAMS = window.AMOPIXEL_IDENTIFIER_PARAMS || {};
  2. window.AMOPIXEL_IDENTIFIER_PARAMS.onload = function (pixel_identifier) {
  3.     var visitor_uid = pixel_identifier.getVisitorUid(); // Reciving visitor_uid
  4.     console.log('visitor_uid', visitor_uid);
  5.     if (visitor_uid) {
  6.       // Write it to the hidden form field 'visitor_uid'
  7.       document.getElementById('visitor_uid').value = visitor_uid;
  8.    }
  9. };

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

Method URL

POST / api / v2 / leads

  1. {
  2.     "add": [
  3.           {
  4.               "name": "Request from site",
  5.               "status_id": 142,
  6.               "visitor_uid": "12345678-52d2-44c2-9e16-ba0052d9f6d6"
  7.           }
  8.      ]
  9. }

On the amoCRM 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 AMOPIXEL_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.