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

  1. Create a ClickHouse cluster in Yandex Cloud if you don't have one yet.
  2. 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.
  3. Map the fields in your SQL queries and data marts using the mapping tables on this page.
  4. For Logs API fields that don't have a direct equivalent in Data Streaming, use formulas for calculated fields.
  5. Verify your data in the ClickHouse cluster by comparing query results against Logs API data for an overlapping date range.
  6. 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

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

ym:pv:watchID

WatchID

ym:pv:counterID

CounterID

ym:pv:clientID

FirstPartyCookie

ym:pv:date

EventDate

ym:pv:dateTime

Date and time in UTC format

ym:pv:title

Title

ym:pv:pageCharset

PageCharset

ym:pv:goalsID

GoalsReached

IDs of completed goals, including offline conversions (available starting August 12, 2025)

ym:pv:URL

URL

ym:pv:referer

Referer

ym:pv:UTMCampaign

UTMCampaign

ym:pv:UTMContent

UTMContent

ym:pv:UTMMedium

UTMMedium

ym:pv:UTMSource

UTMSource

ym:pv:UTMTerm

UTMTerm

ym:pv:openstatAd

OpenstatAdID

ym:pv:openstatCampaign

OpenstatCampaignID

ym:pv:openstatService

OpenstatServiceName

ym:pv:openstatSource

OpenstatSourceID

ym:pv:operatingSystem

OSStr, OS

String and numeric OS ID

ym:pv:from

FromTag

ym:pv:hasGCLID

HasGCLID

ym:pv:GCLID

GCLID

ym:pv:lastTrafficSource

—

To learn more, see Attribution

ym:pv:lastSearchEngineRoot

SearchEngineRootID, SearchEngineRootStrID

To learn more, see Attribution

ym:pv:lastSearchEngine

—

To learn more, see Attribution

ym:pv:lastAdvEngine

AdvEngine, AdvEngineStrID

To learn more, see Attribution

ym:pv:lastSocialNetwork

SocialSourceNetworkID, SocialSourceNetworkStrID

To learn more, see Attribution

ym:pv:lastSocialNetworkProfile

SocialSourcePage

To learn more, see Attribution

ym:pv:browser

UserAgentStr

String ID of the browser

ym:pv:browserMajorVersion

UserAgentMajor

Major version number of the browser

ym:pv:browserMinorVersion

UserAgentMinor

Minor version number of the browser

ym:pv:browserCountry

BrowserCountry

ym:pv:browserEngine

BrowserEngineID

ym:pv:browserEngineVersion1

BrowserEngineVersion1

ym:pv:browserEngineVersion2

BrowserEngineVersion2

ym:pv:browserEngineVersion3

BrowserEngineVersion3

ym:pv:browserEngineVersion4

BrowserEngineVersion4

ym:pv:browserLanguage

BrowserLanguage

ym:pv:clientTimeZone

ClientTimeZone

ym:pv:cookieEnabled

CookieEnable

ym:pv:deviceCategory

IsMobile, IsTablet, IsTV

1 — the hit came from this type of device

ym:pv:javascriptEnabled

JavascriptEnable

ym:pv:mobilePhone

MobilePhoneVendor

ym:pv:mobilePhoneModel

MobilePhoneModel

ym:pv:operatingSystemRoot

OSRoot, OSRootStr

Numeric and string ID of the OS group

ym:pv:physicalScreenHeight

—

Calculated field (see Formulas)

ym:pv:physicalScreenWidth

—

Calculated field (see Formulas)

ym:pv:screenColors

ResolutionDepth

ym:pv:screenFormat

—

Calculated field (see Formulas)

ym:pv:screenHeight

ResolutionHeight

ym:pv:screenOrientation

—

Calculated field (see Formulas)

ym:pv:screenWidth

ResolutionWidth

ym:pv:windowClientHeight

WindowClientHeight

ym:pv:windowClientWidth

WindowClientWidth

ym:pv:ipAddress

ClientIP, ClientIP6

IPv4 or IPv6 address from which the TCP connection was established

ym:pv:regionCity

—

To learn more, see Location data

ym:pv:regionCountry

—

To learn more, see Location data

ym:pv:regionCityID

—

To learn more, see Location data

ym:pv:regionCountryID

—

To learn more, see Location data

ym:pv:isPageView

IsPageView

ym:pv:iFrame

IsIFrame

ym:pv:link

IsLink

ym:pv:download

IsDownload

ym:pv:notBounce

IsNotBounce

ym:pv:artificial

IsArtifical

ym:pv:parsedParamsKey1

ParsedParams.Key1

ym:pv:parsedParamsKey2

ParsedParams.Key2

ym:pv:parsedParamsKey3

ParsedParams.Key3

ym:pv:parsedParamsKey4

ParsedParams.Key4

ym:pv:parsedParamsKey5

ParsedParams.Key5

ym:pv:parsedParamsKey6

ParsedParams.Key6

ym:pv:parsedParamsKey7

ParsedParams.Key7

ym:pv:parsedParamsKey8

