---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com/dev/metrika/en/management/offline-conv.md
  - https://yandex.com/dev/metrika/ru/management/offline-conv.md
  - href: en/management/offline-conv.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/metrika/en/llms.txt

# Passing offline conversions

For information on offline conversions and what business goals you can achieve by tracking them, see [Offline conversions and calls](https://yandex.com/dev/metrika/en/management/conversion.md).

## Step 1. Preparing data {#data}

1. Prepare [special IDs](https://yandex.com/dev/metrika/en/management/conversion.md#cpec-ids): `ClientID`, `UserID`, `yclid`, or `PurchaseId`.

   {% note info %}

   Pass at least one of these identifiers. Otherwise, the conversion won't be attributed to the session.

   {% endnote %}
1. Create a [JavaScript event goal](https://yandex.com/support/metrica/general/goal-js-event.html) using the [POST /management/v1/counter/{counterId}/goals](https://yandex.com/dev/metrika/en/management/openapi/goal/addGoal.md) 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 info %}

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

   {% endnote %}

   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 {#csv}

Conversion data is sent in CSV format. There are several ways to send call data:

{% list tabs %}

- CSV file (recommended)

  In the file, specify the data that you want to pass to Yandex Metrica. [Sample file](https://download.cdn.yandex.net/from/yandex.ru/support/ru/metrica/files/offline-conversions.csv).

- multipart/form-data
  
  Be sure to pass the column names in the first line.

{% endlist %}

#|
|| **Columns** | **Description** ||
|| **Required** ||
|| `Target` | ID of the goal. ||
|| `DateTime` | Date and time of the conversion in [Unix Time Stamp](http://www.unixtimestamp.com/index.php) 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. ||
|| `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. The click ID is passed in the ad URL. ||
|| `PurchaseId` | The E-commerce purchase ID assigned by the site owner. ||
|| **Optional** ||
|| `Price` | Goal cost (value), with full stop (.) as the decimal separator. ||
|| `Currency` | Currency code in three-letter ISO 4217 format. ||
|#

## Step 3. Sending data {#upload}

{% note info %}

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.

{% endnote %}

{% note info %}

The data will appear in Yandex Metrica reports within 2 hours of upload.

{% endnote %}

Use the [POST /management/v1/counter/{counterId}/offline_conversions/upload](https://yandex.com/dev/metrika/en/management/openapi/offline_conversions/upload_1.md) method. Make sure to include the OAuth token and the tag ID in your input data.

{% list tabs %}

- PHP
  
  ```php translate=no
  $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);
  ```

- Python

  ```python translate=no
  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})
  ```

{% endlist %}

## What's next? {#other}

To track the status of your conversion upload, use the [GET /management/v1/counter/{counterId}/offline_conversions/uploading/{id}](https://yandex.com/dev/metrika/en/management/openapi/offline_conversions/findById_1.md) method.

## Learn more

- [Example of using a goal in the report](https://yandex.com/dev/metrika/en/stat/examples.md#conv)
