---
metadata:
  - name: generator
    content: Diplodoc Platform v5.72.0
alternate:
  - https://yandex.com.tr/support/metrica/en/pro/logs-api-migration.md
  - https://yandex.com.tr/support/metrica/ru/pro/logs-api-migration.md
  - href: https://yandex.com.tr/support/metrica/en/pro/logs-api-migration.md
    type: text/markdown
    title: Markdown version
  - href: https://yandex.com.tr/support/metrica/en/llms.txt?revision=r22488372
    rel: describedby
title: Migrating from Logs API to Data Streaming
description: A table of field mappings between Logs API and Data Streaming, formulas for calculated fields, working with attribution and geo-data.
---
> **Documentation capabilities:** Search, read sources, and browse this documentation: [agent guide](https://yandex.com.tr/support/metrica/docs-api/agent/overview?project=common%2Fsupport-metrika-tld-com-tr&lang=en).

> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/support/metrica/en/llms.txt?revision=r22488372


# Migrating from the Logs API to Data Streaming

{% note info %}

This feature is only available with the Yandex Metrica Pro package.

{% endnote %}

When you migrate from the [Logs API](https://yandex.com/dev/metrika/doc/api2/logs/intro.html) to [Data Streaming](https://yandex.com.tr/support/metrica/en/uploading-data/cloud.md) (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](https://yandex.com.tr/support/metrica/en/pro/data-work.md#visits). To automatically clean up outdated versions, use built-in ClickHouse engines like [CollapsingMergeTree](https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/collapsingmergetree).

## How to migrate from the Logs API to Data Streaming {#how-to-migrate}

1. [Create a ClickHouse cluster](https://cloud.yandex.ru/docs/managed-clickhouse/operations/cluster-create) in Yandex Cloud if you don't have one yet.
1. [Set up Data Streaming](https://yandex.com.tr/support/metrica/en/uploading-data/cloud.md#quick-start): 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.
1. Map the fields in your SQL queries and data marts using the [mapping tables](#hits-mapping) on this page.
1. For Logs API fields that don't have a direct equivalent in Data Streaming, use [formulas for calculated fields](#formulas).
1. Verify your data in the ClickHouse cluster by comparing query results against Logs API data for an overlapping date range.
1. 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 info %}

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.

{% endnote %}

To migrate smoothly and keep your data marts intact, use the sections on this page:

- [Hit field mapping table](#hits-mapping)
- [Session field mapping table](#visits-mapping)
- [Formulas for calculated fields](#formulas)
- [How attribution works](#attribution)
- [How to work with location data](#geo)
- [E-commerce data](#ecommerce)

## Hit field mapping table {#hits-mapping}

Below are the Logs API hit (event) fields and their matching fields in Data Streaming.

{% note info %}

Fields without a direct equivalent are marked as "Calculated field" (see [Formulas for calculated fields](#formulas)). Fields related to attribution and location data are covered in separate sections: [Attribution](#attribution) and [Location data](#geo).

{% endnote %}

#|
||**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](#attribution)||
||`ym:pv:lastSearchEngineRoot`|`SearchEngineRootID`, `SearchEngineRootStrID`|To learn more, see [Attribution](#attribution)||
||`ym:pv:lastSearchEngine`|—|To learn more, see [Attribution](#attribution)||
||`ym:pv:lastAdvEngine`|`AdvEngine`, `AdvEngineStrID`|To learn more, see [Attribution](#attribution)||
||`ym:pv:lastSocialNetwork`|`SocialSourceNetworkID`, `SocialSourceNetworkStrID`|To learn more, see [Attribution](#attribution)||
||`ym:pv:lastSocialNetworkProfile`|`SocialSourcePage`|To learn more, see [Attribution](#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](#formula-physcreenheight))||
||`ym:pv:physicalScreenWidth`|—|Calculated field (see [Formulas](#formula-physcreenwidth))||
||`ym:pv:screenColors`|`ResolutionDepth`||
||`ym:pv:screenFormat`|—|Calculated field (see [Formulas](#formula-screenformat))||
||`ym:pv:screenHeight`|`ResolutionHeight`||
||`ym:pv:screenOrientation`|—|Calculated field (see [Formulas](#formula-screenorientation))||
||`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](#geo)||
||`ym:pv:regionCountry`|—|To learn more, see [Location data](#geo)||
||`ym:pv:regionCityID`|—|To learn more, see [Location data](#geo)||
||`ym:pv:regionCountryID`|—|To learn more, see [Location data](#geo)||
||`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 {#visits-mapping}

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](#formula-isnewuser))||
||`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](#geo)||
||`ym:s:regionCity`|—|To learn more, see [Location data](#geo)||
||`ym:s:regionCountryID`|—|To learn more, see [Location data](#geo)||
||`ym:s:regionCityID`|—|To learn more, see [Location data](#geo)||
||`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](#attribution)||
||`ym:s:lastAdvEngine`|—|To learn more, see [Attribution](#attribution)||
||`ym:s:lastReferalSource`|—|To learn more, see [Attribution](#attribution)||
||`ym:s:lastSearchEngineRoot`|—|To learn more, see [Attribution](#attribution)||
||`ym:s:lastSearchEngine`|—|To learn more, see [Attribution](#attribution)||
||`ym:s:lastSocialNetwork`|—|To learn more, see [Attribution](#attribution)||
||`ym:s:lastSocialNetworkProfile`|—|To learn more, see [Attribution](#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](#attribution)||
||`ym:s:firstGCLID`|—|To learn more, see [Attribution](#attribution)||
||`ym:s:lastSignificantGCLID`|—|To learn more, see [Attribution](#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](#formula-screenformat))||
||`ym:s:screenColors`|`ResolutionDepth`||
||`ym:s:screenOrientation`|—|Calculated field (see [Formulas](#formula-screenorientation))||
||`ym:s:screenWidth`|`ResolutionWidth`||
||`ym:s:screenHeight`|`ResolutionHeight`||
||`ym:s:physicalScreenWidth`|—|Calculated field (see [Formulas](#formula-physcreenwidth))||
||`ym:s:physicalScreenHeight`|—|Calculated field (see [Formulas](#formula-physcreenheight))||
||`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](#ecommerce)||
||`ym:s:impressionsDateTime`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductID`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductName`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductBrand`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCategory`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCategory1`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCategory2`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCategory3`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCategory4`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCategory5`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductVariant`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductPrice`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCurrency`|—|See [E-commerce data](#ecommerce)||
||`ym:s:impressionsProductCoupon`|—|See [E-commerce data](#ecommerce)||
||`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 {#formulas}

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 {#formula-screenformat}

```sql
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 {#formula-screenorientation}

```sql
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 {#formula-physcreenwidth}

```sql
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 {#formula-physcreenheight}

```sql
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 {#formula-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.

```sql
TrafficSource.StartTime[indexOf(TrafficSource.Model, 3)] = UTCStartTime AS isNewUser
```

Where attribution `3` — "First session".

## Attribution {#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:

```sql
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

```sql
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](https://clickhouse.com/docs/ru/guides/clickhouse/working-with-arrays).

## Location data {#geo}

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`:

```sql
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](https://clickhouse.com/docs/sql-reference/functions/ym-dict-functions#regiontoname).

## E-commerce data {#ecommerce}

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`).

{% note 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.

{% endnote %}

- **`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.
