@@ -38,7 +38,7 @@ public class AuthenticatorAnalyticsTracker {
3838
3939 /// Starts when the used adds a site from the site picker
4040 ///
41- case selfHosted
41+ case selfHosted = " self_hosted "
4242 }
4343
4444 public enum Flow : String {
@@ -234,34 +234,9 @@ public class AuthenticatorAnalyticsTracker {
234234 /// Shared Instance.
235235 ///
236236 public static var shared : AuthenticatorAnalyticsTracker = {
237- return AuthenticatorAnalyticsTracker ( configuration : defaultConfiguration ( ) )
237+ return AuthenticatorAnalyticsTracker ( )
238238 } ( )
239239
240- struct Configuration {
241- let appleEnabled : Bool
242- let googleEnabled : Bool
243- let iCloudKeychainEnabled : Bool
244- let prologueEnabled : Bool
245- let siteAddressEnabled : Bool
246- let wpComEnabled : Bool
247- }
248-
249- private class func defaultConfiguration( ) -> Configuration {
250- // When unit testing, WordPressAuthenticator is not always initialized.
251- // The following code ensures we have configuration defaults even if that's the case.
252- guard WordPressAuthenticator . isInitialized ( ) else {
253- return Configuration ( appleEnabled: false , googleEnabled: false , iCloudKeychainEnabled: false , prologueEnabled: false , siteAddressEnabled: false , wpComEnabled: false )
254- }
255-
256- return Configuration (
257- appleEnabled: WordPressAuthenticator . shared. configuration. enableUnifiedApple,
258- googleEnabled: WordPressAuthenticator . shared. configuration. enableUnifiedGoogle,
259- iCloudKeychainEnabled: WordPressAuthenticator . shared. configuration. enableUnifiedKeychainLogin,
260- prologueEnabled: true ,
261- siteAddressEnabled: WordPressAuthenticator . shared. configuration. enableUnifiedSiteAddress,
262- wpComEnabled: WordPressAuthenticator . shared. configuration. enableUnifiedWordPress)
263- }
264-
265240 /// State for the analytics tracker.
266241 ///
267242 public class State {
@@ -276,22 +251,23 @@ public class AuthenticatorAnalyticsTracker {
276251 }
277252 }
278253
279- /// The tracking configuration.
280- ///
281- private let configuration : Configuration
282-
283254 /// The state of this tracker.
284255 ///
285256 public let state = State ( )
286257
287258 /// The backing analytics tracking method. Can be overridden for testing purposes.
288259 ///
289260 let track : TrackerMethod
261+
262+ /// Whether tracking is enabled or not. This is just a convenience configuration to enable this tracker to be turned on and off
263+ /// using a feature flag. It should go away once we remove the legacy tracking.
264+ ///
265+ let enabled : Bool
290266
291267 // MARK: - Initializers
292268
293- init ( configuration : Configuration , track: @escaping TrackerMethod = WPAnalytics . track) {
294- self . configuration = configuration
269+ init ( enabled : Bool = WordPressAuthenticator . shared . configuration . enableUnifiedAuth , track: @escaping TrackerMethod = WPAnalytics . track) {
270+ self . enabled = enabled
295271 self . track = track
296272 }
297273
@@ -310,14 +286,8 @@ public class AuthenticatorAnalyticsTracker {
310286 ///
311287 /// - Returns: `true` if we can track using the state machine.
312288 ///
313- public func canTrackInCurrentFlow( ) -> Bool {
314- return isInSiteAuthenticationFlowAndCanTrack ( )
315- || isInAppleFlowAndCanTrack ( )
316- || isInGoogleFlowAndCanTrack ( )
317- || isInMagicLinkFlowAndCanTrack ( )
318- || isInWPComFlowAndCanTrack ( )
319- || isInPrologueFlowAndCanTrack ( )
320- || isInKeychainFlowAndCanTrack ( )
289+ public func canTrack( ) -> Bool {
290+ return enabled
321291 }
322292
323293 /// This is a convenience method, that's useful for cases where we simply want to check if the legacy tracking should be
@@ -326,45 +296,15 @@ public class AuthenticatorAnalyticsTracker {
326296 /// - Returns: `true` if we must use legacy tracking, `false` otherwise.
327297 ///
328298 public func shouldUseLegacyTracker( ) -> Bool {
329- return !canTrackInCurrentFlow( )
330- }
331-
332- // MARK: - Legacy vs Unified tracking: Support Methods
333-
334- private func isInSiteAuthenticationFlowAndCanTrack( ) -> Bool {
335- return configuration. siteAddressEnabled && state. lastFlow == . loginWithSiteAddress
336- }
337-
338- private func isInAppleFlowAndCanTrack( ) -> Bool {
339- return configuration. appleEnabled && [ Flow . loginWithApple, . signupWithApple] . contains ( state. lastFlow)
340- }
341-
342- private func isInGoogleFlowAndCanTrack( ) -> Bool {
343- return configuration. googleEnabled && [ Flow . loginWithGoogle, . signupWithGoogle] . contains ( state. lastFlow)
344- }
345-
346- private func isInMagicLinkFlowAndCanTrack( ) -> Bool {
347- return configuration. wpComEnabled && state. lastFlow == . loginWithMagicLink
348- }
349-
350- private func isInWPComFlowAndCanTrack( ) -> Bool {
351- return configuration. wpComEnabled && [ Flow . wpCom, . signup, . loginWithPassword] . contains ( state. lastFlow)
352- }
353-
354- private func isInPrologueFlowAndCanTrack( ) -> Bool {
355- return configuration. prologueEnabled && state. lastFlow == . prologue
356- }
357-
358- private func isInKeychainFlowAndCanTrack( ) -> Bool {
359- return configuration. iCloudKeychainEnabled && state. lastFlow == . loginWithiCloudKeychain
299+ return !canTrack( )
360300 }
361301
362302 // MARK: - Tracking
363303
364304 /// Track a step within a flow.
365305 ///
366306 public func track( step: Step ) {
367- guard canTrackInCurrentFlow ( ) else {
307+ guard canTrack ( ) else {
368308 return
369309 }
370310
@@ -374,7 +314,7 @@ public class AuthenticatorAnalyticsTracker {
374314 /// Track a click interaction.
375315 ///
376316 public func track( click: ClickTarget ) {
377- guard canTrackInCurrentFlow ( ) else {
317+ guard canTrack ( ) else {
378318 return
379319 }
380320
@@ -384,7 +324,7 @@ public class AuthenticatorAnalyticsTracker {
384324 /// Track a failure.
385325 ///
386326 public func track( failure: String ) {
387- guard canTrackInCurrentFlow ( ) else {
327+ guard canTrack ( ) else {
388328 return
389329 }
390330
@@ -397,7 +337,7 @@ public class AuthenticatorAnalyticsTracker {
397337 /// for the flow.
398338 ///
399339 public func track( step: Step , ifTrackingNotEnabled legacyTracking: ( ) -> ( ) ) {
400- guard canTrackInCurrentFlow ( ) else {
340+ guard canTrack ( ) else {
401341 legacyTracking ( )
402342 return
403343 }
@@ -409,7 +349,7 @@ public class AuthenticatorAnalyticsTracker {
409349 /// for the flow.
410350 ///
411351 public func track( click: ClickTarget , ifTrackingNotEnabled legacyTracking: ( ) -> ( ) ) {
412- guard canTrackInCurrentFlow ( ) else {
352+ guard canTrack ( ) else {
413353 legacyTracking ( )
414354 return
415355 }
@@ -421,7 +361,7 @@ public class AuthenticatorAnalyticsTracker {
421361 /// for the flow.
422362 ///
423363 public func track( failure: String , ifTrackingNotEnabled legacyTracking: ( ) -> ( ) ) {
424- guard canTrackInCurrentFlow ( ) else {
364+ guard canTrack ( ) else {
425365 legacyTracking ( )
426366 return
427367 }
0 commit comments