Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
A basic example of using the Google Analytics Core Reporting v4 API
Go
Branch: master
Clone or download
Cannot retrieve the latest commit at this time.
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
google_analytics
.gitignore
LICENSE
README.md
main.go

README.md

google-analytics-v4-example

License

Overview

This is an example of a simple console application that pulls pageview data from Google Analytics.

Pre-requisites

Enabling Google Analytics Reporting API

To query Google Analytics data, you'll need to enable the Google Analytics Reporting API in your Google Cloud Platform project.

Creating a service account

  1. Create a service account in Google Cloud Platform console for your project.
  2. Assign the service account no permissions/roles.
  3. Click "Create Key" to create a private key and save it in JSON format.
  4. In Google Analytics, open Admin > View > View User Management and add the email address of the service account you just created (it will have an email like [name]@[project ID].iam.gserviceaccount.com.
  5. Grant the user only "Read & Analyze" permissions.

Finding your Google Analytics View ID

  1. In Google Analytics, open Admin > View > View Settings
  2. Save the View ID displayed

Usage

go run main.go -viewID 123456789 -keyFile google-analytics-viewer-key.json
You can’t perform that action at this time.