ParsedParams.Key8

ym:pv:parsedParamsKey9

ParsedParams.Key9

ym:pv:parsedParamsKey10

ParsedParams.Key10

ym:pv:httpError

HTTPError

ym:pv:networkType

NetworkType

ym:pv:shareService

ShareService

ym:pv:shareURL

ShareURL

ym:pv:shareTitle

ShareTitle

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

ym:s:visitID

VisitID

ym:s:counterID

CounterID

ym:s:watchIDs

WatchIDs

ym:s:date

StartDate

ym:s:dateTime

—

Convert UTCStartTime to your target time zone

ym:s:dateTimeUTC

UTCStartTime

ym:s:isNewUser

—

Calculated field (see Formulas)

ym:s:startURL

StartURL

ym:s:endURL

EndURL

ym:s:pageViews

PageViews

ym:s:visitDuration

Duration

Session duration in seconds

ym:s:bounce

IsBounce

ym:s:ipAddress

ClientIP, ClientIP6

ym:s:regionCountry

—

To learn more, see Location data

ym:s:regionCity

—

To learn more, see Location data

ym:s:regionCountryID

—

To learn more, see Location data

ym:s:regionCityID

—

To learn more, see Location data

ym:s:clientID

ClientID, FirstPartyCookie

ClientID includes both the domain cookie and the value sent via the Measurement Protocol, while FirstPartyCookie is stored separately

ym:s:networkType

NetworkType

ym:s:goalsID

Goals.ID

ym:s:goalsSerialNumber

Goals.Serial

ym:s:goalsDateTime

Goals.EventTime

ym:s:goalsPrice

Goals.Price

ym:s:goalsOrder

Goals.OrderID

ym:s:goalsCurrency

Goals.CurrencyID

ym:s:lastTrafficSource

—

To learn more, see Attribution

ym:s:lastAdvEngine

—

To learn more, see Attribution

ym:s:lastReferalSource

—

To learn more, see Attribution

ym:s:lastSearchEngineRoot

—

To learn more, see Attribution

ym:s:lastSearchEngine

—

To learn more, see Attribution

ym:s:lastSocialNetwork

—

To learn more, see Attribution

ym:s:lastSocialNetworkProfile

—

To learn more, see Attribution

ym:s:referer

Referer

ym:s:lastDirectClickOrder

TrafficSource.ClickDirectCampaignID

Yandex Direct campaign ID

ym:s:lastDirectBannerGroup

TrafficSource.ClickGroupBannerID

Yandex Direct ad group ID

ym:s:lastDirectClickBanner

TrafficSource.ClickBannerID

Ad ID

ym:s:lastDirectClickOrderName

—

There's no direct equivalent. Use TrafficSource.DirectCLID instead. It stores the Yandex Direct ad click ID (YCLID).

ym:s:lastClickBannerGroupName

—

There's no direct equivalent. Use TrafficSource.DirectCLID instead.

ym:s:lastDirectClickBannerName

—

There's no direct equivalent. Use TrafficSource.DirectCLID instead.

ym:s:lastDirectPhraseOrCond

—

There's no direct equivalent. Use TrafficSource.DirectCLID instead.

ym:s:lastDirectPlatformType

—

There's no direct equivalent. Use TrafficSource.DirectCLID instead.

ym:s:lastDirectPlatform

TrafficSource.ClickTargetType

Placement site

ym:s:lastDirectConditionType

—

There's no direct equivalent. Use TrafficSource.DirectCLID instead.

ym:s:lastCurrencyID

Goals.CurrencyID, EPurchase.CurrencyID

ym:s:from

TrafficSource.FromTag

ym:s:UTMCampaign

TrafficSource.UTMCampaign

ym:s:UTMContent

TrafficSource.UTMContent

ym:s:UTMMedium

TrafficSource.UTMMedium

ym:s:UTMSource

TrafficSource.UTMSource

ym:s:UTMTerm

TrafficSource.UTMTerm

ym:s:openstatAd

TrafficSource.OpenstatAdID

ym:s:openstatCampaign

TrafficSource.OpenstatCampaignID

ym:s:openstatService

TrafficSource.OpenstatServiceName

ym:s:openstatSource

TrafficSource.OpenstatSourceID

ym:s:hasGCLID

TrafficSource.HasGCLID

ym:s:lastGCLID

—

To learn more, see Attribution

ym:s:firstGCLID

—

To learn more, see Attribution

ym:s:lastSignificantGCLID

—

To learn more, see Attribution

ym:s:browserLanguage

BrowserLanguage

ym:s:browserCountry

BrowserCountry

ym:s:clientTimeZone

ClientTimeZone

ym:s:deviceCategory

IsMobile, IsTablet, IsTV

ym:s:mobilePhone

MobilePhoneVendor

ym:s:mobilePhoneModel

MobilePhoneModel

ym:s:operatingSystemRoot

OSRoot, OSRootStr

ym:s:operatingSystem

OSStr, OS

ym:s:browser

UserAgentStr

