github.com/skabbes/up@v0.2.1/internal/stats/stats.go (about)

     1  // Package stats provides CLI analytics.
     2  package stats
     3  
     4  import (
     5  	"github.com/apex/log"
     6  	"github.com/tj/go-cli-analytics"
     7  )
     8  
     9  // p merged with track calls.
    10  var p = map[string]interface{}{}
    11  
    12  // Client for Segment analytics.
    13  var Client = analytics.New(&analytics.Config{
    14  	WriteKey: "qnvYCHktBBgACBkQ6V4dzh7aFCe8LF8u",
    15  	Dir:      ".up",
    16  })
    17  
    18  // Track event `name` with optional `props`.
    19  func Track(name string, props map[string]interface{}) {
    20  	if props == nil {
    21  		props = map[string]interface{}{}
    22  	}
    23  
    24  	for k, v := range p {
    25  		props[k] = v
    26  	}
    27  
    28  	log.Debugf("track %q %v", name, props)
    29  	Client.Track(name, props)
    30  }
    31  
    32  // SetProperties sets global properties.
    33  func SetProperties(props map[string]interface{}) {
    34  	p = props
    35  }