LoginSignup
7
6

More than 3 years have passed since last update.

AMP で Google Analytics を利用する

Last updated at Posted at 2016-05-17

やり方

次のスクリプト分を <head> 内かつ AMP JS library1 よりも前に以下の内容を記述

<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>

Body 先頭に以下の内容を記述

<amp-analytics type="googleanalytics" id="analytics1">
    <script type="application/json">
        {
            "vars": {
                // 通常ページのトラッキング用と、 AMP 用ではプロパティを分けて設定することが推奨
                "account": "UA-XXXXXX-Y"
            },
            "triggers": {
                "trackPageview" : {
                    "on": "visible",
                    "request": "pageview"
                }
            }
        }
    </script>
</amp-analytics>

ちなみに amp-analyticsid は必須ではないがデバッグのために追加しておくことが推奨


  1. AMP JS library は <script async src="https://cdn.ampproject.org/v0.js"></script> です 

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6