Transmitting data on offline conversions

For information about what offline conversions are and what business objectives you can meet by tracking them, see Offline conversions and calls.
Attention. Before you start, enable offline conversion tracking.
  1. Step 1. Preparing data
  2. Step 2. Checking whether you can upload conversions to Yandex.Metrica.
  3. Step 3. Preparing the CSV file
  4. Step 4. Transmitting data
  5. What's next?

Step 1. Preparing data

  1. Prepare special identifiers: ClientID, UserID, or yclid.
  2. Create a JavaScript event goal using the POST /management/v1/counter/{counterId}/goals method. For the goal ID, specify the event to be tracked (for example, for order confirmation: “order_confirmed”). You'll need this ID when creating a CSV file.

    You can use a previously created goal if a conversion for this goal happens both on and off the site and you want to get general statistics.

Step 2. Checking whether you can upload conversions to Yandex.Metrica.

Sessions tracked by Yandex.Metrica can be supplemented with information about conversions within 21 days. The conversion tracking period increases gradually once you enable the option. Therefore, you can transfer conversions for the number of days equal to the tracking period. You can upload conversions 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/visit_join_threshold method.

Step 3. Preparing the CSV file

Conversion 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. Sample file.
Columns Description
Required
UserId Site user ID assigned by the site owner (only for client_id_type = USER_ID).
ClientId Site user ID assigned by Yandex.Metrica (only for client_id_type = CLIENT_ID).
yclid ID of a click on a Yandex.Direct ad, assigned by Yandex.Direct. Passed in the ad URL.
Target ID of the goal
DateTime Date and time of conversion in unix timestamp format.
Optional
price Goal cost (value), with a period (.) used as a decimal separator.
Currency Currency code in three-letter ISO 4217 format.

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.

Using the POST /management/v1/counter/{counterId}/offline_conversions/upload method. 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, USER_ID or YCLID

$curl = curl_init("https://api-metrika.yandex.ru/management/v1/counter/$counter/offline_conversions/upload?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 status of conversion uploads using the GET /management/v1/counter/{counterId}/offline_conversions/uploading/{id} method