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
- Appendix: Connect with an API Key
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 enter our values into API Connector and start importing Google PageSpeed Insights data into Google Sheets.
- In API Connector, click Create, choose GET from the dropdown menu, and paste in the Request URL we created above.
- Under headers, enter Key = Accept, Value = application/json.
- Choose ‘Google PageSpeed’ from the authentication dropdown.
- 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.