Skip to content

Commit

Permalink
feat: migrate to matomo analytics (#4095)
Browse files Browse the repository at this point in the history
* add matomo anlytics

* matomo url

* add changelog

* matomo  analytics refacor

* build analytics url

* fix matomo request parameters

* remove unused parameters and improve readability

* remove unused matomo request response parser

* fix analytics data

* change the source name to github

* fix UTM values

* fix scaffold type condition

* remove gacli pkg

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani authored Jun 7, 2024
1 parent 24770f1 commit e49e11d
Show file tree
Hide file tree
Showing 7 changed files with 414 additions and 198 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [#4133](https://github.com/ignite/cli/pull/4133) Improve buf rate limit
- [#4113](https://github.com/ignite/cli/pull/4113) Generate chain config documentation automatically
- [#4131](https://github.com/ignite/cli/pull/4131) Support `bytes` as data type in the `scaffold` commands
- [#4095](https://github.com/ignite/cli/pull/4095) Migrate to matomo analytics

### Changes

Expand Down
9 changes: 7 additions & 2 deletions ignite/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ func NewVersion() *cobra.Command {
c := &cobra.Command{
Use: "version",
Short: "Print the current build information",
Run: func(cmd *cobra.Command, _ []string) {
cmd.Println(version.Long(cmd.Context()))
RunE: func(cmd *cobra.Command, _ []string) error {
v, err := version.Long(cmd.Context())
if err != nil {
return err
}
cmd.Println(v)
return nil
},
}
return c
Expand Down
63 changes: 45 additions & 18 deletions ignite/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package analytics

import (
"context"
"encoding/json"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
Expand All @@ -13,21 +13,21 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/v29/ignite/config"
"github.com/ignite/cli/v29/ignite/pkg/gacli"
"github.com/ignite/cli/v29/ignite/pkg/gitpod"
"github.com/ignite/cli/v29/ignite/pkg/matomo"
"github.com/ignite/cli/v29/ignite/pkg/randstr"
"github.com/ignite/cli/v29/ignite/version"
)

const (
telemetryEndpoint = "https://telemetry-cli.ignite.com"
telemetryEndpoint = "https://matomo-cli.ignite.com"
envDoNotTrack = "DO_NOT_TRACK"
envCI = "CI"
envGitHubActions = "GITHUB_ACTIONS"
igniteAnonIdentity = "anon_identity.json"
)

var gaclient gacli.Client
var matomoClient matomo.Client

// anonIdentity represents an analytics identity file.
type anonIdentity struct {
Expand All @@ -38,7 +38,11 @@ type anonIdentity struct {
}

func init() {
gaclient = gacli.New(telemetryEndpoint)
matomoClient = matomo.New(
telemetryEndpoint,
matomo.WithIDSite(4),
matomo.WithSource("https://cli.ignite.com"),
)
}

// SendMetric send command metrics to analytics.
Expand All @@ -52,23 +56,46 @@ func SendMetric(wg *sync.WaitGroup, cmd *cobra.Command) {
return
}

path := cmd.CommandPath()
met := gacli.Metric{
Name: cmd.Name(),
Cmd: path,
Tag: strings.ReplaceAll(path, " ", "+"),
OS: runtime.GOOS,
Arch: runtime.GOARCH,
SessionID: dntInfo.Name,
Version: version.Version,
IsGitPod: gitpod.IsOnGitpod(),
IsCI: getIsCI(),
versionInfo, err := version.GetInfo(context.Background())
if err != nil {
return
}

var (
path = cmd.CommandPath()
scaffoldType = ""
)
if strings.Contains(path, "ignite scaffold") {
splitCMD := strings.Split(path, " ")
if len(splitCMD) > 2 {
scaffoldType = splitCMD[2]
}
}

met := matomo.Metric{
Name: cmd.Name(),
Cmd: path,
ScaffoldType: scaffoldType,
OS: versionInfo.OS,
Arch: versionInfo.Arch,
Version: versionInfo.CLIVersion,
CLIVersion: versionInfo.CLIVersion,
GoVersion: versionInfo.GoVersion,
SDKVersion: versionInfo.SDKVersion,
BuildDate: versionInfo.BuildDate,
SourceHash: versionInfo.SourceHash,
ConfigVersion: versionInfo.ConfigVersion,
Uname: versionInfo.Uname,
CWD: versionInfo.CWD,
BuildFromSource: versionInfo.BuildFromSource,
IsGitPod: gitpod.IsOnGitpod(),
IsCI: getIsCI(),
}

wg.Add(1)
go func() {
defer wg.Done()
_ = gaclient.SendMetric(met)
_ = matomoClient.SendMetric(dntInfo.Name, met)
}()
}

Expand Down Expand Up @@ -98,7 +125,7 @@ func checkDNT() (anonIdentity, error) {
return i, nil
}

i.Name = randstr.Runes(10)
i.Name = randstr.Runes(16)
i.DoNotTrack = false

prompt := promptui.Select{
Expand Down
2 changes: 0 additions & 2 deletions ignite/pkg/gacli/doc.go

This file was deleted.

125 changes: 0 additions & 125 deletions ignite/pkg/gacli/gacli.go

This file was deleted.

Loading

0 comments on commit e49e11d

Please sign in to comment.