Skip to content

Integration with Bitrix24

If your Bitrix24 (leads + deals) account has permissions other than administrator permissions, errors may occur in data transfer between R7K12 and Bitrix24 (leads + deals) after you set up the integration. To check the permissions in Bitrix24 (leads + deals):

  1. In your Bitrix24 account, open the Company section.
  2. Go to the Employees tab.
  3. Click Edit next to the Bitrix24 (leads + deals) user who will set up the integration with R7K12:
  4. On the user profile settings page, in the User information block, make sure the Allow user to edit portal checkbox is selected:

How the integration works

When a request is submitted on the website, a new deal is automatically created in the CRM, and the visit ID from the browser cookie r7k12_si is passed to it in an additional field named r7k12id.

Setting up the integration

Step 1. Install the tracking code on your website

A detailed description of how to install the tracking code on your website is in the help section Installing tracking codes.

Step 2. Add an additional field

Add the custom field r7k12id to the "Lead" and "Deal" entities:

  1. In Bitrix24, open the tab CRM → More → Settings → Form and report settings → Custom fields.

2. For the “Lead” entity, click “Add field”; in the window that opens, enter “r7k12id” in the “Name” field and select “String” in the “Type” field. 3. In the same way, add the r7k12id field to the "Deal" entity.

Step 3. Connect Bitrix24 in the integration catalog

In the R7K12 system, go to the “Integrations” tab and select the “Bitrix24” tile. In the window that opens, in the “Enter portal” field, enter your project address, which you can take from the Bitrix24 URL. For example, for https://.bitrix24.ru, take .bitrix24.ru. In the upper right corner, click “Create”. A page with information about the R7K12 integration app will open in your Bitrix24 profile. Select “I have read and agree to the license agreement” and “I have read and agree to the privacy policy”. If the window with information about the R7K12 integration app does not open and you cannot find it in Marketplace, write to us and we will help. Select the checkboxes I have read and agree to the license agreement and I have read and agree to the privacy policy and click Install. To install the app, your Bitrix24 account must have administrator permissions. If everything went well, the following window will open: Set the deal statuses: Deal statuses can have the following values:

  1. “Not counted”: if a deal has this status, it appears in the "Inquiries" column in the analytics.
  2. “In progress”: means the deal is in the "Requests" column.
  3. “Completed”: the deal has been closed successfully and is in the "Sales" column.
  4. “Canceled”: means the deal has been closed without a sale and is in the "Canceled requests" column.

Next, select the managers responsible for the deal: Select the “Default status”: Save the configuration with the “Save” button in the upper right corner.

Step 4. Set up automatic sending of deals to Bitrix24

Session_id is stored in:

  • the browser cookies (r7k12_si);
  • the browser local storage (localStorage) (r7k12_si);
  • a global JS variable (r7k12_si).

We recommend getting the visit ID through the “R7K12_CallBack” function. This function is called automatically after the “pageview” is sent and the visit ID is received. The function must be declared before the tracking code script is initialized. Form data can be sent to the CRM using either PHP or JavaScript. The scripts are equivalent and perform the same function. 4.1. PHP script:

<?php

$KEY = 'PROJECT KEY';//ключ проекта
$CRM = array(
    'r7k12id' => isset($_COOKIE['r7k12_si']) ? $_COOKIE['r7k12_si'] : null,
    'type' => 'Form',//Тип заявки (ОБЯЗЯТЕЛЬНО)
    'title' => 'Проверка макросов',//Заголовок заявки (НЕ ОБЯЗАТЕЛЬНО)
    'comment' => 'Коментарий к сделке',//Комментарий к сделке (НЕ ОБЯЗАТЕЛЬНО)
    'name' => 'Имя клиента',//Название контакта (НЕ ОБЯЗАТЕЛЬНО)
    'email' => '[email protected]',//E-mail адрес контакта (ОБЯЗАТЕЛЕН ЕСЛИ НЕ УКАЗАН ТЕЛЕФОН КОНТАКТА)
    'phone' => '380501234567',//Телефон контакта (ОБЯЗАТЕЛЕН ЕСЛИ НЕ УКАЗАН E-MAIL КОНТАКТА)
    'create_new_lead' => '1' //'0' - новая сделка создается только если нет сделки или предыдущая в статусе "успешно реализовано" или "возврат"; '1' - новая сделка создается в любом случае
);

$context = stream_context_create(array(
   'http' => array(
       'method' => 'POST',
       'content' => json_encode($CRM),
   ),
));
file_get_contents("https://r7k12.com/".$KEY."/crm/", false, $context);

When sending via PHP, it is preferable to use the cURL library instead of the file_get_contents() function. Example:

<?php
define('KEY','YOUR PROJECT KEY');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://r7k12.com/'.KEY.'/crm/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt(
    $curl,
    CURLOPT_POSTFIELDS,
    urlencode(
        json_encode(
            [
                'r7k12id' => !empty($_COOKIE['r7k12_si']) ? $_COOKIE['r7k12_si'] : null,
                'type' => 'Form',
                'comment' => 'Комментарий к сделке',
                'name' => 'Имя клиента',
                'email' => 'E-mail клиента',
                'phone' => 'Телефон клиента',
                'create_new_lead' => '0'
            ],
            JSON_UNESCAPED_UNICODE
        )
    )
);
$out = curl_exec($curl);
curl_close($curl);

4.2. JavaScript:

r7k12.push({
    hit: 'crm',
    data: {
        type: "Form",//тип заявки
        title: "Заявка с сайта",//Заголовок заявка
        comment: "Сделка созданная с фронта",//комментарий
        name: "Алексей Владимирович",//имя контакта
        phone: "8-912-345-67-89",//телефон
        fields: {//доп. поля
            lead: {
                cost: "{cost}",
                revenue: "{revenue}",
                price: 100,
                '127633': 'Текст'  // Заполнение доп. поля с ID ‘127633’
// Подробную информацию о наименовании полей и получить список доп. полей вы можете в документации Битрикс24: https://dev.1c-bitrix.ru/rest_help/crm/fields.php
            },
            contact: {
                '3124124': 'Текст' // Заполнение доп. поля с ID ‘3124124’
                // Подробную информацию о наименовании полей и получить список доп. полей вы можете в документации Битрикс24: https://dev.1c-bitrix.ru/rest_help/crm/fields.php
            }
        }
    }
});

If form sending is set up correctly, incoming requests will be displayed on the “Request log” tab.

Connecting CRM forms in Bitrix

To track inquiries from these forms, you need to pass r7k12id to the deals. Open the form settings (in Bitrix, CRM -> More -> CRM forms): Opened file "Photo note" Select the form you need and click “Edit”. At the bottom, click “Additional”. Opened file "Photo note" Scroll down to the “Default field values” section. Select the lead or deal field you need (depending on whether a lead or a deal is created through the form). Click “Add field” r7k12id. Opened file "Photo note" In the value, enter %r7k12id%: Opened file "Photo note"