Automatically Track PageSpeed Insights Over Time

Last Updated: June 18, 2024

I have written two detailed guides to improve your website’s page speed (How to Score 100 on Google PSI: A Complete Guide to Optimizing Your WordPress Site Performance and Speed and How to Score 100 on Google PSI: More Lessons Learned). Those discuss multiple online testing tools that are useful, but the core focus was on Google’s PagesPeed Insights tool.

After working to improve your page speed you’ll want to monitor it to make sure things are still performing well. Life being what it is, remembering to regularly run a manual check is not convenient or likely. Ideally, there should be a way to automate the process. Recently, I began to investigate the options and found three options worth considering.

Google API Key

For the potential solutions discussed below you will need an API key. This is something Google provides for free but you will need a Gmail or Google account. The layout and process involved in enabling APIs and obtaining an API Key often changes, but the general process is:

  1. Login to Google API Console.
  2. Create a new project. Name the project anything you’d like, such as: PageSpeed Insights. Agree to the terms and service if asked. It may take 10-20 seconds for the new project to be created, be patient. If you have already created a project previously that you want to use, select that project.
  3. Enable the PageSpeed Insights API. After your project has been created, you can enable the google services you want to use from the API Library. Find / Search for “PageSpeed Insights API”, and click it. Enable the PageSpeed Insights API.
  4. Create credentials for using the PageSpeed API from the credentials page. The type of credentials that we want to make is “API Key.” Google will generate an API Key for you to use. Copy it to your clipboard to use it later. You can come back to the credentials page if you misplace it. (Note: You will be given the option to restrict usage of your API key. Be careful that you do not accidentally add a restriction that will block your site form using this key.)

WordPress Google PageSpeed Insights Plugin

The Google Pagespeed Insights WordPress plugin is a pretty impressive tool. It will query PageSpeed Insights for all the pages of your site (beware if you have many). You can sort your page reports by their score to prioritize the largest areas of opportunity on your site. Click on any page to see a detailed report of the results, with recommendations based upon current industry best practices.

psi pagespeed plugin 1024x576 - Automatically Track PageSpeed Insights Over Time

In the options section you can configure the plugin to run reports for desktop, mobile or both. Since the results vary a lot between the two I recommend using both.

One nice feature is the ability to schedule the plugin to run. Unfortunately, I am unable to actually access the scheduling section of the options page (or the advanced options section). I have posted in the support section asking about this so hopefully the plugin author will address it. It may just be an issue specific to my setup, but until resolved it won’t allow for ongoing tracking.

Another concern I have with the plugin is that it seems to automatically check every page on the site. Once you have those results you can click on any page result and choose Ignore to prevent it from running. But, it would be nice to specify which pages you want to run in the main options page. That may actually be an advanced setting, but I have no idea since I cannot access that section.

Google Sheet Monitor for PageSpeed Insights

The more I use Google Sheets the more impressed I become. I have created several public projects, including:

Recently, I came across projects by Robert Ellison and Rick Viscomi that can track PageSpeed Insights. These spreadsheets use the script editor and pivot tables. I haven’t previously used either, so it was a good chance to learn some new things.

Neither of those spreadsheets quite do what I want so I decided to create my own. My spreadsheet uses the best of both and adds new pieces as well. One of the new features is the ability to email yourself the results. I have made a public version that you can copy.

PageSpeed Insights Monitor: Lighthouse and Fast FCP from CrUX – Public
(NOTE: please don’t ask for editing permission, just use the “Make a copy” option in the “File” menu)

This spreadsheet will track various PageSpeed Lighthouse and CrUX results. You can track one or more websites (useful if you want to compare your site to competitors). If you schedule it to run daily (recommended) it will create charts to track desktop and mobile performance over time.

Modifying the Spreadsheet

After making a copy of the sheet, you will need to modify it a bit to suit your needs. First, use the “Extensions” menu to select the “Apps Script” option.

Note: The script editor was previously accessed via the “Tools” menu but it seems Google has updated their user interface. I have updated some of the screenshots but not all so if you notice any discrepancies between a screenshot here and what you are seeing, that’s the explanation.
pagespeed monitor edit script menu 1024x576 - Automatically Track PageSpeed Insights Over Time

Next, edit the pageSpeedApiKey and pageSpeedMonitorUrls variables to use your API key and the URLs that you would like to monitor. Note that PageSpeed Insights now lets you test not only a single page of your site but also the aggregated page speed data across all pages of your site. To test that simply use the syntax origin:

pagespeed monitor edit script code 1024x576 - Automatically Track PageSpeed Insights Over Time

Now edit the email address where you want to send the results of each run.

psi email address 1024x576 - Automatically Track PageSpeed Insights Over Time

Running the Script

Finally, save the changes (via the disk icon or Ctrl+s) and run the script (the Run menu option) to verify everything is working properly. The monitor function should be selected by default but if not, select it first.

Note that to run the script, you will first need to authorize it. A window will pop up warning you that authorization is required. Just choose the “Review Permissions” button.

psi authorize script 1024x576 - Automatically Track PageSpeed Insights Over Time

Next you will be asked to choose your account.

psi authorize script choose account - Automatically Track PageSpeed Insights Over Time

Now you will be shown a warning that the script isn’t verified. You will need to override this warning by clicking the “Advanced” link at the bottom.

psi authorize script app not verified - Automatically Track PageSpeed Insights Over Time

Now just click the “Go to PSI CrUX Monitor (unsafe)” link.

psi authorize script app not verified override - Automatically Track PageSpeed Insights Over Time

