func (a *Analytics) Enabled() (bool, error) {
	_, err := os.Stat(filepath.Join(a.root, "disable"))
	if os.IsNotExist(err) {
		return true, nil
	}
	return false, err
}
Enabled returns true if the user hasn't opted out.
package analytics
import (
	"encoding/json"
	"io"
	"io/ioutil"
	stdlog "log"
	"os"
	"path/filepath"
	"time"
	"github.com/apex/log"
	"github.com/hashicorp/go-uuid"
	"github.com/mitchellh/go-homedir"
	"github.com/pkg/errors"
	segment "github.com/segmentio/analytics-go"
)
type Event struct {
	Event      string                 `json:"event"`
	Properties map[string]interface{} `json:"properties"`
}
type Config struct {
	WriteKey string         
	Dir      string         
	Log      log.Interface  
}
func (c *Config) defaults() {
	if c.Log == nil {
		c.Log = log.Log
	}
}
func New(config *Config) *Analytics {
	config.defaults()
	a := &Analytics{
		Config: config,
	}
	a.init()
	return a
}
type Analytics struct {
	*Config
	root       string
	userID     string
	eventsFile *os.File
	events     *json.Encoder
}
func (a *Analytics) init() {
	a.initRoot()
	enabled, err := a.Enabled()
	if err != nil || !enabled {
		a.Log.Debug("disabled")
		return
	}
	a.initDir()
	a.initID()
	a.initEvents()
}
func (a *Analytics) initRoot() {
	home, err := homedir.Dir()
	if err != nil {
		a.Log.WithError(err).Debug("error finding home dir")
		return
	}
	a.root = filepath.Join(home, a.Dir)
}
func (a *Analytics) initDir() {
	os.Mkdir(a.root, 0755)
}
func (a *Analytics) initID() {
	path := filepath.Join(a.root, "id")
	b, err := ioutil.ReadFile(path)
	if err == nil {
		a.userID = string(b)
		a.Log.Debug("id already created")
		return
	}
	a.Log.Debug("creating id")
	id, err := uuid.GenerateUUID()
	if err != nil {
		return
	}
	a.userID = string(id)
	err = ioutil.WriteFile(path, []byte(id), 0666)
	if err != nil {
		a.Log.WithError(err).Debug("error saving id")
		return
	}
	a.Touch()
}
func (a *Analytics) initEvents() {
	path := filepath.Join(a.root, "events")
	f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		log.WithError(err).Debug("error opening events")
		return
	}
	a.eventsFile = f
	a.events = json.NewEncoder(f)
}