Multiple Google Tracking Codes on AMP pages

2019-06-03 23:36发布

Is there a way to add different Google Analytics tracking accounts? I've been looking around but I only find examples and sites are using 1 single account:

<script type="application/json">
    {
        "requests": {
        "pageview": "https://example.com/analytics?url=${canonicalUrl}&title=${title}&acct=${account}",
        "event": "https://example.com/analytics?eid=${eventId}&elab=${eventLabel}&acct=${account}"
    },
    "vars": {
        "account": "ABC123"
    },
    "triggers": {
        "trackPageview": {
            "on": "visible",
            "request": "pageview"
        },...

3条回答
混吃等死
2楼-- · 2019-06-04 00:07

You can copy paste the amp-analytics tag twice. Or you can use use two triggers. Here are some examples:

Two separate tags:

<amp-analytics>
<script type="application/json">
    {
    "vars": {
        "account": "ABC123"
    },
    "triggers": {
        "trackPageview": {
            "on": "visible",
            "request": "pageview"
        },...


<amp-analytics>
<script type="application/json">
    {
    "vars": {
        "account": "PQR987"
    },
    "triggers": {
        "trackPageview": {
            "on": "visible",
            "request": "pageview"
        },...

Two triggers:

<amp-analytics>
<script type="application/json">
    {
    "triggers": {
        "trackPageview": {
            "on": "visible",
            "request": "pageview"
            "vars": {
              "account": "ABC123"
            },
        },
        "trackPageview2": {
            "on": "visible",
            "request": "pageview"
            "vars": {
              "account": "PQR987"
            },
        },...
查看更多
疯言疯语
3楼-- · 2019-06-04 00:09

In the AMPforWP (Wordpress), Google Analytics, Advanced Google Analytics plugin, the "JSON" format is requested. By inserting in this format only triggers work, triggers2 will not.

查看更多
Animai°情兽
4楼-- · 2019-06-04 00:18

We're just missing a comma after "request": "pageview"

  <amp-analytics type="googleanalytics" id="analytics-ga">
  <script type="application/json">
  {
  "triggers": {
    "trackPageviewAmp": {
      "on": "visible",
      "request": "pageview",
      "vars": {
        "account": "UA-000000-2"
      }
    }
  },
  "triggers": {
    "trackPageviewMain": {
      "on": "visible",
      "request": "pageview",
      "vars": {
        "account": "UA-000000-1"
      }
    }
  }
}
</script>
</amp-analytics>
查看更多
登录 后发表回答