SYNCER

SYNCER

<amp-pixel> - GETリクエストを送信する

1件

公開日:

AMPのamp-pixelは、GETメソッドのリクエストを送るための要素です。トラッキングなどに利用できます。

概要

名前
amp-pixel
可用性
Stable (安定)
サポートするレイアウト
fixed,nodisplay
必要なスクリプト
なし。
検証
https://github.com/ampproject/amphtml/blob/master/validator/validator-main.protoascii
ドキュメント
https://www.ampproject.org/docs/reference/amp-pixel.html

属性

src

GETメソッドのリクエストを送るURL。URLはhttpから始めなければいけない。

共通属性

AMPの全てのタグで利用できる共通属性を指定できます。

説明

GETメソッドのリクエスト

amp-pixel要素は、srcに指定したURLにGETメソッドを送信します。

HTML

<amp-pixel
	src="https://demo.syncer.jp/523/index.php?q=hoge">
</amp-pixel>

これはとても単純なことで、src属性に指定したURLを手動で開くのと同じことです。アクセスしてみて下さい。

リクエストのURL

https://demo.syncer.jp/523/index.php?q=hoge[LINK]

置換変数

src属性のURLに一部のキーワードを指定すると、それが置換されます。例えば、TITLEというキーワードを含めた場合、その部分がページのタイトルに置き換えられます。

HTML

<head>
	<title>SYNCER</title>
</head>
<body>
	<amp-pixel
		src="https://demo.syncer.jp/523/index.php?q=TITLE">
	</amp-pixel>
</body>

実際に送信されるURL

https://demo.syncer.jp/523/index.php?q=SYNCER[LINK]

他にどのような変数があるかは、置換変数の項目をご参考下さい。ページ、ブラウザなど、ユーザーの様々な情報をamp-pixel要素を利用して記録することができます。

サイズの指定

amp-pixelは、width属性、height属性、layout属性を指定しなくても、デフォルトで横幅、高さともに0に設定されます。

サンプルコード

HTML

<!doctype html>
<html amp>
	<head>
		<meta charset="utf-8">
		<title>【デモ】<amp-pixel> - GETリクエストを送信する</title>
		<link rel="canonical" href="https://syncer.jp/Web/AMP/Component/amp-pixel/">
		<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
		<style amp-custom>
			body {
				padding: 12px ;
				background-color: #fff ;
			}
		</style>
		<script type="application/ld+json">
			{
				"@context": "http://schema.org",
				"@type": "NewsArticle",
				"headline": "記事のタイトル",
				"image": [
					"eyecatch.jpg"
				],
				"datePublished": "2017-08-23T00:00:00+0900"
			}
		</script>
		<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
		<script async src="https://cdn.ampproject.org/v0.js"></script>
	</head>
	<body>

<p><code>//demo.syncer.jp/523/index.php?q=TITLE</code>にGETリクエストを送信しました。</p>
<p>上記URLが受けたリクエストの内容を<a href="//demo.syncer.jp/523/test.txt" target="_blank">テキストファイル</a>に記録しています。ページのタイトルを変えて確認してみて下さい。</p>

<amp-pixel
	src="//demo.syncer.jp/523/index.php?q=TITLE">
</amp-pixel>

	</body>
</html>

デモを開く

デモ

</head><body>までを含めて下さい。

</body> </html>

<style amp-custom>

</style>