Adding Google Analytics to Your AMP Page

Follow

Adding Google Analytics to Your AMP Page

  

AMP pages have built in support for Google Analytics which makes it easy set up events and track your user interactions.

  1. Find your Google Analytics tracking ID. Record this number for later use.
  2. Navigate to the Unbounce AMP page where you’d like to add Google Analytics.
  3. Click the Edit in Builder link on the right-hand side of the page to enter the Unbounce builder.
  4. Click on the Javascriptsimage2.pngbutton at the bottom left-hand corner of the page. A new dialog box will appear.
  5. Copy and paste the following script into the blank box. Make sure to change the bolded value starting with UA with the Google Analytics tracking ID that you recorded earlier from your Google Account.
  6. <amp-analytics type="googleanalytics">
     <script type="application/json">
     {
       "vars": {
         "account": "UA-XXXXX-Y"
       },
       "triggers": {
         "trackPageview": {
           "on": "visible",
           "request": "pageview"
         }
       }
     }
     </script>
    </amp-analytics>
  7. Type “AMP Analytics Component” in the blank Script Name Field and select Before Body End Tag from the Placement drop-down menu, then click the Save Code button at the bottom right-hand corner of the dialog box.
  8. image1.png
  9. Save and Publish/Republish your Page.

Google Analytics tracking should now be active on your AMP page.

 

Note:

Google says that you need to include the following script on your pages but we’ve automatically added this for you:

 

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

 

Which means you don’t need to worry about adding it yourself.

Don’t want to use Google Analytics? Here’s a list of other supported Ad networks that you can use if you’d prefer another option.

Are you interested in setting up events tracking? Google has detailed documentation on setting up trigger configuration within your AMP page.

Was this article helpful?
2 out of 2 found this helpful