It's important to be able to measure things that are likely to impact your end users and your position in search engine results.
Anyone who has at least a passing interest in SEO has at one point or another tried to minimise un-neccesary links on a page, minimise the number of scripts used, and ensure there aren't pages with an overload of images.
It's a surefire way to ensure your pages are loading quickly, which gives a good user experience, and a good way to check that every page of your site isn't linking across to every other page (I'm looking at you megamenus).
But if you haven't done this before, how do you know which pages are your worst offenders that you can prioritise first? if you have a small site it's easy, but if you have a giant ecommerce site or large content site, how do you know there isn't some old page with 1,000 links buried somewhere?
...is not going to answer this question.
For a start it's only going to tell you how many links there are, but even then, it shows you the most linked pages not the pages with the most links on them. Which is an important distinction.
Measuring this automatically
Add the variable in Google Tag Manager
What we're going to do, is set up tag manager to automatically query the browser and ask it how many images, scripts and links it finds, so we can send this information off to Google Analytics.
- Go into the "Variables" section of tag manager
- Create a new "user defined variable"
- Specify a global variable name
- Number of images is - document.images.length
- Number of links is - document.links.length
- Number of scripts is - document.scripts.length
- Name it something logical
- Save the variable
Now what will happen is upon tag manager loading on the page, it will look through the document body (the page code) and return the number of items that are of the type images/links/scripts.
Configure the custom metrics in Google Analytics
By default Google Analytics has a set of metrics like pageviews, time on site etc, but there is no in-built metric for this information, so we need to create it.
- Log into your Google Analytics account
- Go into the "Admin" section
- On the relevant property, click into "Custom Definitions"
- Click into "Custom Metrics"
- Click "+ New Custom Metric"
- Specify a name for your custom metric - this is what is shown in reports, I normally just re-use the global variable name from above.
- Scope is "Hit" (it's sent with each pageview)
- Formatting type is "Integer"
- Minimum & Maximum value can be left blank - this is where you can set a minimum or maximum values for it to show up in reports
- Ensure "Active" is ticked on
- Click Create
- Repeat these steps above for each metric
Configure Google Tag manager to send the data into Google Analytics
Now that we have configured the custom metrics in Google Analytics, and we've set up Google Tag Manager to read the information out of the browser, we need to configure it so that they talk to each other.
- Go into Google Tag Manager
- Go into your "Tags"
- Go into the Google Analytics tag that tracks your pageviews
- Go into the "Configure Tag" section
- Click to expand "Custom Metrics"
- Add custom metrics for each of these values
- For the "Index" value, you will be able to see this in Google Analytics by going into the custom metrics section in Admin, then looking at the index column
- Click "Continue"
- Click to "Save Tag"
Now that we've configured everything, we should make sure it's all working as expected.
- In Google Tag Manager click to "Preview and debug"
- Load the page where Google Tag Manager is running
Ensure the variables are being populated
- In the preview window that shows up at the bottom click into the step on the left where your pageview is being fired (probably "2 Pageview")
- Click into the "Variables" section (at the top)
- Scroll down to find the variables you specified in tag manager
- Ensure there is a value shown
Ensure the variables are being sent to Google analytics
- Click into the "Tags" section (at the top)
- Click the pageview tag that's being fired
- In the Properties section, click the "Show More" link
- Look for the "Metric" row, and make sure you see 3 different values being sent off to Google Analytics with the pageview
Seeing this information in Google Analytics reports
Because this is a custom metric, it doesn't show up in any of the standard reports, you'll have to add it to a custom report, or copy an existing report and add this data.
- Go into Google Analytics
- Navigate to a report you want this information on, and click the "Customize" link below the report name or go into "Customization" and click to create a "+ New Custom Report"
- In the "Metric Groups" section, click to "+ add metric"
- Click into "Custom Metrics", and select the metric you'd like.
- Save your report
Now because the metrics are all just totals, you'll have to export this to work out the average value of these metrics, since we want to know how many images/scripts/links there were on each page on average, rather than the total.
Take your custom metrics, and divide them by the Pageviews metric to get an accurate figure.
So now you've been recording this for a while, you can get some really interesting answers and insights.
- Look at average page load time vs number of scripts/images on the page
- Is there a threshold where you see once the number gets high enough there is a slowdown of the page?
- Is there a trend over time of more links/images/scripts?
- Why is this? can you ensure this is providing value to your users?
- Find your pages that have the most links
- Can you minimise how many links there are?
- Find your pages that have the most images
- Are all those images needed?
- Look for pages that have an unusually high number of scripts
- See if there are un-neccesary scripts you can remove
- Are there old pages that don't have the right scripts?
- Look for pages that have an unusually low number of scripts
- Ensure they are working, is something not being included correctly