Passing offline conversions
For information on offline conversions and what business goals you can achieve by tracking them, see Offline conversions and calls.
Step 1. Preparing data
-
Prepare special IDs:
ClientID,UserID,yclid, orPurchaseId.Note
Pass at least one of these identifiers. Otherwise, the conversion won't be attributed to the session.
-
Create a JavaScript event goal using the POST /management/v1/counter/{counterId}/goals method. For the goal ID, specify the event that you want to track (for example, order confirmation — “order_confirmed”). You need this ID to create a CSV file.
Note
When creating a “JavaScript event” goal, make sure to use the “matches” condition.
You can use a goal you've already created if conversions for it happen both on your site and offline, and you want to see the combined statistics.
Step 2. Preparing conversion data
Conversion data is sent in CSV format. There are several ways to send call data:
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 |
|
|
|
ID of the goal. |
|
|
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. |
|
Required for linking a chat to a session — specify at least one of these IDs. |
|
|
|
Site user ID assigned by the site owner. |
|
|
Site user ID assigned by Yandex Metrica. |
|
|
The ID of a click on a Yandex Direct ad assigned by Yandex Direct. The click ID is passed in the ad URL. |
|
|
The E-commerce purchase ID assigned by the site owner. |
|
Optional |
|
|
|
Goal cost (value), with full stop (.) as the decimal separator. |
|
|
Currency code in three-letter ISO 4217 format. |
Step 3. Sending data
Note
Create a CSV data file and send it using this method. We recommend that you also automate your API queries using modules available in your programming language.
Note
The data will appear in Yandex Metrica reports within 2 hours of upload.
Use the POST /management/v1/counter/{counterId}/offline_conversions/upload method. Make sure to include the OAuth token and the tag ID in your input data.
$counter = ""; // Specify the tag ID
$token = ""; // Specify the OAuth token
$curl = curl_init("https://api-metrika.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-metrika.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 your conversion upload, use the GET /management/v1/counter/{counterId}/offline_conversions/uploading/{id} method.