Thank you Robert!
Go to PageSpeed Insights, click Docs and then API Reference. There is a Try this API pane where you can make a call to the API and browse the JSON. This is really helpful for figuring out the response structure.
I´m trying to add more features to this script. I tried adding
but it returns
TypeError: Cannot read property "items" from undefined. (line 9, file "Code")Dismiss
could you help me?
Hi Mike, I think that version 1 of the API was deprecated. It was still working for me but probably because I've had the API key for long enough. I've just updated the script to use v5. The two changes are the v5 in the PageSpeed API URL and the score has moved to lighthouseResult.categories.performance.score and is from 0-1 rather than 0-100. I multiply by 100 above to make it consistent with the old score. Let me know if you're still having any problems after making these changes.
This is just what I've been looking for. A way to automate the collection/export of the Google Analytics PageSpeed report.
I'm fairly new to programming - okay, very new - and I'm running into a problem. Hoping you might be able to assist me.
I've created a Google API key from the console as you instructed. I then launched the Script Editor from within my Google Sheet and I pasted your above script into the editor, replacing everything that shows up in the Script Editor by default.
After adding my API key and my URL to monitor, I ran the script and I receive the following error:
"Request failed for https ://www.googleapis.com/pagespeedonline/v1/runPagespeed?"
I looked up that error message and I found the page (
Pagespeedapi: runpagespeed) - which references v4 instead of v1, but I still get the error if I use v4.
If you have any suggestions on how to resolve this, I would be incredibly grateful.