Giter Club home page Giter Club logo

example-analyticsreporting's Introduction

example-analyticsreporting

Example for Google Analytics Reporting API v4 in golang using the official client.

This example was written using the official examples for java, python

How to run

  • Enable the API - Using steps described in https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-java, create a private key client_secrets.json and download it to your file system. Also add the new service account to the Google Analytics Account with Read & Analyze permission.

  • 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
    • Execute a GET analytics report request
    • Parse and print the response using logrus.
  • debug.go - This is copied from https://github.com/google/google-api-go-client/blob/master/examples/debug.go. It is used to log the HTTP request and response to os.Stdout in debug mode.
  • util.go - This has a simple utility function for tracking function execution time in debug mode.

example-analyticsreporting's People

Contributors

sudo-suhas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.