Analytics in AMP pages?

Does the Casper theme and default way AMP pages are created include support for Analytics?

Specifically, if I use the code injection at the site level in Ghost Admin, will that tracking carry over into the AMP pages or do I have to create a custom hbs file in order to track AMP data?

Analytics in AMP pages do not work with the same script that you usually use for Analytics. Accelerated Mobile Pages require a different Analytics tag.

Here are a few links that might help you understand how to set Analytics for AMP pages:

Tracking Accelerated Mobile Pages (AMP)
Adding Analytics to your AMP pages
AMP Analytics by example
Analytics and AMP - How to Track ALL THE THINGS (AMP Conf 2018)

The best way to do this is to save the amp.hbs file:

AMP default template

Put it into your theme folder. Do the required changes and it should work.

After you do your changes be sure that everything is validated. To do this add #development=1 to the URL of the page. You will see your errors, if you have, in Console tab. Debugging.

1 Like