AMP
  • websites

amp-pixel

Introduction

amp-pixel is a lightweight mechanism for measuring pageviews. It provides functionality similar to amp-analytics, but only includes a single event (views), and offers fewer transport mechanisms and variables.

Setup

amp-pixel is a built-in component and does not require loading an extension.

Basic usage

The amp-pixel issues a simple GET request to the given URL and ignores the result. This is a fast way to track pageviews.

<amp-pixel src="https://ampbyexample.com/tracker/foo"
  layout="nodisplay"></amp-pixel>

Variable substitution

The variables noted in amp-var-substitutions will be interpolated in the URL as a way to capture some meaningful data.

<amp-pixel src="https://ampbyexample.com/tracker/foo?redirectTime=REDIRECT_TIME&sourceHost=SOURCE_HOSTNAME&viewer=VIEWER"
  layout="nodisplay"></amp-pixel>

Referrer Policy

The optional referrerpolicy attribute allows you to strip the 'Referrer' header in the outbound HTTP request. Other values of referrerpolicy that are valid for other tags (e.g. amp-img) are not available for amp-pixel.

<amp-pixel src="https://ampbyexample.com/tracker/foo"
  layout="nodisplay"
  referrerpolicy="no-referrer"></amp-pixel>
需要进一步说明?

如果此页面的说明未能涵盖您的所有问题,欢迎与其他 AMP 用户取得联系,讨论您的具体用例。

前往 Stack Overflow
一项无法解释的功能?

AMP 项目强烈鼓励您参与其中并作出贡献!我们希望您能成为我们开源社区的持续参与者,但我们也欢迎您对热衷问题做出单次贡献。

在 GitHub 上编辑实例