Import Google PageSpeed Insights Data to Google Sheets
In this guide, we’ll walk through how to pull Google PageSpeed Insights data data directly into Google Sheets, using the API Connector add-on for Sheets.
PageSpeed Insights is Google’s tool to measure and analyze the performance of a webpage. You may have seen data from this API when running a Lighthouse audit of your site, which retrieves PageSpeed Insights data and presents it in your browser console like this:
With this API, you can see this data in Sheets instead of (or in addition to) viewing the Lighthouse report in your browser.
- Before You Begin
- Part 1: Connect to the Google PageSpeed Insights API
- Part 2: Create a Google PageSpeed Insights API Request
- Part 3: Pull Google PageSpeed Insights API Data into Sheets
- Part 4: Other PageSpeed Insights Data
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Connect to the Google PageSpeed Insights API
- Open up Google Sheets and click Add-ons > API Connector > Manage Connections.
- In the list of available connections, find “Google PageSpeed” and click Connect.
- You will be directed to google.com and asked to sign in.
- You’ll then be returned to your Google Sheet, and can verify that your Google PageSpeed Insights connection is active in the Connections screen.
Part 2: Create a Google PageSpeed Insights API Request
We’ll first follow Google’s PageSpeed Insights API documentation to pull in a summary of all the audit scores reported by Lighthouse.
- API root: https://www.googleapis.com
- Endpoint: /pagespeedonline/v5/runPagespeed
- Query strings: ?url=https://mixedanalytics.com&fields=lighthouseResult/categories/*/score&strategy=mobile&category=performance&category=pwa&category=best-practices&category=accessibility&category=seo
Note the different query strings you can modify: in ‘url’ you can substitute in your own URL, under ‘strategy’ you can choose mobile or desktop, and under ‘fields’ you can choose the fields you want to return.
Putting it together, we get the full API Request URL:
Part 3: Pull Google PageSpeed Insights API Data into Sheets
We can now start pulling in data.
- In API Connector, click Create, choose GET from the dropdown menu, and paste in the Request URL we created above.
- Choose ‘Google PageSpeed’ from the authentication dropdown.
- Under headers, enter Key = Accept, Value = application/json.
- Create a new tab and click ‘Set current’ to use that tab as your data destination.
- Name your request and click Run. A moment later you’ll see your summary scores populate your sheet. Note that they may not exactly match what you see in your Lighthouse audit, because the scores vary between runs.
Part 4: More Example PageSpeed API Requests
Loading time details
Google’s PageSpeed Insights documentation also contains a handy expression builder that you can use to create and test queries. You can then take the resulting cURL snippet and copy/paste it into API Connector (Add-ons > API Connector > Import / Export > Import cURL). Just make sure to remove the Authorization header as we handle authorization through the OAuth2 connection manager.