Installing and configuring a tag in Facebook Instant Articles

You can install your Yandex Metrica tag in Facebook Instant Articles *.

Due to the way Instant Articles are implemented, the JavaScript tag code is isolated from other HTML elements. This means that the following features of Yandex Metrica are available:

  • Session Replay
  • Click map, link map, and scroll map
  • Form analysis
  • E-commerce data

You can use special HTML elements to add the Yandex Metrica code snippet to an instant article.

Installing a tag

注意

Content analytics data cannot be collected from Facebook * Instant Articles.

Add the following code to the body element in the instant article:

...
<figure class="op-tracker">
  <iframe>
    <!-- Tag code -->
  </iframe>
</figure>
...

The tag registers sessions for the page that is specified in the head element as canonical:

...
<head>
  <meta charset="utf-8">
  <link rel="canonical" href="http://example.com/page.html">
  <meta property="op:markup_version" content="v1.0">
</head>
...

To check that the tag is working correctly, use the endpoint from Facebook *.

Transmitting session parameters

  1. Create the yaParams JavaScript object:

    ...
    var yaParams = {
      title: "Article title",
      referrer: "Article referrer"
    }
    ...
    
  2. Send parameters for tag initialization:

    ...
    ym(XXXXXX, 'init', {params: window.yaParams||{}});
    ...
    

    Facebook * provides a specific set of data about instant articles that can be used as session parameters. You can get this data from the ia_document JavaScript object.

Transmitting user parameters

  1. Send pageview data using the hit method after tag initialization:

    ...
    ym(XXXXXX, 'init', {
      defer: true
    });
    ym(XXXXXX, 'hit', ia_document.shareURL, {
      referer: ia_document.referrer,
      title: ia_document.title
    });
    ...
    
  2. Send user parameters by calling the UserParams function:

    ...
    ym(XXXXXX, 'userParams', { user_key: "user_value"});
    ...
    

Example of tag integration

<body>
  ...
  <figure class="op-tracker">
    <iframe>
      <script type="text/javascript"><script>
        (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?id=XXXXXX', 'ym')

            ym(XXXXXX, 'init', { 
                trackLinks:true,
                accurateTrackBounce:true,
                params: window.yaParams||{title: "no title"}
            });

      </script>
      <noscript><div><img src="https://mc.yandex.ru/watch/XXXXXX" style="position:absolute; left:-9999px;" alt=""/></div></noscript>
    </iframe>
  </figure>
  ...
</body>

XXXXXX — Your tag number.

与我们聊天

发送电子邮件

如果您无法独立检查计数器,请遵循以下建议。

发生这种情况的原因可能如下:

  • 计数器安装不正确。 例如 CMS 修改了计数器代码。 重新安装计数器或联系您的 CMS 的支持服务。
  • 损坏的脚本导致 Yandex Metrica 计数器无法在网站上运行。 您可以在浏览器控制台中检查这一点。
这些建议没有帮助

这意味着信息正在传输到 Yandex Metrica。 但是,由于以下任一原因,数据可能不会显示在报表中:

  • 数据被发送到具有不同编号的计数器。
  • 计数器设置中的 Filters 选项卡指定了过于严格的筛选条件。 删除不需要的筛选条件。
  • 计数器设置中的 Filters 选项卡已启用 Don't count my sessions 筛选条件。 这意味着计数器不会统计您自己的会话。 尝试使用您的浏览器在“隐身”模式下访问该网站。
这些建议没有帮助

在俄罗斯被禁止。

XXXXXX 是您的计数器编号。