ym:s:browserMajorVersion

UserAgentMajor

ym:s:browserMinorVersion

UserAgentMinor

ym:s:browserEngine

BrowserEngineID

ym:s:browserEngineVersion1

BrowserEngineVersion1

ym:s:browserEngineVersion2

BrowserEngineVersion2

ym:s:browserEngineVersion3

BrowserEngineVersion3

ym:s:browserEngineVersion4

BrowserEngineVersion4

ym:s:cookieEnabled

CookieEnable

ym:s:javascriptEnabled

JavascriptEnable

ym:s:screenFormat

—

Calculated field (see Formulas)

ym:s:screenColors

ResolutionDepth

ym:s:screenOrientation

—

Calculated field (see Formulas)

ym:s:screenWidth

ResolutionWidth

ym:s:screenHeight

ResolutionHeight

ym:s:physicalScreenWidth

—

Calculated field (see Formulas)

ym:s:physicalScreenHeight

—

Calculated field (see Formulas)

ym:s:windowClientWidth

WindowClientWidth

ym:s:windowClientHeight

WindowClientHeight

ym:s:purchaseID

EPurchase.ID

ym:s:purchaseDateTime

EPurchase.EventTime

ym:s:purchaseAffiliation

EPurchase.Affiliation

ym:s:purchaseRevenue

EPurchase.Revenue

ym:s:purchaseTax

EPurchase.Tax

ym:s:purchaseShipping

EPurchase.Shipping

ym:s:purchaseCoupon

EPurchase.Coupon

ym:s:purchaseCurrency

EPurchase.Currency

ym:s:purchaseProductQuantity

EPurchase.ProductQuantity

ym:s:productsPurchaseID

EPurchaseWithProducts.ID

ym:s:productsID

EAction.ProductID

ym:s:productsName

EAction.ProductName

ym:s:productsBrand

EAction.ProductBrand

ym:s:productsCategory

EAction.ProductCategory

ym:s:productsCategory1

EAction.ProductCategory1

ym:s:productsCategory2

EAction.ProductCategory2

ym:s:productsCategory3

EAction.ProductCategory3

ym:s:productsCategory4

EAction.ProductCategory4

ym:s:productsCategory5

EAction.ProductCategory5

ym:s:productsVariant

EAction.ProductVariant

ym:s:productsPosition

EAction.ProductPosition

ym:s:productsPrice

EAction.ProductPrice

ym:s:productsCurrency

EAction.ProductCurrency

ym:s:productsCoupon

EAction.ProductCoupon

ym:s:productsQuantity

EAction.ProductQuantity

ym:s:impressionsURL

—

See E-commerce data

ym:s:impressionsDateTime

—

See E-commerce data

ym:s:impressionsProductID

—

See E-commerce data

ym:s:impressionsProductName

—

See E-commerce data

ym:s:impressionsProductBrand

—

See E-commerce data

ym:s:impressionsProductCategory

—

See E-commerce data

ym:s:impressionsProductCategory1

—

See E-commerce data

ym:s:impressionsProductCategory2

—

See E-commerce data

ym:s:impressionsProductCategory3

—

See E-commerce data

ym:s:impressionsProductCategory4

—

See E-commerce data

ym:s:impressionsProductCategory5

—

See E-commerce data

ym:s:impressionsProductVariant

—

See E-commerce data

ym:s:impressionsProductPrice

—

See E-commerce data

ym:s:impressionsProductCurrency

—

See E-commerce data

ym:s:impressionsProductCoupon

—

See E-commerce data

ym:s:offlineCallTalkDuration

Goals.CallTalkDuration

Call duration in seconds

ym:s:offlineCallHoldDuration

Goals.CallHoldDuration

Call hold duration in seconds

ym:s:offlineCallMissed

Goals.CallMissed

Whether the call was missed

ym:s:offlineCallTag

Goals.CallTag

Tags associated with the call

ym:s:offlineCallFirstTimeCaller

Goals.CallFirstTimeCaller

Whether that was the first call from this customer

ym:s:offlineCallURL

Goals.Call

Page from which the call was made

ym:s:parsedParamsKey1

ParsedParams.Key1

ym:s:parsedParamsKey2

ParsedParams.Key2

ym:s:parsedParamsKey3

ParsedParams.Key3

ym:s:parsedParamsKey4

ParsedParams.Key4

ym:s:parsedParamsKey5

ParsedParams.Key5

ym:s:parsedParamsKey6

ParsedParams.Key6

ym:s:parsedParamsKey7

ParsedParams.Key7

ym:s:parsedParamsKey8

ParsedParams.Key8

ym:s:parsedParamsKey9

ParsedParams.Key9

ym:s:parsedParamsKey10

ParsedParams.Key10

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 — undefined
  • 1 — portrait orientation
  • 2 — 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 the EAction.Type field.
  • EPurchase.* — array of purchases made during a session. One user can make multiple purchases during a session.
  • EPurchaseWithProducts.* — array of purchased products. It matches EAction.* 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 the EPromotion.Type field.