Steps and code for pulling Google Analytics into Google Sheets
- Setup
- Create a new Google spreadsheet
- Enable Scripts
- Activate APIs
- Code
- Troubleshooting
I could not have figured out much of this without the help of tanaikech's article Linking Cloud Platform Project to Google Apps Script Project.
Google has put out a very helpful Query Explorer. If you're having trouble formating your queries, playing with the query explorer can be helpful.