If the script runs with no errors, view the spreadsheet “Results” sheet. You should see a row entered for each URL you are tracking. Note that one error that might appear while running the script looks like:

This happens if the server hosting a site you are trying to test is configured to block scripts like PageSpeed Insights. If it’s your own URL you will need to investigate with your hosting provider. If it is a competitor URL you may be out of luck. FWIW, I was unable to run the script using either Google or Yahoo when I was trying to test things.

Scheduling Daily Runs

If everything is working well, you will want to set a schedule to have the script run itself automatically. To do so, you need to set a “trigger” to run the monitor function daily, which will append a new row for each URL every day. To set that up, go to the “Triggers” menu on the left sidebar (a ringing alarm clock icon) and then click the “Add Trigger” button.

pagespeed monitor edit script trigger add 1024x576 - Automatically Track PageSpeed Insights Over Time

Add a new trigger with the following configuration:

  • Run the monitor function
  • Choose the Head deployment
  • Choose “Time-driven” event source
  • Choose “Day timer” for the type of time based trigger
  • Select any hour for the script to run, or leave it on the default “Midnight to 1am”
psi trigger time driven 1024x576 - Automatically Track PageSpeed Insights Over Time
psi trigger day timer 1024x576 - Automatically Track PageSpeed Insights Over Time

After saving the trigger, return to this sheet daily to see the performance stats for all monitored URLs or origins.

Pivot Tables

I am pretty new to pivot tables myself so I am in no position to offer detailed advice or help. Still, one thing that may happen is that your pivot table data won’t populate automatically. This is because it was looking for the URLs that you changed. The way to fix this is to change the “Filters” section on the “Pivot Table Editor” right sidebar. On the “URL” box use the “Status” dropdown box to select all your URLs. Once you do this, the data from the “Result” sheet should populate the rows.

psi pivot table filter 1024x576 - Automatically Track PageSpeed Insights Over Time

Once you have some days of data the charts should graph the values for each URL in a nice way. The screenshot below is from Rick Viscomi’s version of the script since my own hasn’t yet run for enough days.

psi chart 1024x576 - Automatically Track PageSpeed Insights Over Time

Finally, make sure you receive an email after successfully running the script. That should provide convenient push notifications of the results and remind you to check the sheet occasionally.

PHP PageSpeed Insights Monitoring Script

I think the Google Sheets solution I just described is the best option and the WordPress plugin has a lot of promise too, but before I knew about either of those I used a PHP script run with a cron job to monitor my sites. That script was lightly modified from one written by Adam Malone and served me well for the past few years.

That script was written for the first version of Google’s API, which is now on the fifth version. Older versions are ending, which is what prompted me to research a replacement and how I found the other options. I didn’t find any similar script already written for the latest version so I decided to write my own.

The current version of PageSpeed Insights barely resembles the one used a few years ago, for better and worse. Previously, Google spelled out where your page was doing well and where it was falling short, providing useful tips for each. Those tips still sort of exist but in a different, more confusing format. It’s also not clear how those tips tie directly to the score you see on the results page.

I still haven’t mastered all the results that the API returns but I decided to use the ones that the PSI page highlights. Note that many of these are not listed in the results of the Google Sheets tracking as they aren’t numeric. They are, however, given in the reports generated by the WordPress plugin.

All of which is a long-winded way of saying I am not sure how helpful this script will be. It may need some small to big modifications in the future. But, for now, if you are interested, here is the code.


I hope one of the three ways to automate your PageSpeed Insights checks will prove useful. I am writing this post before really trying them out so if you notice any problems please leave a comment and I will investigate.

Like this content? Why not share it?
z927iFhzZhhHlG0vLRrW0rNOtvomSRnScsIUGYEOoGWhQHZCAD51BxKmftlAwAAAABJRU5ErkJggg== - Automatically Track PageSpeed Insights Over TimerCAA+N5JPqrDdnnVjMCDtV3aOq+dynp0fAgEsHNpInPMvAAAAAElFTkSuQmCC - Automatically Track PageSpeed Insights Over Timeedfvr+8cdvzQdvCndu33HnFTCc55x7yN4E0py04fz9919vvPkMjHMUzRDE2rRZunenXN8uwY5tTA2bJLpBbNGuHYwNIFnetq1ArmzfLs7mLejxDLcfjCBsCBddlqqFAdkIAEZaZD6ak+MlAAAAAElFTkSuQmCC - Automatically Track PageSpeed Insights Over TimekZwb+rrmiWtf3ej011fDyWUdE3D3PX0McITKAQDxIc8AJ3Xhy1ZmirwAAAAAElFTkSuQmCC - Automatically Track PageSpeed Insights Over TimelBqK4mcnbAAAAAElFTkSuQmCC - Automatically Track PageSpeed Insights Over TimenXuolUE1LSK7Ikslnc4VQTCqRhOYZ0nc2hRw3hK+pxpzKp2hqEjVAACJTFcy8WQrEEoj2QfDH+ftT8vfQcs4fyzcHAAAAAASUVORK5CYII= - Automatically Track PageSpeed Insights Over TimeXn19tOURXs4NFOIzRgsKonqLhVu8d2ucV2abpVcWqmk5WdQkpYHIXDapkVhQDYCAEkHQoyIRHVHAAAAAElFTkSuQmCC - Automatically Track PageSpeed Insights Over Time6wBVv3UpPm2PsQAAAABJRU5ErkJggg== - Automatically Track PageSpeed Insights Over Time
There Are 10 Comments
Click to See or Add Your Own »