---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://yandex.com/support/metrica/en/objects/hit.md
  - https://yandex.com/support/metrica/es/objects/hit.md
  - https://yandex.com/support/metrica/pt/objects/hit.md
  - https://yandex.com/support/metrica/ru/objects/hit.md
  - https://yandex.com/support/metrica/tr/objects/hit.md
  - https://yandex.com/support/metrica/zh/objects/hit.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/support/metrica/zh/llms.txt

# hit

<!-- source: zh/_includes/code/counter-initialize/id-counter-initialize/rest-js.md -->
{% note warning %}

使用 JavaScript API 需要了解 HTML 和 JavaScript。 如果您不了解这些语言，请联系您的网站开发人员或站长。

{% endnote %}
<!-- endsource: zh/_includes/code/counter-initialize/id-counter-initialize/rest-js.md -->


发送有关页面浏览次数的数据。 通常用于具有 AJAX 或 Flash 实现的页面。

```javascript
ym(XXXXXXXX, 'hit', [url[, options]])
```


{% note alert %}

[hit([url[, title[, referer[, params]]]])](https://yandex.com/support/metrica/zh/objects/hit-url-title-referer.md) 签名已过时。 支持向后兼容，但可能随时被弃用。 我们强烈不建议使用该方法。

{% endnote %}



#|
||
**参数**
|
**默认值**
|
**类型**
|
**描述**
||
||
`url`[*](*Параметр)
|
—
|
String?
|
视图所来自的页面的 URL。 如果未提供 URL，则使用来自 [`window.location.href`](https://yandex.com/support/metrica/zh/data/visit-params-example.md#goal) 的值。
||
||
`options`
|
—
|
Object
|
—
||
||
`options` 字段
|
>
|
>
||
||
`options.callback`
|
—
|
Function
|
发送页面浏览数据后调用的回调函数
||
||
`options.ctx`
|
—
|
Object
|
在回调函数中通过 `this` 关键字访问的上下文
||
||
`options.params`
|
—
|
Object
|
会话参数
||
||
`options.referer`
|
—
|
String
|
用户加载当前页面内容的 URL
||
||
`options.title`
|
`document.title`
|
String
|
当前页面的标题
||
||
`options.params` 对象的字段：
|
>
|
>
||
||
`order_price`
|
—
|
Double
|
[Revenue by goal](#price)。 您可以用货币或常规单位设置成本。
||
||
`currency`
|
—
|
String
|
如果您想以货币形式传递目标成本，请使用此字段。 Yandex Metrica 识别三个字母的 [ISO 4217 货币代码](https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=currency-codes)。

<!-- source: zh/_includes/ecommerce/data/id-about/currency-note.md -->
如果传递不同的货币，则将发送空值，而不是货币和金额。
<!-- endsource: zh/_includes/ecommerce/data/id-about/currency-note.md -->
||
|#
 
<sup >*</sup>必填参数。

借助 `url` 和 `options.referer` 参数，您可以使用没有架构（协议）和主机的 URL 路径。

在这种情况下，如果路径以 `/` 开始，则认为 URL 是从主机的根目录设置的。

```javascript
ym(XXXXXXXX, 'hit', '/contacts');
```

否则，认为该路径是相对于当前页面的。

```javascript
ym(XXXXXXXX, 'hit', 'contacts', {params:{'param': 'value'}});
```

> # 示例
> 
> ```javascript
> ym(XXXXXXXX, 'init', {});
> //...
> ym(XXXXXXXX, 'hit', '#contacts',{params:{
>     'Page title': 'Contact information',
>     'another_param': 'another_value'
> }});
> ```

## 按目标划分的收入 {#price}

如果页面浏览次数是您网站上配置的目标之一，您可以在方法参数中传输收入。 [有关 revenue by goal 的详细信息](https://yandex.com/support/metrica/zh/general/price-goal.md)

示例：

```javascript
var goalParams =
{
   order_price: 1000.35,
   currency: "RUB"
};
ym(XXXXXXXX, 'hit', '/contacts', {params: goalParams})
```

<!-- 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/buttons/support-button.md -->
<div class="cut-button">

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

<!-- source: zh/_includes/popup/id-popup/wrong-sup.md -->
请注意：我们的支持团队永远不会主动给您打电话。 请勿按照自称为 Yandex Metrica 支持团队来电者的指示操作。
<!-- endsource: zh/_includes/popup/id-popup/wrong-sup.md -->

<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/?&iframe=1&lang=en">
  </iframe>
</div>

{% endcut %}

</div>

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

<!-- endsource: zh/_includes/styles/cut-button.md -->
<!-- endsource: zh/_includes/buttons/support-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 -->

[*Параметр]: <sup >*</sup>必填参数。