Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide an environment variable to disable GA #436

Merged
merged 5 commits into from Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -9,6 +9,10 @@ Command-line tool to develop and manage [LeanCloud](https://leancloud.cn) apps.
- via `homebrew`: `$ brew install lean-cli`
- via `https://releases.leanapp.cn/#/leancloud/lean-cli/releases`(In case of your connection with GitHub cracked)

lean-cli will send stastics information such as your os version and lean-cli version to Google Analytics.
This stastics information helps us to improve LeanEngine services.
To opt out, you can set the environment variable `NO_ANALYTICS` to `true`.

## Develop

Install the toolchains:
Expand All @@ -23,7 +27,7 @@ Clone this repo then run `make all` to build releases.

Please run `go mod tidy` and `go mod vendor` to make vendored copy of dependencies after importing new dependencies.

Ensure all codes is formated by [gofmt](https://golang.org/cmd/gofmt/). Commit message should write in [gitmoji](https://gitmoji.carloscuesta.me/).
Ensure all codes is formatted by [gofmt](https://golang.org/cmd/gofmt/). Commit message should write in [gitmoji](https://gitmoji.carloscuesta.me/).

## Release

Expand Down
10 changes: 6 additions & 4 deletions commands/app.go
Expand Up @@ -326,10 +326,12 @@ func Run(args []string) {
}

app.Before = func(c *cli.Context) error {
args := []string{"--_collect-stats"}
args = append(args, c.Args()...)
err := exec.Command(os.Args[0], args...).Start()
_ = err
disableGA, ok := os.LookupEnv("NO_ANALYTICS")
if !ok || disableGA == "false" {
args = []string{"--_collect-stats"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不用 args := 的话会不会影响外层的 args

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

会的,加上了。

args = append(args, c.Args()...)
_ = exec.Command(os.Args[0], args...).Start()
}
return nil
}

Expand Down
6 changes: 5 additions & 1 deletion stats/collect.go
@@ -1,6 +1,7 @@
package stats

import (
"fmt"
"runtime"

"github.com/levigross/grequests"
Expand Down Expand Up @@ -37,7 +38,7 @@ type ClientType struct {

// Collect the user's stats
func Collect(event Event) {
grequests.Post("https://www.google-analytics.com/collect", &grequests.RequestOptions{
_, err := grequests.Post("https://www.google-analytics.com/collect", &grequests.RequestOptions{
Data: map[string]string{
"aid": Client.Platform,
"aiid": Client.AppChannel,
Expand All @@ -51,4 +52,7 @@ func Collect(event Event) {
"v": "1",
},
})
if err != nil {
fmt.Println("Failed to send statistics to Google Analytics.")
}
}