Passing offline conversions

To learn about offline conversions and how their tracking can help your business, see Offline conversions and calls.
Attention. Before getting started, enable offline conversion tracking.
  1. Step 1. Preparing data
  2. Step 2. Checking that Yandex Metrica is ready to process conversions
  3. Step 3. Preparing the CSV file
  4. Step 4. Transmitting data
  5. What's next?

Step 1. Preparing data

  1. Prepare special IDs: 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 track (for example, order confirmation: “order_confirmed”). You will need this ID when creating a CSV file.

    Note. When creating a “JavaScript event” goal, make sure to use the “matches” condition.

    You can use a previously created goal if conversions for this goal are done both on the website and offline and you want to get general statistics.

Step 2. Checking that Yandex Metrica is ready to process conversions

You can attribute conversion to a session tracked by Yandex Metrica within 21 days. The conversion tracking period gradually increases after enabling the option. Therefore, conversions can be transmitted for a time period equal to the accounting period. You can upload conversions in about a day after 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 transmitted in CSV format. There are several ways to do this:
In the file, specify the data that you want to pass 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 The ID of a click on a Yandex Direct ad assigned by Yandex Direct. It is passed in the ad URL (only for client_id_type = YCLID).
Target ID of the goal.
datetime Date and time of the conversion in Unix Time Stamp format.
Optional
Price Goal cost (value), with full stop (.) as the decimal separator.
Currency Currency code of the purchase in the three-letter ISO 4217 format.
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 The ID of a click on a Yandex Direct ad assigned by Yandex Direct. It is passed in the ad URL (only for client_id_type = YCLID).
Target ID of the goal.
datetime Date and time of the conversion in Unix Time Stamp format.
Optional
Price Goal cost (value), with full stop (.) as the decimal separator.
Currency Currency code of the purchase in the three-letter ISO 4217 format.

Step 4. Transmitting data

Tip. Create a CSV file with the data and send it using this method. We also recommend generating API requests automatically using modules written in a programming language.
Note. The data will appear in Yandex Metrica reports within 24 hours of uploading.

Use the method POST /management/v1/counter/{counterId}/offline_conversions/upload. In the input data, specify the OAuth token, tag ID, and user ID type.

$counter = "";            // Specify the tag ID
$token = "";              // Specify the OAuth token
$client_id_type = "";     // Specify the type of user IDs – 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?

To track the status of conversion upload, use the GET /management/v1/counter/{counterId}/offline_conversions/uploading/{id} method.