🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/m-hosoi/go-google-analytics

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/m-hosoi/go-google-analytics

v1.0.0
Source
Go
Version published
Created
Source

go-google-analytics

Google Analytics Helper for GoLang

Install

go get golang.org/x/net/context
go get golang.org/x/oauth2
go get golang.org/x/oauth2/google
go get google.golang.org/api/analytics/v3
go get github.com/m-hosoi/go-google-analytics/ga

Usage

import (
    "fmt"
    "os"

    "github.com/m-hosoi/go-google-analytics/ga"
)

func getNewContextFromEnv() ga.Context {
    clientID := os.Getenv("GA_CLIENT_ID")
    clientSecret := os.Getenv("GA_CLIENT_SECRET")
    refreshToken := os.Getenv("GA_REFRESH_TOKEN")
    return ga.NewContext(clientID, clientSecret, refreshToken)
}

func ExampleGetEvent() {
    res := ga.GetEvent(getNewContextFromEnv(), os.Getenv("GA_ID"), "^.*Tag/.*", 30, true)
    fmt.Println(res)
    // Output:
    // map[iPhone:10 Android:17 Windows:12]
}

func ExampleGet() {
    metrics := "ga:uniquePageviews"
    dimensions := "ga:pagePath"
    sortOrder := "-ga:uniquePageviews"
    filters := "ga:pagePath=~^/path/to/site/.*"
    res := ga.Get(getNewContextFromEnv(), 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]
}

FAQs

Package last updated on 27 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts