Socket
Socket
Sign inDemoInstall

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

Package Overview
Dependencies
4
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

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


Version published

Readme

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

Last updated on 27 Aug 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc