This repo serves as sample to use GA Reporting APIs v4 to query common basic analytics use cases on reporting website usage. Queried results are outputed as CSV files.
- Retrieves most visited pages for past 30 days
- Retrieves most visited pages, breakdown by source for past 30 days
- Retrieves most popular searched terms within site for past 30 days (WIP)
- Retrieves most frequently referred pages and sources for past 30 days (WIP)
- Enable Analytics Reporting API v4 on your Google API Console
- Create an service account and generate your service accounts keys
- Add service account's email to GA account.
Under
GA's Settings > Account User Management > Property User Management >
- Add service account keys and update
.env
files with keypath - Find your GA property's
ViewId
fromGA's Settings > Account User Management > View Settings
and update.env
's GA_VIEW_ID (ga:<viewId>
)
npm install
- Restore dependenciesnpm run setup
- Setup dir structurenpm run start
- Run reporting script and write results as CSV to./output
dir