Adding Google Analytics to AMP posts in Ghost

I noticed that out of the box, Ghost comes with AMP support (as has done since 2016), however there is no built in way to in the administration UI to add Google Analytics to your AMP theme. This means you will be missing out on a portion of your mobile traffic in your analytics. Not great.

Verify your AMP posts are valid

Option #1 - Use your browser's console

Visit any AMP post and add on to the end to the end of the URL #development=1 this will trigger the AMP validator to run. If you open the console of your browser, you should see something like this:

Chrome's console after visiting an AMP page with #development=1

If you see AMP validation successful. then you know at least the theme is still valid.

Option #2 - Use a Chrome extension

Another option (if the console is not your friend) is to use the dedicated plugin for AMP validation. There is one for chrome that I am aware of.

What the browser extension looks like when the AMP is valid.

Option #3 - Use a website

Likely the simplest option if you content has a valid public URL, visit https://search.google.com/test/amp and plug in your URL to your AMP post, and then see the results:

What the web based validator will look like after testing a valid AMP page.

Verify Google Analytics is working

Next steps is verifying that the tracking is enabled, you can prove this in the Network tab of your browser's console and filtering by google-analytics, you should see a request to a URL that starts off like collect?v=1&_v=a1&ds=AMP&aip&_s=1...

How to ensure that Google Analytics is sending the tracking request using the browser's console.

You can also just go checkout the realtime view inside Google Analytics itself:

If you see any realtime pages that include /amp/ on the end, then your analytics is working.