From eac44c05694fc42c334802517f239f5b9fd5489b Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 16 Jul 2015 14:04:48 +0300 Subject: [alohalytics] Initialize user agent on each launch, not only on install/update events. --- 3party/Alohalytics/src/apple/alohalytics_objc.mm | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/3party/Alohalytics/src/apple/alohalytics_objc.mm b/3party/Alohalytics/src/apple/alohalytics_objc.mm index b36a11e4d0..62eda99572 100644 --- a/3party/Alohalytics/src/apple/alohalytics_objc.mm +++ b/3party/Alohalytics/src/apple/alohalytics_objc.mm @@ -140,14 +140,7 @@ static std::string RectToString(CGRect const & rect) { } // Logs some basic device's info. -static void LogSystemInformation() { - // Initialize User Agent later, as it takes significant time at startup. - dispatch_async(dispatch_get_main_queue(), ^{ - gBrowserUserAgent = [[[UIWebView alloc] initWithFrame:CGRectZero] stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; - if (gBrowserUserAgent) { - Stats::Instance().LogEvent("$browserUserAgent", ToStdString(gBrowserUserAgent)); - } - }); +static void LogSystemInformation(NSString * userAgent) { UIDevice * device = [UIDevice currentDevice]; UIScreen * screen = [UIScreen mainScreen]; std::string preferredLanguages; @@ -186,6 +179,10 @@ static void LogSystemInformation() { info.emplace("screenNativeBounds", RectToString(screen.nativeBounds)); info.emplace("screenNativeScale", std::to_string(screen.nativeScale)); } + if (userAgent) { + info.emplace("browserUserAgent", ToStdString(userAgent)); + } + Stats & instance = Stats::Instance(); instance.LogEvent("$iosDeviceInfo", info); @@ -372,6 +369,7 @@ bool IsConnectionActive() { // Calculate some basic statistics about installations/updates/launches. NSUserDefaults * userDataBase = [NSUserDefaults standardUserDefaults]; NSString * installedVersion = [userDataBase objectForKey:@"AlohalyticsInstalledVersion"]; + BOOL shouldSendUpdatedSystemInformation = NO; if (installationId.second && isFirstLaunch && installedVersion == nil) { // Documents folder modification time can be interpreted as a "first app launch time" or an approx. "app install time". // App bundle modification time can be interpreted as an "app update time". @@ -380,11 +378,7 @@ bool IsConnectionActive() { {"bundleTimestampMillis", PathTimestampMillis([bundle executablePath])}}); [userDataBase setValue:version forKey:@"AlohalyticsInstalledVersion"]; [userDataBase synchronize]; -#if (TARGET_OS_IPHONE > 0) - LogSystemInformation(); -#else - static_cast(options); // Unused variable warning fix. -#endif // TARGET_OS_IPHONE + shouldSendUpdatedSystemInformation = YES; } else { if (installedVersion == nil || ![installedVersion isEqualToString:version]) { instance.LogEvent("$update", {{"CFBundleShortVersionString", [version UTF8String]}, @@ -392,9 +386,7 @@ bool IsConnectionActive() { {"bundleTimestampMillis", PathTimestampMillis([bundle executablePath])}}); [userDataBase setValue:version forKey:@"AlohalyticsInstalledVersion"]; [userDataBase synchronize]; -#if (TARGET_OS_IPHONE > 0) - LogSystemInformation(); -#endif // TARGET_OS_IPHONE + shouldSendUpdatedSystemInformation = YES; } } instance.LogEvent("$launch" @@ -402,6 +394,17 @@ bool IsConnectionActive() { , ParseLaunchOptions(options) #endif // TARGET_OS_IPHONE ); +#if (TARGET_OS_IPHONE > 0) + // Initialize User-Agent asynchronously and log additional system info for iOS, as it takes significant time at startup. + dispatch_async(dispatch_get_main_queue(), ^{ + gBrowserUserAgent = [[[UIWebView alloc] initWithFrame:CGRectZero] stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; + if (shouldSendUpdatedSystemInformation) { + LogSystemInformation(gBrowserUserAgent); + } + }); +#else + static_cast(options); // Unused variable warning fix. +#endif // TARGET_OS_IPHONE } + (void)forceUpload { -- cgit v1.2.3