@@ -25,8 +25,6 @@ import (
2525 "github.com/spf13/cobra"
2626 "io/ioutil"
2727 "net/http"
28- "net/url"
29- "strings"
3028)
3129
3230const (
@@ -124,50 +122,3 @@ type MixPanelResponse struct {
124122 } `json:"$properties"`
125123 } `json:"results"`
126124}
127-
128- //User is opted in by default
129- //If distinct id can't be found through query api, return true to reflect that user is opted in
130- func IsUserOptedIn () (bool , error ) {
131- distinctId , err := generateNewDistinctId ()
132- if err != nil {
133- return false , err
134- }
135-
136- queryPayload := "distinct_id=" + url .QueryEscape (distinctId )
137- payload := strings .NewReader (queryPayload )
138- req , err := http .NewRequest ("POST" , MIXPANEL_QUERY_URL , payload )
139- if err != nil {
140- return false , err
141- }
142-
143- mixpanelAuth := "Basic " + MIXPANEL_SERVICE_ACCOUNT_SECRET
144- req .Header .Add ("Accept" , "application/json" )
145- req .Header .Add ("Content-Type" , "application/x-www-form-urlencoded" )
146- req .Header .Add ("Authorization" , mixpanelAuth )
147-
148- res , err := http .DefaultClient .Do (req )
149- if err != nil {
150- return false , err
151- }
152-
153- defer res .Body .Close ()
154- body , err := ioutil .ReadAll (res .Body )
155-
156- var queryResponse MixPanelResponse
157- err = json .Unmarshal (body , & queryResponse )
158-
159- if err != nil {
160- return false , err
161- }
162- if res .StatusCode >= 400 {
163- if res .StatusCode == 429 {
164- //tracking is enabled by default if there is rate limit error from mixpanel
165- return true , nil
166- }
167- return false , fmt .Errorf ("invalid response status code %d for tracking command usage" , res .StatusCode )
168- }
169- if len (queryResponse .Results ) == 0 {
170- return true , nil
171- }
172- return queryResponse .Results [0 ].Properties .OptIn , nil
173- }
0 commit comments