Skip to content

Commit

Permalink
Merge pull request #1079 from tchapgouv/1078-enable-analytics-on-debug
Browse files Browse the repository at this point in the history
Activation de l'analytics PostHog en version Debug
  • Loading branch information
NicolasBuquet authored Aug 14, 2024
2 parents 401ef7b + de3042d commit 3098586
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Btchap/Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ final class BuildSettings: NSObject {

#if DEBUG
/// The configuration to use for analytics during development. Set `isEnabled` to false to disable analytics in debug builds.
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: false,
host: "",
apiKey: "",
termsURL: URL(string: "https://")!)
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: true, // Tchap: enable PostHog analytics on DEBUG
host: "https://us.i.posthog.com", // Tchap: dev posthog,
apiKey: "phc_eQOeaQiaIxdX9kaQmqYTD7RJLyFubYmGYKUI9czqqQD", // Tchap: dev posthog,
termsURL: URL(string: "https://tchap.beta.gouv.fr/politique-de-confidentialite")!) // Tchap: dev posthog,
#else
/// The configuration to use for analytics. Set `isEnabled` to false to disable analytics.
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: false,
Expand Down
8 changes: 4 additions & 4 deletions DevTchap/Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ final class BuildSettings: NSObject {

#if DEBUG
/// The configuration to use for analytics during development. Set `isEnabled` to false to disable analytics in debug builds.
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: false,
host: "",
apiKey: "",
termsURL: URL(string: "")!)
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: true, // Tchap: enable PostHog analytics on DEBUG
host: "https://us.i.posthog.com", // Tchap: dev posthog,
apiKey: "phc_eQOeaQiaIxdX9kaQmqYTD7RJLyFubYmGYKUI9czqqQD", // Tchap: dev posthog,
termsURL: URL(string: "https://tchap.beta.gouv.fr/politique-de-confidentialite")!) // Tchap: dev posthog,
#else
/// The configuration to use for analytics. Set `isEnabled` to false to disable analytics.
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: false,
Expand Down
4 changes: 3 additions & 1 deletion Riot/Modules/Analytics/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ import AnalyticsEvents
/// Whether to show the user the analytics opt in prompt.
var shouldShowAnalyticsPrompt: Bool {
// Only show the prompt once, and when analytics are enabled in BuildSettings.
!RiotSettings.shared.hasSeenAnalyticsPrompt && BuildSettings.analyticsConfiguration.isEnabled
// Tchap: always return FALSE because user already agreed about analytics in the private policy
// !RiotSettings.shared.hasSeenAnalyticsPrompt && BuildSettings.analyticsConfiguration.isEnabled
false
}

/// Indicates whether the user previously accepted Matomo analytics and should be shown the upgrade prompt.
Expand Down
22 changes: 21 additions & 1 deletion Riot/Modules/Application/LegacyAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
profiler.analytics = analytics;
[MXSDKOptions sharedInstance].profiler = profiler;

[analytics startIfEnabled];
// Tchap: Don't try to start analytics here.
// Wait to have MXSession initialized in `handleAppState` method.
// [analytics startIfEnabled];

self.localAuthenticationService = [[LocalAuthenticationService alloc] initWithPinCodePreferences:[PinCodePreferences shared]];

Expand Down Expand Up @@ -2551,6 +2553,24 @@ - (void)handleAppState
// An observer has been set in didFinishLaunching that will call the stored block when ready
self.roomListDataReadyCompletion = finishAppLaunch;
}

// Tchap: handle analytics start now that a MXSession is known.
// Check classes with `object_getClass` function because they are `id` conforming to protocols and not direct objects.
if (object_getClass(MXSDKOptions.sharedInstance.profiler) == MXBaseProfiler.class &&
object_getClass(((MXBaseProfiler *)MXSDKOptions.sharedInstance.profiler).analytics) == Analytics.class)
{
Analytics *analytics = (Analytics *)((MXBaseProfiler *)MXSDKOptions.sharedInstance.profiler).analytics;
#if DEBUG
// Tchap: Force analytics acceptance in DEBUG mode
// `optInWith:` calls `startIfEnabled`
[analytics optInWith:mainSession];
#else
// Tchap: start analytics as it was done in `application:didFinishLaunchingWithOptions:`
[analytics startIfEnabled];
#endif
}


}
}

Expand Down
8 changes: 4 additions & 4 deletions Tchap/Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ final class BuildSettings: NSObject {

#if DEBUG
/// The configuration to use for analytics during development. Set `isEnabled` to false to disable analytics in debug builds.
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: false,
host: "",
apiKey: "",
termsURL: URL(string: "https://")!)
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: true, // Tchap: enable PostHog analytics on DEBUG
host: "https://us.i.posthog.com", // Tchap: dev posthog,
apiKey: "phc_eQOeaQiaIxdX9kaQmqYTD7RJLyFubYmGYKUI9czqqQD", // Tchap: dev posthog,
termsURL: URL(string: "https://tchap.beta.gouv.fr/politique-de-confidentialite")!) // Tchap: dev posthog,
#else
/// The configuration to use for analytics. Set `isEnabled` to false to disable analytics.
static let analyticsConfiguration = AnalyticsConfiguration(isEnabled: false,
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1078.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Activation de l'analytics PostHog en version Debug

0 comments on commit 3098586

Please sign in to comment.