Installing and configuring the tag for SPA sites

  1. Tag initialization
  2. Sending conversions
  3. Transmitting session parameters and user parameters
  4. Transmitting e-commerce data
  5. Enabling Session Replay, click maps, link maps, and Form Analysis

Tag initialization

To use a Yandex.Metrica tag on SPA sites, follow these steps:

  1. When initializing the tag, set the defer parameter to true. This is required to disable the automatic submission of data on views. To register page impressions, use the hit function, as described in point 3.

    Example of initializing the tag:

    ym(XXXXXX, 'init', {
        defer: true,
  2. In order for Yandex.Metrica to register important changes to a page, analyze the logic of your site and insert a hit function in the appropriate places so it’s triggered each time you believe the page has changed.

    Call the hit function:

    ym(XXXXXX, 'hit', url[, options]);
    Parameters that can be passed in the hit function:


    Default value



    url *


    Current page URL



    options fields


    The callback function to call after sending pageview data



    Context accessed by the this keyword in the callback function



    Session parameters



    The URL that the user loaded the current page contents from

    options.title document.title


    Title of the current page

    options.params fields:


    Revenue by goal. You can set the cost in currency or Yandex units.



    Use this field if you want to pass the goal cost in currency. Yandex.Metrica recognizes three-letter ISO 4217 currency codes

    If a different currency is passed, null values will be sent instead of currencies and amounts.

    Example of calling the hit function
    ym(XXXXXX, 'init', {});
    ym(XXXXXX, 'hit', '#contacts', {
        title: 'Contact information',
        referer: ''

Sending conversions

To track events on the site that do not change the page URL, use the reachGoal function:
ym(XXXXXX, 'reachGoal', 'TARGET_NAME);

Examples of setting goals in the code snippet.

Transmitting session parameters and user parameters

ym(XXXXXX, 'params', {param1: 'param_value1'})

Transmitting e-commerce data

To transmit data, enable e-commerce in Yandex.Metrica.

To collect e-commerce data correctly, you need to insert the hit function once when the user goes to a new page.
Example of sending e-commerce data
    "ecommerce": {
        "purchase": {
            "actionField": {
                "id" : "TRX987"
            "products": [
                    "id": "25341",
                    "name": "Men's Yandex hoodie",
                    "price": 1345.26,
                    "brand": "Yandex / Яndex",
                    "category": "Clothing/Men's clothing/Hoodies and sweatshirts",
                    "variant": "Orange"
     Yandex women''s hoodie",
                    "price": 1543.62,
                    "brand": "Yandex / Яndex",
                    "category": "Clothing/Women's clothing/Hoodies and sweatshirts",
                    "variant": "White",
                    "quantity": 3

Enabling Session Replay, click maps, link maps, and Form Analysis

You can connect Session Replay 2.0, click maps and link maps. The scroll map, form analysis, and Session Replay 1.0 are not supported.

If you were unable to independently check the tag, follow the recommendations below.

This might happen for the following reasons:

  • The tag is installed incorrectly. For example, the CMS modified the code snippet. Reinstall the tag or contact the support service for your CMS.
  • Broken scripts are preventing the Yandex.Metrica tag from working on the site. You can check this in the browser console.

This means that information is being transmitted to Yandex.Metrica. However, the data might not be shown in reports for any of the following reasons:

  • Data is sent to a tag with a different number.
  • The Filters tab in the tag settings has overly strict filters defined. Remove unneeded filters.
  • The Filters tab in the tag settings has the Don't count my sessions filter enabled. This means that the tag doesn't register your own sessions. Try accessing the site with your browser in “incognito” mode.