ga

package module
v0.0.0-...-877814a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2015 License: MIT Imports: 11 Imported by: 0

README

##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

Install

go get github.com/chonthu/go-google-analytics

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 "Installed" App Client ID and download it in JSON format.

Place the client_secret.json in the root of your application. Ps. you have to renaming it from the crazy name to just "client_secret.json"

Usage

See Examples here

Testing

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

** This doesnt really work yet, but working on it **

Changelog

1.0.0

  • cleaner naming
  • clearner working examples

0.1.1:

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

0.1.0:

  • Initial release

Documentation

Index

Constants

View Source
const (
	StdEndpoint string = "https://www.googleapis.com/analytics/v3/data/ga" // standard endpoint
	Limit       int    = 5                                                 // max requests / sec guard
)

Base constants

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanResponse

type CleanResponse struct {
	Columns []struct {
		Name  string `json:"name"`
		CType string `json:"columnType"`
		DType string `json:"dataType"`
	} `json:"columnHeaders"`
	Total map[string]string `json:"totalsForAllResults"`
	Rows  [][]string        `json:"rows"`
}

Processed GA response

type Client

type Client struct {
	Auth     *utils.OauthData
	Request  *Request
	Response *Response
}

Client is the primary Google Analytics API pull structure

func (*Client) BatchGet

func (g *Client) BatchGet(requests []*Request) (responses []*CleanResponse, err error)

BatchGet runs all queries in parellel and returns the results (or times out)

func (*Client) Get

func (g *Client) Get(key int, request *Request) *Response

Get queries GA API endpoint, returns response

func (*Client) Init

func (g *Client) Init()

Initialise the Client connection, ready to make a new request

type Request

type Request struct {
	Id         string `json:"ids"`
	StartDate  string `json:"start-date"`
	EndDate    string `json:"end-date"`
	Metrics    string `json:"metrics"`
	Dimensions string `json:"dimensions"`
	Filters    string `json:"filters"`
	Segments   string `json:"segment"`
	Sort       string `json:"sort"`
	MaxResults int    `json:"max-results"`
	Attempts   int
}

Request is the Google Analytics request structure

func (*Request) ToURLValues

func (a *Request) ToURLValues() (out url.Values)

ToURLValues converts struct to url.Values struct

type Response

type Response struct {
	Data []byte
	Pos  int
}

Initial returned response

func (Response) Process

func (rawResponse Response) Process() (data CleanResponse, ok bool)

type ResponseData

type ResponseData struct {
	Id      string
	Query   Request
	Kind    string `json:kind`
	Columns []struct {
		Name  string `json:"name"`
		CType string `json:"columnType"`
		DType string `json:"dataType"`
	} `json:"columnHeaders"`
	Total map[string]string `json:"totalsForAllResults"`
	Rows  [][]string        `json:"rows"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL