Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,7 @@ func (c Command) handleUserTracking() {
if util.MIXPANEL_SERVICE_ACCOUNT_SECRET == "" || util.MIXPANEL_PROJECT_TOKEN == "" {
return
}
optedIn, err := util.IsUserOptedIn()
if err != nil {
sentry.CaptureException(err)
}
if optedIn {
err = util.TrackCommandUsage(c.Cmd)
if err != nil {
sentry.CaptureException(err)
}
}
_ = util.TrackCommandUsage(c.Cmd)
}

// AddToParent add new command to main parent cmd
Expand Down
49 changes: 0 additions & 49 deletions pkg/flowkit/util/mixpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"github.com/spf13/cobra"
"io/ioutil"
"net/http"
"net/url"
"strings"
)

const (
Expand Down Expand Up @@ -124,50 +122,3 @@ type MixPanelResponse struct {
} `json:"$properties"`
} `json:"results"`
}

//User is opted in by default
//If distinct id can't be found through query api, return true to reflect that user is opted in
func IsUserOptedIn() (bool, error) {
distinctId, err := generateNewDistinctId()
if err != nil {
return false, err
}

queryPayload := "distinct_id=" + url.QueryEscape(distinctId)
payload := strings.NewReader(queryPayload)
req, err := http.NewRequest("POST", MIXPANEL_QUERY_URL, payload)
if err != nil {
return false, err
}

mixpanelAuth := "Basic " + MIXPANEL_SERVICE_ACCOUNT_SECRET
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", mixpanelAuth)

res, err := http.DefaultClient.Do(req)
if err != nil {
return false, err
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)

var queryResponse MixPanelResponse
err = json.Unmarshal(body, &queryResponse)

if err != nil {
return false, err
}
if res.StatusCode >= 400 {
if res.StatusCode == 429 {
//tracking is enabled by default if there is rate limit error from mixpanel
return true, nil
}
return false, fmt.Errorf("invalid response status code %d for tracking command usage", res.StatusCode)
}
if len(queryResponse.Results) == 0 {
return true, nil
}
return queryResponse.Results[0].Properties.OptIn, nil
}