Passing offline conversions

To learn about offline conversions and how their tracking can help your business, see Offline conversions and calls.

Step 1. Preparing data

  1. Prepare special IDs: ClientID, UserID, yclid, or PurchaseId.

  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 site and offline and you want to get general statistics.

Step 2. Preparing conversion data

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.

Be sure to pass the column names in the first line.

Columns

Description

Required

UserId

Site user ID assigned by the site owner.

ClientId

Site user ID assigned by Yandex Metrica.

Yclid

The ID of a click on a Yandex Direct ad assigned by Yandex Direct. It is passed in the ad URL.

PurchaseId

The E-commerce purchase ID assigned by the site owner.

Target

ID of the goal.

DateTime

Date and time of the conversion in Unix Time Stamp format.

Please note that the DateTime can only be in the past. An error occurs if the file is loaded before the DateTime value has been reached.

Optional

Price

Goal cost (value), with full stop (.) as the decimal separator.

Currency

Currency code in three-letter ISO 4217 format.

Step 3. Transmitting data

Note

Create a CSV file with the data and pass 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 2 hours of uploading.

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

$counter = "";            // Specify the counter ID
$token = "";              // Specify the OAuth token

$curl = curl_init("https://api-metrica.yandex.net/management/v1/counter/$counter/offline_conversions/upload");

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);
import requests

counter = 123456
token = "token"

file = open("offline-conversions.csv", "r").read()

url = "https://api-metrica.yandex.net/management/v1/counter/{}/offline_conversions/upload".format(counter)
headers = {
 "Authorization": "OAuth {}".format(token)
}

req = requests.post(url, headers=headers, files={"file":file})

What's next?

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

Learn more