# Ptengine在SPA网站中的测量配置指南

## Ptengine在SPA网站中的测量配置指南

## **什么是SPA页面？**

SPA是单页应用程序（Single Page Application）的缩写。

为了优化内容传递速度并提高整个网站的性能，越来越多的网站开始采用SPA。

## **为什么SPA页面的测量需要特殊处理**

由于SPA使用与传统网站不同的方式加载内容，常规的测量方法无法自动检测到SPA页面内容和URL变化，这影响了对用户行为的正确分析。Ptengine使用标准基础标签时也无法正确测量SPA页面，需要特殊处理。

解决方法是配置Ptengine SPA专用标签，当页面内容更改时触发该标签，将更新后的页面URL等信息发送给Ptengine，从而正确进行测量。具体的配置方法如下所示。

## **实现逻辑说明**

Ptengine基础标签在SPA页面加载后，在页面变化的瞬间通过"router change"函数调用Ptengine的SPA专用标签。

Google Tag Manager（以下简称GTM）可以轻松识别历史记录的变化，因此建议将其设置为触发器。当然，也可以手动配置，但需要技术团队的协助。

**警告：**

如果页面内容改变但URL不变，可以使用以下标签生成演示URL，然后用新URL测量数据。请注意，无法使用GTM，需要进行[手动配置](/cn/faq/tag-and-domain/spa-tracking.md)。有关"URL/#位置信息"的详细信息，请参考此文档中的[setPVTag](/cn/faq/tag-and-domain/spa-tracking.md)部分。

```
window._pt_sp_2 && window._pt_sp_2.push('setPVTag,URL/＃所情報,replace');
```

## **GTM配置方法**

1. 在设置了基础标签的GTM容器中创建新标签。
2. 设置标签名称后，选择"自定义HTML"，输入以下标签，将触发器设置为"历史记录变化"并保存。

```
window._pt_sp_2 && window._pt_sp_2.push('setPVTag,'+ location.href +',replace');
```

3. 确认没有问题后，点击"发布"按钮进行发布。

####

## **手动配置方法**

也可以手动触发setPVTag，如果要手动配置，请在页面更改的瞬间通过"router change"函数调用Ptengine的SPA专用标签，将以下标签添加到页面逻辑中。

```
window._pt_sp_2 && window._pt_sp_2.push('setPVTag,'+ location.href +',replace');
```

如果页面内容改变但URL不变，请使用以下标签。有关"URL/#位置信息"的详细信息，请参考[此处](/cn/faq/tag-and-domain/spa-tracking.md)文档中的"setPVTag"部分。

```
window._pt_sp_2 && window._pt_sp_2.push('setPVTag,URL/＃所情報,replace');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://helps.ptengine.com/cn/faq/tag-and-domain/spa-tracking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
