How Home Pages Appear in Google Analytics

Google analytics default page

Have you noticed multiple index pages showing up in your Google Analytics reports? While the page path dimension is mostly reported as ‘/’ for your home page, depending on how your website has been developed, you may also see values like ‘/index.html’, ‘/default.php’, or similar pages showing up in your reports.

When it comes to your home page, the forward slash will likely have the most page views. This is because most people visiting your top-level domain will land on something looking like ‘https://www.example.com/’. Since the ‘Page Path’ dimensions present everything after the domain, you will see ‘/’ in your reports.

Sometimes, a visitor finds the physical page (for example, https://www.yoursite.com/default.html). This is likely because there is a link somewhere that takes people directly to the ‘default.html’ page.

When people directly load the physical page, this will also be included in the ‘Page Path’ dimensions. This simplest option is to leave your reports as they are, and to be honest, unless you’re seeing a lot of views for your default page, this is what I would recommend.

The next option is to find the links that direct people to the default page and adjust them. This means you would find all of the links that include ‘/default.html’ (or whatever you’ve found for your physical page) and edit them.

Finally, you could modify how your pages are reported in Google Analytics.

Since Google Analytics 4 (GA4) lets you modify events, this seems like a logical choice for cleaning up URLs in our reports. However, modifying events to replace ‘/default.html’ with ‘/’ will remove any query parameters from the URL, which means we will be missing information from our reports. So we’ll need to use another approach to clean up our reports.

This brings us to Google Tag Manager. Since we can use Google Tag Manager to adjust data before it’s sent to Google Analytics, we’re going to cover this approach for removing the physical page from our URLs.

Let’s get started!

1. Create a Custom JavaScript Variable

We will use a custom JavaScript variable to capture the full URL someone visits on our website. This will look for the default page if it is included in the URL and remove it. It will also preserve any query parameter or fragments in the URL.

Here’s an example of the JavaScript you can use to create the variable. This searches for ‘default.html’ and removes it from the URL. You can modify this code for the physical page you’ve found in your Google Analytics reports.

function() {var fullUrl = window.location.href;var indexHtml = "default.html";var indexPos = fullUrl.toLowerCase().indexOf(indexHtml);if (indexPos !== -1) {fullUrl = fullUrl.substring(0, indexPos) + fullUrl.substring(indexPos + indexHtml.length);}return fullUrl;}

And here’s an example of the custom JavaScript variable in Google Tag Manager:

And here’s an example of the custom JavaScript variable in Google Tag Manager

2. Adjust Your Google Tag

Now that we’ve cleaned up our URLs using the variable, we need to send this clean URL to Google Analytics. To do this, we must modify our Google Tag, which sends data to GA4.

After opening the Google Tag, select ‘Share Event Settings’ and click ‘Add Parameter’. Then, enter ‘page_location’ as the event parameter and select the variable you created as the value.

I named my custom JavaScript variable ‘Clean URLs’, so this is what my tag looks like:

I named my custom JavaScript variable ‘Clean URLs’, so this is what my tag looks

You can then save the tag and preview your changes.

Take time to thoroughly test your implementation. You will need to verify that the custom JavaScript variable is working correctly and that it returns the expected value for your URLs, especially URLs ending in ‘default.html’ (or your physical page).

Once you’re confident everything is working correctly, you can publish your changes.

Conclusion

Managing how home pages appear in Google Analytics can streamline your data analysis and reporting. By addressing the issue of multiple index pages such as ‘/index.html’, ‘/default.php’, and others appearing in your reports, you can achieve cleaner reporting of page views and visitor behavior. And apart from adjusting your implementation, you also have the option of leading the reports as they are with multiple home pages. The approach you take comes down to what you want to see in your reports.

Comments