Transmitting call data

Attention. Before you start, enable offline conversion tracking.
  1. Step 1. Preparing data
  2. Step 2. Checking whether you can upload call data to Yandex.Metrica.
  3. Step 3. Preparing the CSV file
  4. Step 4. Transmitting data
  5. What's next?

Step 1. Preparing data

Prepare special identifiers: ClientID or UserID.

Step 2. Checking whether you can upload call data to Yandex.Metrica.

Sessions tracked by Yandex.Metrica can be supplemented with information about calls within 21 days. The call tracking period increases gradually once you enable the option. Therefore, you can transfer call data for the number of days equal to the tracking period. You can upload call data within about 24 hours of enabling the option.

To check whether you can upload data and for what period, use the GET /management/v1/counter/{counterId}/offline_conversions/calls_visit_join_threshold method.

Step 3. Preparing the CSV file

Call data is sent in CSV format. There are several ways to transfer data:
In the file, specify the data you want to transfer to Yandex.Metrica.

Required columns:

  • UserId: The site user ID assigned by the site owner (only for client_id_type = USER_ID).
  • ClientId: The site user ID assigned by Yandex.Metrica (only for client_id_type = CLIENT_ID).
  • DateTime: The data and time of conversion in unix timestamp format.

Optional columns:

  • StaticCall: Indicates whether the call is static (1 — static, 0 — dynamic).

    About static and dynamic calls

    Calls can be dynamic (linked to a user and their session) or static (not linked). Yandex.Metrica doesn't associate a call with a user or session if:

    • A user ID was transmitted that doesn't exist in the Yandex.Metrica database.
    • The user's session ended after the call that was transmitted to the service or earlier than 21 days before the data was sent.
    • The extended conversion tracking period was enabled after data was transmitted to Yandex.Metrica and the conversion tracking period still didn't reach 21 days.
  • Price: The goal cost, with a period (.) used as a decimal separator.
  • Currency: The currency code in three-letter ISO 4217 format.
  • PhoneNumber: The phone number without spaces (with the country and city codes specified). For example, +70123456789.
  • TalkDuration: The duration of the call in seconds.
  • HoldDuration: The amount of time spent waiting on the call in seconds.
  • CallMissed: Indicates whether the call was missed (1 — missed, 0 — answered).
  • Tag: A custom tag. It can be used to mark the quality of a call, the result, and so on. For example, “the customer was not satisfied with the price”.
  • FirstTimeCaller: Indicates whether it was the first call (1 — first call, 0 — repeat call).
  • URL: The URL that the call was made from (the page associated with the event). For example, the landing page of ad campaign that contains the phone number (PhoneNumber).
  • CallTrackerURL: The URL that was clicked through to the call tracker interface.

Step 4. Transmitting data

Tip. Create a CSV file with data and pass it using this method. We also recommend that you generate API requests automatically using programming language modules.

To transmit data, use the POST /management/v1/counter/{counterId}/offline_conversions/upload_calls method. A request passes the name of the goal to be created during data transfer. You can then add this goal to Yandex.Metrica reports.

Specify the OAuth token, tag number, and user ID type in the input data.

$counter = "";            // Specify the tag number
$token = "";              // Specify the OAuth token
$client_id_type = "";     // Specify the user ID type: CLIENT_ID or USER_ID

$curl = curl_init("https://api-metrika.yandex.ru/management/v1/counter/{counterId}/offline_conversions/upload_calls?client_id_type=$client_id_type");

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array('file' => new CurlFile(realpath('file.csv'))));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data", "Authorization: OAuth $token"));

$result = curl_exec($curl);

echo $result;

curl_close($curl);

What's next?

Track the call upload status using the GET /management/v1/counter/{counterId}/offline_conversions/calls_uploading/{id} method.