Clone the repo and install dependencies. Glide is preferred.
$ mkdir -p $GOPATH/src/github.com/sudo-suhas && cd $_
$ git clone https://github.com/sudo-suhas/example-analyticsreporting.git
$ cd example-analyticsreporting
# preferred method
$ glide install
# or use `go get`
$ go get .
Build the executable binary.
# This should generate an executable binary in the current folder
# Example example-analyticsreporting.exe on windows
$ go build .
You need to pass the location of the client_secrets.json file
and the Google analytics view ID from the command line.
You can use the Account Explorer to find a View ID.
Additionally, you can pass the flag --debug for verbose logging.
Usage:
$ ./example-analyticsreporting.exe --help
usage: hello_analytics.exe --keyfile=KEYFILE --view-id=VIEW-ID [<flags>]
Flags:
--help Show context-sensitive help (also try --help-long and
--help-man).
-d, --debug Enable debug mode.
-k, --keyfile=KEYFILE Path to JSON key file.
-v, --view-id=VIEW-ID Google Analytics View ID.
$ ./example-analyticsreporting.exe --keyfile=E:\creds\client_secrets.json -view-id=299792458 --debug
File Structure
hello_analytics.go - This is the main file. It does the following:
Create a Google Analytics Reporting API v4 service client