---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.1
alternate:
  - https://yandex.com/support/metrica/en/code/install-counter-fb.md
  - https://yandex.com/support/metrica/es/code/install-counter-fb.md
  - https://yandex.com/support/metrica/pt/code/install-counter-fb.md
  - https://yandex.com/support/metrica/ru/code/install-counter-fb.md
  - https://yandex.com/support/metrica/tr/code/install-counter-fb.md
  - https://yandex.com/support/metrica/zh/code/install-counter-fb.md
  - href: zh/code/install-counter-fb.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
title: 在 Facebook 即阅文中安装和配置计数器
description: 如何在 Facebook 即阅文中安装和配置计数器。
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/support/metrica/zh/llms.txt


# 在 Facebook 即阅文中安装和配置计数器

您可以在 [Facebook 即阅文](https://developers.facebook.com/docs/instant-articles)[ *](*prohibited-service)中安装 Yandex Metrica 计数器。

由于即阅文的实现方式，JavaScript 计数器代码与其他 HTML 元素是隔离的。 这意味着 Yandex Metrica 的以下功能可用：

- Session Replay
- Click map、link map 和 scroll map
- 表单分析
- E-commerce 数据

您可以使用特殊的 HTML 元素将 Yandex Metrica 代码片段添加到即阅文中。

## 安装计数器 {#integration}


{% note alert %}

无法从 Facebook[ *](*prohibited-service) 即阅文收集内容分析数据。

{% endnote %}


在即阅文中将以下代码添加到 `body` 元素：

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

该计数器为在 `head` 元素中指定为规范页面的页面统计会话：

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

要检查计数器是否正常工作，请使用来自 [Facebook 的端点](https://developers.facebook.com/docs/instant-articles/analytics?#analytics-services)[ *](*prohibited-service)。


## 传输会话参数 {#params}

1. 创建 `yaParams` JavaScript 对象：
    ```javascript
    ...
    var yaParams = {
      title: "Article title",
      referrer: "Article referrer"
    }
    ...
    ```
    
1. 发送计数器初始化参数：
    
    ```javascript
    ...
    ym([XXXXXXXX](*counter-number), 'init',{params: window.yaParams||{}});
    ...
    ```
    
    Facebook[ *](*prohibited-service) 提供有关即阅文的[一组特定数据](https://developers.facebook.com/docs/instant-articles/analytics#analytics-services)，该组数据可用作会话参数。 您可以从 `ia_document` JavaScript 对象获取此数据。
    
## 传输用户参数 {#user-params}

1. 计数器初始化后使用 [`hit`](https://yandex.com/support/metrica/zh/objects/hit.md) 方法发送页面浏览数据：

    ```javascript
    ...
    ym([XXXXXXXX](*counter-number), 'init', {
      defer: true
    });
    ym([XXXXXXXX](*counter-number), 'hit', ia_document.shareURL, {
      referer: ia_document.referrer,
      title: ia_document.title
    });
    ...
    ```
    
1. 通过调用 [`UserParams`](https://yandex.com/support/metrica/zh/objects/user-params.md) 函数发送用户参数：
    ```javascript
    ...
    ym([XXXXXXXX](*counter-number), 'userParams', { user_key: "user_value"});
    ...
    ```
    


## 计数器集成示例 {#example}

```javascript
<body>
  ...
  <figure class="op-tracker">
    <iframe>
      
      <noscript><div><img src="https://mc.yandex.ru/watch/[XXXXXXXX](*counter-number)" style="position:absolute; left:-9999px;" alt=""/></div></noscript>
    </iframe>
  </figure>
  ...
</body>
```

`XXXXXXXX` — 您的计数器编号。



<!-- source: zh/_includes/buttons/chat-button.md -->
[与我们聊天](https://yandex.com/chat/#/user/036e6a02-3620-9cdc-4c5e-a34667a7379e?utm_source=spravka){.button}

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

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

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

{% cut "发送电子邮件" %}

<!-- source: zh/_includes/popup/id-qanda/check1.md -->
如果您无法独立检查计数器，请遵循以下建议。
<!-- endsource: zh/_includes/popup/id-qanda/check1.md -->

{% list tabs radio %}

- 数据未发送到控制台

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

  {% cut "这些建议没有帮助" %}


  <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/surveys/1706/?&theme=Dannye v konsoli ne otpravlyayutsya&iframe=1&lang=en">
    </iframe>
  </div>

  {% endcut %}

- 控制台有数据，但报表不显示

  <!-- source: zh/_includes/popup/id-qanda/check2-3.md -->
  这意味着信息正在传输到 Yandex Metrica。 但是，由于以下任一原因，数据可能不会显示在报表中：
  <!-- endsource: zh/_includes/popup/id-qanda/check2-3.md -->

  <!-- source: zh/_includes/popup/id-qanda/check2-4.md -->
  - 数据被发送到具有不同编号的计数器。
  - 计数器设置中的 **Filters** 选项卡指定了过于严格的筛选条件。 删除不需要的筛选条件。
  - 计数器设置中的 **Filters** 选项卡已启用 **Don't count my sessions** 筛选条件。 这意味着计数器不会统计您自己的会话。 尝试使用您的浏览器在“隐身”模式下访问该网站。
  <!-- endsource: zh/_includes/popup/id-qanda/check2-4.md --> 

  {% cut "这些建议没有帮助" %}


  <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/surveys/1706/?&theme=Dannye v konsoli est, no otchety ne otobrazhayutsya&iframe=1&lang=en">
    </iframe>
  </div>

  {% endcut %}

{% endlist %}

{% endcut %}

</div>

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

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

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

<div class="borderless-table">

#|
||
实用链接

- [演示计数器](https://metrica.yandex.com/r/dashboard?)
- [添加计数器](https://metrica.yandex.com/add/)
- [免费计数器设置](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/)
- [提出您的想法](https://yandex.com/support/metrica/troubleshooting/idea.html)
|
线上培训



- [参加培训课程](https://yandex.com/adv/edu/online/metrika?utm_source=metrika_help&utm_medium=web&utm_campaign=static&utm_content=useful_links)

||
|#

</div>

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

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

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

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

[*prohibited-service]: 在俄罗斯被禁止。

[*counter-number]: XXXXXX 是您的计数器编号。
{% included (../_includes/popup/id-qanda/check2-2.md) %}
   发生这种情况的原因可能如下：
   - 计数器安装不正确。 例如 CMS 修改了计数器代码。 重新安装计数器或联系您的 CMS 的支持服务。
   - 损坏的脚本导致 Yandex Metrica 计数器无法在网站上运行。 您可以在浏览器控制台中检查这一点。


{% endincluded %}