Wednesday 6 April 2016

How to add google analytics with AMP pages.?

Introduction:

I am going to explain how to use google analytics for AMP pages. What is AMP page.? Check my previous article.


Step1:
       Create AMP website and include all the necessary AMP files including

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


Step2:
          Then finally add this script into your AMP page

  1. <amp-analytics type="googleanalytics" id="analytics1">
  2. <script type="application/json">
  3. {
  4.   "vars": {
  5.     "account": "Your account Id"  //UA-69036925-1
  6.   },
  7.   "triggers": {
  8.     "trackPageview": {
  9.       "on": "visible",
  10.       "request": "pageview"
  11.     }
  12.   }

  13. }
  14. </script>
  15. </amp-analytics> 


No comments:

Post a Comment