realtime

package module
v0.0.0-...-e786d2f Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: MIT Imports: 9 Imported by: 0

README

go-realtime

Simple go client to query Google Analytics API.

https://developers.google.com/apis-explorer/#p/analytics/v3/analytics.data.realtime.get

Example


client := realtime.NewClient(realtime.WithHTTPClient(oauthClient))

opts := &realtime.Options{
    IDs:     "ga:56576851",
    Metrics: "rt:activeUsers",
}

resp, err := client.GetRealTime(opts)
if err != nil {
    log.Fatalf("error in calling resource %v", err)
}

OAuth Client

Requires an OAUTH http client to make the client requests.

key, err := ioutil.ReadFile("./real.pem")
if err != nil {
    log.Fatal("Error reading GA Service Account PEM key -", err)
}

conf := &jwt.Config{
    Email:      "readonly@mm.iam.gserviceaccount.com",
    PrivateKey: key,
    Scopes: []string{
        "https://www.googleapis.com/auth/analytics.readonly",
    },
    TokenURL: google.JWTTokenURL,
}
client := conf.Client(oauth2.NoContext)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client to interact with the realtime API

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a client for the realtime API.

func (*Client) GetRealTime

func (c *Client) GetRealTime(opt *Options) (*Response, error)

GetRealTime returns the realtime analytics api. https://developers.google.com/apis-explorer/#p/analytics/v3/analytics.data.realtime.get

type ClientOption

type ClientOption func(*Client)

ClientOption modifies the default behavior of a realtime client.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient makes the realtime client use the given HTTP client.

type Options

type Options struct {
	IDs     string `url:"ids"`
	Metrics string `url:"metrics"`
}

Options specifies the parameters required to make a valid request.

type Response

type Response struct {
	TotalsForAllResults *ResponseTotals `json:"totalsForAllResults,omitempty"`
}

Response stores the google analytics response.

type ResponseTotals

type ResponseTotals struct {
	RtActiveUsers *string `json:"rt:activeUsers,omitempty"`
}

ResponseTotals stores the total active users response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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