---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.1
alternate:
  - https://yandex.com/support/metrica/en/code/counter-initialize.md
  - https://yandex.com/support/metrica/es/code/counter-initialize.md
  - https://yandex.com/support/metrica/pt/code/counter-initialize.md
  - https://yandex.com/support/metrica/ru/code/counter-initialize.md
  - https://yandex.com/support/metrica/tr/code/counter-initialize.md
  - https://yandex.com/support/metrica/zh/code/counter-initialize.md
  - href: en/code/counter-initialize.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
title: Tag initialization
description: How to initialize a tag and initialization parameters, how to enable a tag using the tag management system.
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/support/metrica/en/llms.txt


# Tag initialization


{% note tip %}

Working with the JavaScript API requires knowledge of HTML and JavaScript. If you don’t know these languages, contact your website developer or webmaster.

{% endnote %}


Go to `https://mc.yandex.ru/metrika/tag.js` and download the JavaScript library, which is required for the tag to work.

The code for enabling the library is available on the tag editing page. The library can be loaded asynchronously (recommended) or synchronously, but its functionality remains the same.

To create and manage a tag, use the `ym` method. It is created in the download code:
```javascript
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
```

`ym` requires the tag ID and the name of the function being called. The method can also be passed arguments of the invoked function. For example, to initialize a tag, you need to pass the tag ID, the name of the `init` function, and an array of parameters:

```javascript
ym(XXXXXXXX, "init", {clickmap: true, webvisor: true});
```

If you don’t want to pass parameters to the function, initialization looks like this:

```javascript
ym(XXXXXXXX, "init", {});
```

The part of the code containing the main initialization parameters is generated on the **Settings** page. The full list of initialization parameters is shown in the table.

Functions that can be called via the `ym` method are described in the [methods reference](https://yandex.com/support/metrica/en/objects/method-reference.md).

## Tag initialization parameters

#|

||
**Name**
|
**Default value**
|
**Type**
|
**Description**
||
||
`accurateTrackBounce`
|
`true`
|
Boolean \| Number
|
Accurate bounce rate The parameter can accept these values:

- `true` — Enable the accurate bounce rate, with a non-bounce event registered after 15,000 ms (15 s).
- `false` — Don't enable the accurate bounce rate.
- `<N>` (integer) — Enable the accurate bounce rate. Non-bounce events are recorded after `<N> ms`.
||
||
`childIframe`
|
`false`
|
Boolean
|
Whether to [record iframe contents](https://yandex.com/support/metrica/en/webvisor/iframe-support.md) without a tag in a child window.
||
||
`clickmap`
|
`true`
|
Boolean
|
Whether to collect data for a click map
||
||
`defer`
|
`false`
|
Boolean
|
Whether to disable automatically sending data during tag initialization.
||
||
`ecommerce`
|
`false`
|
Boolean \| String \| Array
|
[E-commerce](https://yandex.com/support/metrica/en/ecommerce/about.md) data collection.

- `true` — Enable e-commerce data collection. Equivalent to the `dataLayer` value (if the option is [enabled in Yandex Metrica](https://yandex.com/support/metrica/en/data/e-commerce.md#3)). Data is transferred via a JavaScript array named `dataLayer` in the global namespace (`window.dataLayer`).
- `false` — Disable e-commerce data collection.
- `<objectName>` (String) — Enable e-commerce data collection. Data is transmitted via a JavaScript array named `<objectName>` in the global namespace (`window.<objectName>`).
- `<array>` (Array) — Enable e-commerce data collection. Data is transmitted via a JavaScript `<array>`
||
||
`params`
|
—
|
Object \| Array
|
Session parameters transmitted during tag initialization.

To transmit session parameters at any other time, use the [params](https://yandex.com/support/metrica/en/objects/params-method.md) method.
||
||
`userParams`
|
—
|
Object
|
Parameters of site users that are transmitted when initializing the tag.

To transmit user parameters at any other time, use the [userParams](https://yandex.com/support/metrica/en/objects/user-params.md) method.
||
||
`trackHash`
|
`false`
|
Boolean
|
Tracking of hash changes in the browser’s address bar
||
||
`trackLinks`
|
`true`
|
Boolean
|
Track clicks on outbound links.
||
||
`trustedDomains`
|
—
|
Array
|
Indicates a trusted domain for [recording the contents of a child iframe](https://yandex.com/support/metrica/en/webvisor/iframe-support.md) Contains the domain address of the parent window
||
||
`type`
|
`0`
|
Number
|
Tag type. 1 for YAN.
||
||
`webvisor`
|
`false`
|
Boolean
|
Whether to use Session Replay
||
||
`triggerEvent`
|
`false`
|
Boolean
|
Whether to check if the tag is ready.
||
||
`sendTitle`
|
`true`
|
Boolean
|
Title records. If titles contain private data, the parameter should be set to `false` during initialization: `sendTitle: false`.
||
||
`ssr`
|
`true`
|
Boolean
|
A technical parameter used by the ad tag.
||
|#

## Checking tag initialization {#check-initialize}

You can use a special JavaScript event to find out if the tag is ready to operate. However, you must add the `triggerEvent` parameter set to `true` in the code snippet:
```
ym(XXXXXXXX, "init", {triggerEvent: true});
```
 For jQuery, you can use the following code sample up to the moment of tag initialization:

```xml
jQuery(document).on('yacounterXXXXXXinited', function () {
    console.log('tag yaCounterXXXXXX ready');
});
```




<!-- source: en/_includes/buttons/chat-button.md -->
[Chat with us](https://yandex.com/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/support-2.md -->
<div class="cut-button">

{% cut "Write an email" %}

<!-- source: en/_includes/popup/id-popup/wrong-sup.md -->
Please note: Our support team will never initiate a call to you. Do not follow any instructions of people who call you and introduce themselves as the Yandex Metrica support team.
<!-- endsource: en/_includes/popup/id-popup/wrong-sup.md -->

<div style="padding: 15px;
     margin: 10px 0;
     background: #FFFFFF;
     border-radius: 10px;
     border: 1px solid var(--yc-color-line-generic);">
  <iframe style="background: #FFFFFF;"
        height="700"
        width="100%"
        frameborder="0"
        src="https://forms.yandex.com/surveys/10011833/?&iframe=1&lang=en">
  </iframe>
</div>

{% endcut %}

</div>

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

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

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

<div class="borderless-table">

#|
||
Useful links

- [Demo tag](https://metrica.yandex.com/r/dashboard?)
- [Add a tag](https://metrica.yandex.com/add/)
- [Free tag setup](https://yandex.com/promo/freeservice/metrica?utm_source=help_metrica_en&utm_medium=cpc&utm_campaign=1)
- [Yandex Metrica API](https://tech.yandex.com/metrika/)
- [Suggest your idea](https://yandex.com/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 -->
