@@ -17,6 +17,7 @@ import (
1717 "github.com/rawnly/splash-cli/lib/github"
1818 "github.com/rawnly/splash-cli/lib/github/models"
1919 "github.com/rawnly/splash-cli/lib/keys"
20+ "github.com/rawnly/splash-cli/lib/telemetry"
2021 "github.com/rawnly/splash-cli/unsplash"
2122 "github.com/rawnly/splash-cli/unsplash/tokens"
2223 "github.com/rs/zerolog/log"
@@ -133,6 +134,12 @@ func main() {
133134
134135 ctx := context .Background ()
135136 analyticsClient := setupPosthog ()
137+ telemetryClient , err := telemetry .New ()
138+ if err != nil {
139+ log .Debug ().Err (err ).Msg ("Failed to initialize telemetry" )
140+ telemetryClient = & telemetry.Telemetry {Enabled : false }
141+ }
142+
136143 api := unsplash.Api {
137144 ClientId : clientID ,
138145 RedirectUri : "http://localhost:5835" ,
@@ -147,6 +154,7 @@ func main() {
147154 ctx = context .WithValue (ctx , keys .IsLogged , accessToken != "" && refreshToken != "" )
148155 ctx = context .WithValue (ctx , keys .APIInstance , api )
149156 ctx = context .WithValue (ctx , keys .Analytics , analyticsClient )
157+ ctx = context .WithValue (ctx , keys .Telemetry , telemetryClient )
150158
151159 go setupSentry ()
152160 defer sentry .Flush (2 * time .Second )
@@ -159,6 +167,10 @@ func main() {
159167 if err := analyticsClient .Close (); err != nil {
160168 log .Error ().Msgf ("Error closing analytics client: %s" , err )
161169 }
170+
171+ if err := telemetryClient .Close (); err != nil {
172+ log .Error ().Msgf ("Error closing telemetry client: %s" , err )
173+ }
162174 }()
163175
164176 log .Trace ().Msg ("Checking if first run" )
@@ -168,10 +180,17 @@ func main() {
168180 viper .Set ("has_run_before" , true )
169181 viper .Set ("user_id" , uuid .NewString ())
170182
183+ // First prompt for analytics consent
171184 if analyticsClient .PromptConsent () {
172185 analyticsClient .Capture ("installation" , nil )
173186 }
174187
188+ // Then prompt for telemetry consent
189+ telemetryClient .PromptTelemetryConsent (ctx )
190+
191+ // Always track installation if telemetry is enabled (after consent)
192+ telemetryClient .TrackInstallation (ctx )
193+
175194 err := viper .WriteConfig ()
176195 cobra .CheckErr (err )
177196 }
0 commit comments