Ecommerce

Tip. Working with the JavaScript API requires knowledge of HTML and JavaScript. If you don't have these skills, contact your website
developer or webmaster.

Yandex.Metrica offers features for collecting and analyzing ecommerce data.

Attention. In the past, preset session parameters were used for transmitting order parameters. This method is outdated. It is supported for backward compatibility, but we don't recommend using it. The Ecommerce component of Yandex.Metrica allows you to track more data and provides more sophisticated analysis tools.

Enabling Ecommerce

To connect Ecommerce:

In the Settings section, go to the Counter code tab and enable the option Dispatch ecommerce data to Metrica. A container for collecting data from dataLayer will be added to the counter code by default.

Embed (or update) the counter code on all the site pages that contain information about products and orders (item details,
the “Add to basket” button, and so on).

Data representation and transfer

In Ecommerce, every product item is an object that certain actions can be performed on, such as viewing the complete item
description or adding it to the basket. This data is transmitted as JavaScript objects containing the action ID and a list
of descriptions of items that this action was performed on. In the context of the JavaScript API, we call these objects Ecommerce objects.

To pass data in the form of Ecommerce objects to the Yandex.Metrica service, you need to put them in a special JavaScript
array using the push method. We call this array the data container.

The data container must be located in the global namespace, and its name must match the name specified during counter configuration
or initialization. If the data container is named dataLayer, or the Yandex.Metrica counter was initiated with the ecommerce parameter set to true, it is assumed that the data container is the window.dataLayer array.

The name of the data container and the structure of the Ecommerce objects in it correspond to the same entities in Google Analytics Enhanced Ecommerce. This means that if you have already set up transmitting data to Google Analytics Enhanced Ecommerce and enabled Ecommerce
in Yandex.Metrica, the latter will start collecting data the same way.

The field name (substituted in place of <actionType>) is the identifier of an action performed with a set of products.

Possible values:

detail — Viewing the full item description (product profile).

add — Adding the item to the basket.

remove — Removing the item from the basket.

purchase — Purchasing.

If information about removing the item was transmitted to Yandex.Metrica, the report might show a negative number of items
(the total is calculated by subtracting the number of deleted items from the total number of added items). If the price of
the item was transmitted, it might also have a negative value in the report.

The field name (substituted in place of <actionType>) is the identifier of an action performed with a set of products.

Possible values:

detail — Viewing the full item description (product profile).

add — Adding the item to the basket.

remove — Removing the item from the basket.

purchase — Purchasing.

If information about removing the item was transmitted to Yandex.Metrica, the report might show a negative number of items
(the total is calculated by subtracting the number of deleted items from the total number of added items). If the price of
the item was transmitted, it might also have a negative value in the report.

Action data

The structure of the object describing the action is denoted as <actionField>.

When transmitting data about an action, Yandex.Metrica creates a goal. This allows you to get information about revenue from
Yandex.Direct ad campaigns. In the list of available goals in Yandex.Direct, this goal is shown as “eCommerce: Purchase (counter № <counter ID>)”. You can track goal completion yourself by transmitting the goal_id field.

Solutions to problems

If the information transmitted using Ecommerce doesn't show up in Yandex.Metrica reports, consider the following reasons:

Errors in the transmitted fields. To check the validity of your data, use the JSON.stringify(dataLayer) command in the browser console. For validation, we recommend contacting your webmaster or other person responsible for maintaining
the website.

The actionField field doesn't contain data. To transmit information about a purchase, you must use actionField.