Migrating from the Logs API to Data Streaming
Note
This feature is only available with the Yandex Metrica Pro package.
When you migrate from the Logs API to Data Streaming (via the Yandex Cloud integration), your data is sent to a ClickHouse cluster. The Data Streaming format isn't backward-compatible with the Logs API, so field names may differ, and some Logs API fields don't have a direct equivalent.
Unlike the Logs API, Data Streaming tracks versioned updates for sessions and hits. Each row in the log represents a single version of a session or hit (event), so a single session or hit can appear across multiple rows. To learn how to retrieve only the latest version of a session or hit, see How to work with data. To automatically clean up outdated versions, use built-in ClickHouse engines like CollapsingMergeTree.
How to migrate from the Logs API to Data Streaming
- Create a ClickHouse cluster in Yandex Cloud if you don't have one yet.
- Set up Data Streaming: connect your data source (Yandex Metrica), select the data type (hits or sessions) and the fields you need, and create a transfer. Enable streaming (select the Replication transfer type) to start receiving new data in real time.
- Map the fields in your SQL queries and data marts using the mapping tables on this page.
- For Logs API fields that don't have a direct equivalent in Data Streaming, use formulas for calculated fields.
- Verify your data in the ClickHouse cluster by comparing query results against Logs API data for an overlapping date range.
- Once verified, switch your dashboards, reports, and integrations to read from ClickHouse, and turn off your Logs API exports.
To backfill your cluster with historical data in the same format as your stream, run a historical export for the period you need (select the Snapshot transfer type). Historical exports include data collected over a week ago. For example, data for August 10 isn't available until at least August 17.
Note
You can run Data Streaming and the Logs API side by side during the transition period. Data will flow to both so you can compare results and verify that the migration works properly.
To migrate smoothly and keep your data marts intact, use the sections on this page:
- Hit field mapping table
- Session field mapping table
- Formulas for calculated fields
- How attribution works
- How to work with location data
- E-commerce data
Hit field mapping table
Below are the Logs API hit (event) fields and their matching fields in Data Streaming.
Note
Fields without a direct equivalent are marked as "Calculated field" (see Formulas for calculated fields). Fields related to attribution and location data are covered in separate sections: Attribution and Location data.
|
Logs API field |
Data Streaming field |
Note |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date and time in UTC format |
|
|
|
|
|
|
|
|
|
|
|
|
IDs of completed goals, including offline conversions (available starting August 12, 2025) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String and numeric OS ID |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
To learn more, see Attribution |
|
|
|
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
|
To learn more, see Attribution |
|
|
|
To learn more, see Attribution |
|
|
|
To learn more, see Attribution |
|
|
|
String ID of the browser |
|
|
|
Major version number of the browser |
|
|
|
Minor version number of the browser |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 — the hit came from this type of device |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Numeric and string ID of the OS group |
|
|
— |
Calculated field (see Formulas) |
|
|
— |
Calculated field (see Formulas) |
|
|
|
|
|
|
— |
Calculated field (see Formulas) |
|
|
|
|
|
|
— |
Calculated field (see Formulas) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IPv4 or IPv6 address from which the TCP connection was established |
|
|
— |
To learn more, see Location data |
|
|
— |
To learn more, see Location data |
|
|
— |
To learn more, see Location data |
|
|
— |
To learn more, see Location data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Session field mapping table
This table shows the Logs API session fields and their equivalents in Data Streaming.
|
Logs API field |
Data Streaming field |
Note |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
Convert |
|
|
|
|
|
|
— |
Calculated field (see Formulas) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Session duration in seconds |
|
|
|
|
|
|
|
|
|
|
— |
To learn more, see Location data |
|
|
— |
To learn more, see Location data |
|
|
— |
To learn more, see Location data |
|
|
— |
To learn more, see Location data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
|
|
|
|
|
Yandex Direct campaign ID |
|
|
|
Yandex Direct ad group ID |
|
|
|
Ad ID |
|
|
— |
There's no direct equivalent. Use |
|
|
— |
There's no direct equivalent. Use |
|
|
— |
There's no direct equivalent. Use |
|
|
— |
There's no direct equivalent. Use |
|
|
— |
There's no direct equivalent. Use |
|
|
|
Placement site |
|
|
— |
There's no direct equivalent. Use |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
— |
To learn more, see Attribution |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
Calculated field (see Formulas) |
|
|
|
|
|
|
— |
Calculated field (see Formulas) |
|
|
|
|
|
|
|
|
|
|
— |
Calculated field (see Formulas) |
|
|
— |
Calculated field (see Formulas) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
— |
See E-commerce data |
|
|
|
Call duration in seconds |
|
|
|
Call hold duration in seconds |
|
|
|
Whether the call was missed |
|
|
|
Tags associated with the call |
|
|
|
Whether that was the first call from this customer |
|
|
|
Page from which the call was made |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Formulas for calculated fields
Some Logs API fields are calculated on the service side, while Data Streaming delivers raw data. For Logs API fields without a direct equivalent in Data Streaming, you can calculate the values using ClickHouse formulas.
screenFormat
toUInt16(ifNotFinite(ResolutionWidth * 21 / ResolutionHeight, 0)) AS screenFormat
The screenFormat field returns a numeric code instead of a screen resolution, and here's what this code means:
|
Value |
Aspect ratio |
|
0 |
undefined |
|
9 |
9:21 |
|
11 |
9:16 |
|
12 |
3:5 |
|
13 |
10:16 |
|
14 |
2:3 |
|
15 |
3:4 |
|
16 |
4:5 |
|
26 |
5:4 |
|
28 |
4:3 |
|
31 |
3:2 |
|
33 |
16:10 |
|
35 |
5:3 |
|
37 |
16:9 |
|
49 |
21:9 |
screenOrientation
toUInt8(
if(IsTablet OR IsMobile,
if(WindowClientHeight > 0 AND WindowClientWidth > 0,
if(WindowClientWidth < WindowClientHeight, 1, 2),
0),
if(ResolutionHeight > 0 AND ResolutionWidth > 0,
if(ResolutionWidth < ResolutionHeight, 1, 2),
0)
)
) AS screenOrientation
Values for screenOrientation:
0— undefined1— portrait orientation2— landscape orientation
physicalScreenWidth
if(
UserAgent IN (2, 6, 72, 137, 14) OR (UserAgent = 70 AND NOT IsMobile),
toUInt32(ResolutionWidth),
toUInt32(ifNotFinite(ResolutionWidth * DevicePixelRatio, 0)) + bitAnd(toUInt16(toUInt32(ifNotFinite(ResolutionWidth * DevicePixelRatio, 0))), 1)
) AS physicalScreenWidth
physicalScreenHeight
if(
UserAgent IN (2, 6, 72, 137, 14) OR (UserAgent = 70 AND NOT IsMobile),
toUInt32(ResolutionHeight),
toUInt32(ifNotFinite(ResolutionHeight * DevicePixelRatio, 0)) + bitAnd(toUInt16(toUInt32(ifNotFinite(ResolutionHeight * DevicePixelRatio, 0))), 1)
) AS physicalScreenHeight
isNewUser
To identify new users, use attribution based on the time of the first session. Compare UTCStartTime of the first session with UTCStartTime of the current session. If they match, the current session is the user's first.
TrafficSource.StartTime[indexOf(TrafficSource.Model, 3)] = UTCStartTime AS isNewUser
Where attribution 3 — "First session".
Attribution
Unlike the Logs API, Data Streaming stores session attribution in arrays. All TrafficSource.XXX arrays align by attribution model. The order of elements in arrays matches the attribution model (TrafficSource.Model) used to calculate the value of the TrafficSource.XXX field, and each array contains this value.
To get the XXX field value for a specific attribution model YYY, use the indexOf function:
TrafficSource.XXX[indexOf(TrafficSource.Model, YYY)] AS XXX
Attribution
|
Code |
Attribution model |
|
1 |
Last click |
|
5 |
Last non-direct click (cross-device) |
|
6 |
First cross-device click |
|
11 |
Automatic (cross-device) |
Traffic sources
Values for the TrafficSource.ID field:
|
Code |
Source |
|
-1 |
Internal traffic |
|
0 |
Direct traffic |
|
1 |
Link traffic |
|
2 |
Search engine traffic |
|
3 |
Ad traffic |
|
4 |
Cached page traffic |
|
5 |
Undefined |
|
6 |
External links traffic |
|
7 |
Mailing traffic |
|
8 |
Social media traffic |
|
9 |
Recommendation system traffic |
|
10 |
Messenger traffic |
|
11 |
QR code traffic |
Example
SELECT
VisitID,
TrafficSource.ID[indexOf(TrafficSource.Model, 1)] AS lastTrafficSourceID, -- Traffic source under the Last click attribution model
TrafficSource.ID[indexOf(TrafficSource.Model, 5)] AS cd_last_significant_TraficSourceID, -- Traffic source under the Last non-direct click (cross-device) attribution model
TrafficSource.ID[indexOf(TrafficSource.Model, 6)] AS cd_first_TraficSourceID -- Traffic source under the First click (cross-device) attribution model
FROM your_database.your_visits_table
WHERE StartDate = today() - 1
For more details on working with arrays in ClickHouse, see the ClickHouse documentation.
Location data
Data Streaming doesn't include pre-populated fields for country or city names. Instead, location data is stored as region IDs (such as RegionID). To resolve region names from these IDs, use ClickHouse's built-in geodictionary functions, such as regionToName:
SELECT
RegionID,
regionToName(RegionID, 'ru') AS regionName
FROM your_database.your_visits_table
LIMIT 10
For more details on location functions, see the ClickHouse documentation.
E-commerce data
In Data Streaming, E-commerce data is stored in arrays:
EAction.*— array of actions with products during a session. A single session may include actions with viewed products, products added to the cart, and purchased products. You can check the action type using theEAction.Typefield.EPurchase.*— array of purchases made during a session. One user can make multiple purchases during a session.EPurchaseWithProducts.*— array of purchased products. It matchesEAction.*filtered by purchases only (EAction.Type = 3).
Alert
If purchase data is sent without populating the products array, the EPurchase array will still contain the purchase data, but there won't be an EAction.Type = 3 entry in the EAction array.
EPromotion.*— array of actions with internal promo campaigns during a session. You can check the type of action with a promo campaign using theEPromotion.Typefield.