AMP URL, Combine With Parent URL In Google Analytics
Published: December 15, 2018
Last Updated: October 29, 2022
I recently implemented Accelerated Mobile Pages (AMP) on my site using a WordPress plugin to take advantage of the rich snippets for SEO purposes. This resulted in a small issue with the AMP URL in Google Analytics reports.
I tried 3 different plugins but ultimately settled on WP AMP. One thing these plugins all had in common was that they leveraged a completely separate URL for the AMP pages. For instance my sites home page is https://tortoiseandharesoftware.com/ but the AMP URL might look like
This didn’t bother me too much until I started looking at my Google Analytics reporting and seeing multiple URL flavors. I like to keep a view in my analytics account that has all the filters I want applied so my reporting is showing the highest quality traffic estimates for a given piece of content. So, I decided to combine the AMP URL with it’s parent page using a filter and I will be sharing that information with you.
Setting Up The AMP URL Filter
To start with, open up your analytics account and open up the site you want to apply the filter to and then navigate to your preferred view. If you’re new to views I recommend that you have at least 3 views.
- Raw analytics view (Your out of the box view)
- Filter bots and spiders view
- A view with all your preferred filters.
I am applying this filter to the last of these views. Next you’ll want to click on the admin section in the bottom left of the navigation.
Then you’ll want to click on the filters button on the right side of the navigation menus that fly out on the admin screen.
On the filters screen you’ll want to do several things.
- Change the filter type to “Custom”
- Change the custom filter type to “Search and Replace”
- Make sure the “Request URI” filter field is selected
- Add the regular expression search string. \/amp\/\z|\/amp$
- Add the replace string /
What this will do is look at your URLs and find URLS that end with “/amp” or “/amp/” and replace them with “/”. The end effect is that all AMP URLs will be combined with their parent URL. Let’s say you have hits like this in your analytics currently.
- /page/amp (5 hits)
- /page/amp/ (5 hits)
- /page (5 hits)
In the future your analytics will show all your hits across the 3 distinct URLs rolled up into one. Keep in mind that filters only apply to future traffic so your historical reports from before the filter was applied will still show the duplicate URLs.
- /page (15 hits)
You can see the example in the filter verification screenshot below.
For me this simplifies analysis of traffic data considerably. You can still view traffic segmented by Desktop/Tablet/Mobile so you can still get an understanding of volume of users hitting amp pages because they will simply be the mobile segment.
Hey, how can I do this when my URL is “/?amp”, e.g. “www.mysite.com/page/?amp”?
I recommend checking out https://rubular.com/ for specific regular expressions to build. I haven’t tested this, so take it with a grain of salt, but this regular expression would match /?amp and /?amp/
Always test a filter in a test view before applying to any production view!
Hi, what do you mean with this test view? I can’t find one in Anayltics. Or you mean an only for this created website?
I created a video walking through setting up a test view. Link here: