func (kv *KbrewEvent) Report(ctx context.Context, ec EventCategory, err error, k8sEvent *k8sEvent) error {
	v := url.Values{
		"v":   {kv.gaVersion},
		"tid": {kv.gaTID},
		"cid": {kv.gaCID},
		"aip": {kv.gaAIP},
		"t":   {kv.gaType},
		"ec":  {ec.String()},
		"ea":  {kv.gaEvAction},
		"el":  {kv.gaEvLabel},
		"an":  {kv.gaAppName},
		"av":  {kv.gaAppVersion},
		"cd1": {},
		"cd2": {},
		"cd3": {},
		"cd4": {},
		"cd5": {},
		"cd6": {kv.gaKbrewArgs},
	}
	if err != nil {
		v.Set("cd5", err.Error())
	}
	if k8sEvent != nil {
		v.Set("cd1", k8sEvent.Reason)
		v.Set("cd2", k8sEvent.Message)
		v.Set("cd3", k8sEvent.Action)
		v.Set("cd4", k8sEvent.Object)
	}
	buf := bytes.NewBufferString(v.Encode())
	req, err1 := http.NewRequest("POST", gaCollectURL, buf)
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Add("User-Agent", fmt.Sprintf("kbrew/%s", version.Short()))
	if err1 != nil {
		return err1
	}
	ctx, cancel := context.WithTimeout(ctx, httpTimeout)
	defer cancel()
	req = req.WithContext(ctx)
	client := http.DefaultClient
	resp, err1 := client.Do(req)
	if err1 != nil {
		return err1
	}
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("analytics report failed with status code %d", resp.StatusCode)
	}
	defer resp.Body.Close()
	return err1
}
Report sends event to Google Analytics
package events
import (
	"bytes"
	"context"
	"fmt"
	"net/http"
	"net/url"
	"time"
	"github.com/spf13/viper"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/labels"
	"github.com/kbrew-dev/kbrew/pkg/config"
	"github.com/kbrew-dev/kbrew/pkg/kube"
	"github.com/kbrew-dev/kbrew/pkg/version"
)
type EventCategory string
const (
	kbrewTrackingID = "UA-195717361-1"
	gaCollectURL    = "https://www.google-analytics.com/collect"
	httpTimeout     = 5 * time.Second
)
var (
	ECInstallSuccess EventCategory = "install-success"
	ECInstallFail EventCategory = "install-fail"
	ECInstallTimeout EventCategory = "install-timeout"
	ECUninstallSuccess EventCategory = "uninstall-success"
	ECUninstallFail EventCategory = "uninstall-fail"
	ECUninstallTimeout EventCategory = "uninstall-timeout"
	ECK8sEvent EventCategory = "k8s-event"
)
type k8sEvent struct {
	Reason  string
	Message string
	Object  string
	Action  string
}
type KbrewEvent struct {
	gaVersion    string
	gaType       string
	gaTID        string
	gaCID        string
	gaAIP        string
	gaAppName    string
	gaAppVersion string
	gaEvAction  string
	gaEvLabel   string
	gaKbrewArgs string
}
func (ec EventCategory) String() string {
	return string(ec)
}
func NewKbrewEvent(appConfig *config.AppConfig) *KbrewEvent {
	k8sVersion, err := kube.GetK8sVersion()
	if err != nil {
		fmt.Printf("ERROR: Failed to fetch K8s version, %s\n", err.Error())
		k8sVersion = "NA"
	}
	return &KbrewEvent{
		gaVersion:    "1",
		gaType:       "event",
		gaTID:        kbrewTrackingID,
		gaCID:        viper.GetString(config.AnalyticsUUID),
		gaAIP:        "1",
		gaAppName:    "kbrew",
		gaAppVersion: version.Short(),
		gaEvLabel:    fmt.Sprintf("k8s %s", k8sVersion),
		gaEvAction:   appConfig.App.Name,
		gaKbrewArgs:  labels.FormatLabels(argsToLabels(appConfig.App.Args)),
	}
}