---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://yandex.com.tr/support/metrica/en/code/install-counter-amp.md
  - https://yandex.com.tr/support/metrica/es/code/install-counter-amp.md
  - https://yandex.com.tr/support/metrica/pt/code/install-counter-amp.md
  - https://yandex.com.tr/support/metrica/ru/code/install-counter-amp.md
  - https://yandex.com.tr/support/metrica/tr/code/install-counter-amp.md
title: Installing a counter on a site with AMP
description: How to install a tag on a site with AMP.
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/support/metrica/en/llms.txt


# Installing and setting up a tag on a site with AMP

A Yandex Metrica counter executes JavaScript. If you install the tag code on a site that uses [Accelerated Mobile Pages](https://amp.dev/about/how-amp-works/) (AMP), the site’s pages won’t pass [validation](https://validator.ampproject.org/). This is because the AMP technology restricts the use of JavaScript and HTML5. To get around this issue, you can install the tag in a special way.


{% note info %}

Note that in this case the following Yandex Metrica features won't be supported: [E-commerce](https://yandex.com.tr/support/metrica/en/ecommerce/about.md), [Session Replay](https://yandex.com.tr/support/metrica/en/webvisor/info.md), and tracking [Share button](https://yandex.com.tr/support/metrica/en/content/share-button.md) clicks.


{% endnote %}


## Enabling a tag on a site with AMP {#how-to}


{% note alert %}

Sites that use Accelerated Mobile Pages (AMP) technology cannot collect content analytics data.

{% endnote %}


Make changes to the HTML code on your site’s pages:

1. Tracking user actions on sites with AMP uses the additional [amp-analytics](https://amp.dev/documentation/components/amp-analytics/?format=websites) component. Add it to your web page code, within the `head` element:
    
    ```javascript
    <head>
        ...
            
        ...
    </head>
    ```
    
1. Edit the `body` element: add the `amp-analytics` element. In order for session data to be transmitted to Yandex Metrica, set the `type` attribute to the value `metrika`, and use the `counterId` variable to set the counter number.
    
    ```javascript
    <body>
        ...
            <amp-analytics type="metrika">
                
            </amp-analytics>
        ...
    </body>
    ```
    


## Transmitting data {#data}


{% note alert %}

When a user opens an AMP page, Yandex Metrica registers a [view](*pageview) (`pageview`). This means that you don’t need to transmit this event to Yandex Metrica. If you do send it, Yandex Metrica reports will show the wrong number of pageviews.

{% endnote %}


To transmit data when the tag is initialized, use:

- The [yaParams](https://yandex.com.tr/support/metrica/en/data/visit-params-data.md) variable for sending session parameters.
- Attributes of [triggers](https://amp.dev/documentation/components/amp-analytics/?format=websites#triggers) for transmitting events such as goal completions.

### Sending session parameters and user parameters {#params}

Example of transmitting custom [session parameters](https://yandex.com.tr/support/metrica/en/data/visit-params-data.md) and [user parameters](https://yandex.com.tr/support/metrica/en/data/user-params-data.md) during a session by using the yaParams variable:

```javascript
...
"vars": {
             "counterId": "XXXXXX",
             "yaParams": "{\"key\":\"value\",\"__ymu\":{\"user_param_key\":\"user_param_value\"}}"
},
...
```

You can also transmit just the session parameters, or just the user parameters:


{% list tabs %}

- Session parameters

  
  ```javascript
  ...
  "vars": {
               "counterId": "XXXXXX",
               "yaParams": "{\"key\":\"value\"}"
  },
  ...
  ```
  

- User parameters

  
  ```javascript
  ...
  "vars": {
               "counterId": "XXXXXX",
               "yaParams": "{\"__ymu\":{\"user_param_key\":\"user_param_value\"}}"
  },
  ...
  ```

{% endlist %}


### Accurate bounce rate {#bounce}

To get the accurate bounce rate, use the [timer](https://amp.dev/documentation/components/amp-analytics/?format=websites#timer-trigger) trigger attribute:

```javascript
{
    ...
    "triggers": {
        "notBounce": {
            "on": "timer",
            "timerSpec": {
                "immediate": false,
                "interval": 15,
                "maxTimerLength": 14
            },
            "request": "notBounce"
        },
        ...
    }
}
```

### Conversion {#goal}

To track goal completion when a specific page element is clicked, use the [click](https://amp.dev/documentation/components/amp-analytics/?format=websites#click-trigger) trigger attribute.

```javascript
{
    ...
    "triggers": {
        "someGoalReach": {
            "on": "click",
            "selector": "#Button",
            "request": "reachGoal",
            "vars": {
                "goalId": "superGoalId",
                "yaParams": "{\"key\": \"value\"}" // When the goal is completed, the value of the variable from the event is used as the session parameters
            }
        },
        ...
    }
}
```


#|
||
**Field**
|
**Type**
|
**Description**
||
||
`goalId`
|
String
|
A goal identifier that is set when creating a [JavaScript event](https://yandex.com.tr/support/metrica/en/general/goal-js-event.md) goal in the Yandex Metrica interface.
||
|#

### Page scrolling {#scroll}

You can use the [scroll](https://amp.dev/documentation/components/amp-analytics/?format=websites#scroll-trigger) trigger attribute to register scrolling down to a specific point on the page (a percentage of the page height). You can set this event as a goal.

```javascript
{
    ...
    "triggers": {
        "halfScroll": {
            "on": "scroll",
            "scrollSpec": {
                "verticalBoundaries": [
                    50
                ]
            },
            "request": "reachGoal",
            "vars": {
                "goalId": "halfScrollGoal"
             }
        },
        "partsScroll": {
            "on": "scroll",
            "scrollSpec": {
                "verticalBoundaries": [
                    25,
                    90
                ]
            },
            "request": "reachGoal",
            "vars": {
                    "goalId": "partsScrollGoal"
            }
        },
        ...
    }
}
```

### Scrolling an infinite feed {#next-page-scroll}

An infinite feed can be used to view articles that follow each other. To register article-to-article click-throughs and views of each of them, use the [amp-next-page-scroll](https://amp.dev/documentation/components/amp-next-page/#analytics) trigger.

```javascript
{
    ...
    "triggers": {
        "trackScrollThrough": {
             "on": "amp-next-page-scroll",
             "request": "pageview"
        },
        ...
    }
}
```

### Loading an individual page element {#visible}

Use the [visible](https://amp.dev/documentation/components/amp-analytics/?format=websites#page-and-element-visibility-trigger) trigger attribute to register when elements on a page are displayed on the user’s screen.

### General example of the tag code {#general-amp}

The code sample is provided only to illustrate the capabilities of the tag. When copying it, delete the comments (//<...>), replace XXXXXXXX with your tag number, and make additional changes as necessary (for example, configure transmitting user parameters and session parameters).

```
<body>
    ...
        <amp-analytics type="metrika">
            
        </amp-analytics>
    ...
</body>
```

### Learn more

- [General information for integrating analytics tools on a site with AMP](https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/integrating-analytics.md)

<!-- source: en/_includes/buttons/chat-button.md -->
[Chat with us](https://yandex.com.tr/chat/#/user/036e6a02-3620-9cdc-4c5e-a34667a7379e?utm_source=spravka){.button}

<!-- source: en/_includes/styles/href-to-button.md -->

<!-- endsource: en/_includes/styles/href-to-button.md -->
<!-- endsource: en/_includes/buttons/chat-button.md -->

<!-- source: en/_includes/code/texing-button.md -->
<div class="cut-button">

{% cut "Write an email" %}

<!-- source: en/_includes/popup/id-qanda/check1.md -->
If you were unable to [independently check the tag](https://yandex.com.tr/support/metrica/en/general/check-counter.md), follow the recommendations below.
<!-- endsource: en/_includes/popup/id-qanda/check1.md -->

{% list tabs radio %}

- Data is not sent to the console

  {% include [qanda-check2-2](../_includes/popup/id-qanda/check2-2.md) %}

  {% cut "The recommendations did not help" %}


  <div style="padding: 15px;
         margin: 10px 0;
         background: #FFFFFF;
         border-radius: 10px;
         border: 1px solid var(--g-color-line-generic);">
    <iframe style="background: #FFFFFF;"
            height="700"
            width="100%"
            frameborder="0"
            src="https://forms.yandex.com.tr/surveys/1706/?&theme=Dannye v konsoli ne otpravlyayutsya&iframe=1&lang=tr">
    </iframe>
  </div>

  {% endcut %}

- There is data in the console, but the reports do not appear

  <!-- source: en/_includes/popup/id-qanda/check2-3.md -->
  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:
  <!-- endsource: en/_includes/popup/id-qanda/check2-3.md -->

  <!-- source: en/_includes/popup/id-qanda/check2-4.md -->
  - 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.
  <!-- endsource: en/_includes/popup/id-qanda/check2-4.md --> 

  {% cut "The recommendations did not help" %}


  <div style="padding: 15px;
           margin: 10px 0;
           background: #FFFFFF;
           border-radius: 10px;
           border: 1px solid var(--g-color-line-generic);">
    <iframe style="background: #FFFFFF;"
              height="700"
              width="100%"
              frameborder="0"
              src="https://forms.yandex.com.tr/surveys/1706/?&theme=Dannye v konsoli est, no otchety ne otobrazhayutsya&iframe=1&lang=tr">
    </iframe>
  </div>

  {% endcut %}

{% endlist %}

{% endcut %}

</div>

<!-- source: en/_includes/styles/cut-button.md -->

<!-- endsource: en/_includes/styles/cut-button.md -->
<!-- endsource: en/_includes/code/texing-button.md -->

<!-- source: en/_includes/footer-links.md -->
- - -

<div class="borderless-table">

#|
||
Useful links

- [Demo tag](https://metrica.yandex.com.tr/r/dashboard?)
- [Add a tag](https://metrica.yandex.com.tr/add/)
- [Free tag setup](https://yandex.com.tr/promo/freeservice/metrica?utm_source=help_metrica_tr&utm_medium=cpc&utm_campaign=1)
- [Yandex Metrica API](https://tech.yandex.com.tr/metrika/)
- [Suggest your idea](https://yandex.com.tr/support/metrica/troubleshooting/idea.html)
- [Discuss in Telegram](https://t.me/yandexmetrika)
|
Online training

- [Get a Yandex Metrica certificate](https://yandex.ru/adv/expert/exam/metrika/?utm_source=metrika_help&utm_medium=web&utm_campaign=static&utm_content=useful_links)


- [Take a training course](https://yandex.com/adv/edu/online/metrika?utm_source=metrika_help&utm_medium=web&utm_campaign=static&utm_content=useful_links)

||
|#

</div>

<!-- source: en/_includes/styles/table-style.md -->

<!-- endsource: en/_includes/styles/table-style.md -->
<!-- endsource: en/_includes/footer-links.md -->

<!-- source: en/_includes/styles/cut-button.md -->

<!-- endsource: en/_includes/styles/cut-button.md -->

<!-- source: en/_includes/styles/href-to-button.md -->

<!-- endsource: en/_includes/styles/href-to-button.md -->

[*pageview]: Loading one of a site’s pages when a user navigates to it. Pageviews also include page refreshes, AJAX site updates, and sending data using the [hit method](https://yandex.ru/support/metrica/objects/hit.html). 

[*goalid]: **Type**

String

**Description**

The goal identifier that is set when creating a [JavaScript event](https://yandex.ru/support/metrica/general/goal-js-event.html) goal in the Yandex Metrica interface.
{% included (../_includes/popup/id-qanda/check2-2.md) %}
   This might happen for the following reasons:
   - The tag is installed incorrectly. For example, the CMS modified the tag code. 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.


{% endincluded %}