Giter VIP home page Giter VIP logo

go-ga-reporting's Introduction

##Google analytics Data pull

Lightweight Golang library for pulling Google Analytics API data. Built for use with Core Reporting API (v3):

https://developers.google.com/analytics/devguides/reporting/core/v3/reference

Is being used for BAU report generation and collation. Pull requests welcome!

Codeship Status for vly/go-gadata

Authentication

In order to authenticate this library for use with your Google Analytics account, an oauth2 token needs to be generated. For a new project login to Google Developers Console and Create Project. Add Analytics API to list of APIs, create a new Client ID and download it in JSON format. Place the client_secret.json in the root of your application.

Usage

Example single request flow:

go
import (
    "fmt"
    "github.com/vly/go-gadata"
)

func main() {
	// initialise GAData
    gaTest := new(GAData)
	
		// initialise instance incl. authentication
    gaTest.Init()
    
    // build a basic GA query, replace your ga ID
    testRequest := GaRequest{"ga:43047246", // GA id
		                         "2014-01-01",  // start date
		                         "2014-01-02",  // end date 
		                         "ga:visits",   // metrics 
		                         "ga:day",      // dimensions
		                         "",            // filters
		                         "",            // segments
		                         "",            // sort
		                         100}           // results no.
    
    // launch data
		result := gaTemp.GetData(1, &testRequest)
		fmt.Printf("results: %s\n", result)
	}
}

Example multiple requests flow. Returns a sorted slice (array) of results...

go
import (
    "fmt"
    "github.com/vly/go-gadata"
)

func main() {
	// initialise GAData
    gaTest := new(gadata.GAData)
	
		// initialise instance incl. authentication
    gaTest.Init()
    
    // build a basic GA query, replace your ga ID
    for i := 0; i < 5; i++ {
		testRequests = append(testRequests, &GaRequest{"ga:43047246",
			"2014-01-0" + strconv.Itoa(i+1),
			"2014-01-0" + strconv.Itoa(i+2),
			"ga:visits",
			"ga:day",
			"",
			"",
			"",
			100})
	}
	if results, err := gaTemp.BatchGet(testRequests); err == nil {
		for a, b := range results {
			log.Printf("results: %d: %s", a, b)
		}
	}
}

Testing

Unit tests are included with this library, use go test ./... to run through the set provided.

Changelog

0.1.1:

  • Implemented batch processing
  • New request period segmentation functionality
  • Cleaner error reporting and resolution suggestions

0.1.0:

  • Initial release

go-ga-reporting's People

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.