AMP Validation Umbraco Healthcheck

Written by on

A while ago I wrote about <a href="">AMP implementation in Umbraco </a>, check it out if you are looking for information how I implemented the AMP alternative layouts for pages within an Umbraco instance.

When I was working on this, I realised that some of my pages wouldn't pass validation if I needed to use inline styles or anything else that doesn't conform to the list of elements allowed on an AMP page. Therefore, not all pages would be suitable to have an AMP version of. In my implementation, my code will add the AMP link to the head tag if my node has the 'hasAMP' checkbox set to true.

I didn't want the meta data on the page telling Google there was a AMP page for this when it doesn't pass validation (we need to keep Google happy, you know!), so I decided to have a custom health check dashboard in my Umbraco backoffice. I mainly built this as a reason to have a go at building a healthcheck as I hadn't done it yet, but I showed it to a SEO colleague and they thought it would be useful! Therefore, I am going to include this in my projects with AMP pages so the SEO team/ content admin can check the pages they are advertising to Google as AMP valid, actually are.

This is the first custom health check I have done and it works so I *think* I have done it right... let me know if you have any feedback :) Basically, my code goes through each site node and checks if it has the 'hasAMP' property. If this is true, it runs the page against the AMP validator.

If it fails, we can tell the user and they can either fix the validation issue or un-check the 'hasAMP' box so we aren't telling Google we have an Accelerated Mobile Page when we don't.

I'm not sure if this will be useful for anyone else, but as I have already copied it into another project, I thought maybe it could be reusable and helpful for anyone implementing AMP in Umbraco.

To get this health check working in your Umbraco instance, all you need to do is drop the AmpHealthcheck.cs file in the App_Code folder. If you need to change the name of the field to check (rather than hasAMP) then you can. Similarly, if you don't append ?amp=1 to end of URL like I do, you can easily update this to match your implementation too.

Check it out on <a href="">GitHub</a>, give feedback, say hello on <a href="">Twitter</a>!