ga

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(c AccountToken, id, metrics, dimensions, filters, sortOrder string, days int) (map[string]int, error)

Get is ...

Example
package main

import (
	"fmt"
	"os"

	"../ga"
)

func getNewAccountTokenFromEnv() ga.AccountToken {
	clientID := os.Getenv("GA_CLIENT_ID")
	clientSecret := os.Getenv("GA_CLIENT_SECRET")
	refreshToken := os.Getenv("GA_REFRESH_TOKEN")
	return ga.NewAccountToken(clientID, clientSecret, refreshToken)
}

func main() {
	metrics := "ga:uniquePageviews"
	dimensions := "ga:pagePath"
	sortOrder := "-ga:uniquePageviews"
	filters := "ga:pagePath=~^/path/to/site/.*"
	res, _ := ga.Get(getNewAccountTokenFromEnv(), os.Getenv("GA_ID"), metrics, dimensions, filters, sortOrder, 1)
	fmt.Println(res)
}
Output:

map[/path/to/site/index.html:100 /path/to/site/about.html:10 /path/to/site/other.html:12]

func GetEvent

func GetEvent(c AccountToken, id string, category string, days int, useRegex bool) (map[string]int, error)

GetEvent is ...

Example
package main

import (
	"fmt"
	"os"

	"../ga"
)

func getNewAccountTokenFromEnv() ga.AccountToken {
	clientID := os.Getenv("GA_CLIENT_ID")
	clientSecret := os.Getenv("GA_CLIENT_SECRET")
	refreshToken := os.Getenv("GA_REFRESH_TOKEN")
	return ga.NewAccountToken(clientID, clientSecret, refreshToken)
}

func main() {
	res, _ := ga.GetEvent(getNewAccountTokenFromEnv(), os.Getenv("GA_ID"), "^.*Tag/.*", 30, true)
	fmt.Println(res)
}
Output:

map[iPhone:10 Android:17 Windows:12]

Types

type AccountToken

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

AccountToken .

func NewAccountToken

func NewAccountToken(clientID, clientSecret, refreshToken string) AccountToken

NewAccountToken is constractor

func (AccountToken) CreateAnalyticsService

func (ac AccountToken) CreateAnalyticsService() *analytics.Service

CreateAnalyticsService : create service

Jump to

Keyboard shortcuts

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