Passing call data
- Step 1. Preparing data
- Step 2. Checking if Yandex Metrica is ready to upload calls
- Step 3. Preparing the CSV file
- Step 4. Transmitting data
- What's next?
Step 1. Preparing data
Prepare special identifiers.
Step 2. Checking if Yandex Metrica is ready to upload calls
You can add call information to a session tracked by Yandex Metrica within the last 21 days. The call tracking period gradually increases after the option is enabled. That means call data can be passed for a time period that is equal to the tracking period. You can upload call data in about a day after enabling the option.
To check if you can upload data and the available tracking period, use the GET /management/v1/counter/{counterId}/offline_conversions/calls_visit_join_threshold method.
Step 3. Preparing the CSV file
Be sure to pass the column names in the first line.
Required columns:
- UserId: Site user ID assigned by 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 (only for client_id_type = YCLID).
- DateTime: Date and time of the conversion in Unix Time Stamp format. The time should be in the UTC+0 timezone.
Optional columns:
StaticCall: Whether the call is static (1 — static, 0 — dynamic).
- A user ID was transmitted that doesn't exist in the Yandex Metrica database.
- The user's session ended after the call that was transmitted to the service, or earlier than 21 days before the data was sent.
- Conversion tracking is enabled after data was passed to Yandex Metrica and the conversion tracking period hasn't reached 21 days.
Static and dynamic callsThe type of call is determined by the call tracker. With the dynamic method, the call tracker assigns a phone number to each user session, meaning it uses number substitution. When the call tracker transmits a dynamic call, Yandex Metrica links the call data to the nearest session appropriate by time. Static calls aren't linked to user sessions. More information about call tracking methods.
Yandex Metrica doesn't link calls to users and user sessions in the following cases:
- Price: Goal cost, with full stop (.) as the decimal separator.
- Currency: Currency code in three-letter ISO 4217 format.
- PhoneNumber: Phone number without spaces (with both country code and city code). For example, +70123456789.
- TalkDuration: Call duration in seconds.
- HoldDuration: Time on hold in seconds.
- CallMissed: Whether the call was missed (1 — missed, 0 — answered).
- Tag: Custom tag. You can use it for arbitrary comments, for example, on the call quality or results. For example, “customer wasn't happy with the price”.
- FirstTimeCaller: Whether it was the customer's first call (1 — primary call, 0 — repeat call).
- URL: Source URL for the call (the web page linked to the event). For example, this could be a campaign landing page specifying a phone number (PhoneNumber).
- CallTrackerURL: Click-through URL to the call tracker interface.
Step 4. Transmitting data
To pass data, use the POST /management/v1/counter/{counterId}/offline_conversions/upload_calls method. The request includes the name of the goal that will be created when data is transmitted. This goal can then be added to Yandex Metrica reports.
Specify in the input data 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/{counterId}/offline_conversions/upload_calls?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);
import requests
counter = 123456
token = "token"
file = open("offline-conversions.csv", "r").read()
id_type = "CLIENT_ID"
url = "https://api-metrika.yandex.net/management/v1/counter/{counterId}/offline_conversions/upload_calls?client_id_type={}".format(counter, id_type)
headers = {
"Authorization": "OAuth {}".format(token)
}
req = requests.post(url, headers=headers, files={"file":file})
What's next?
To track the status of call upload, use the GET /management/v1/counter/{counterId}/offline_conversions/calls_uploading/{id} method.