diff --git a/3party/Alohalytics/src/alohalytics_objc.h b/3party/Alohalytics/src/alohalytics_objc.h index 3b026c7eae..5396471b5b 100644 --- a/3party/Alohalytics/src/alohalytics_objc.h +++ b/3party/Alohalytics/src/alohalytics_objc.h @@ -32,8 +32,8 @@ @interface Alohalytics : NSObject + (void)setDebugMode:(BOOL)enable; -// Should be called in application:didFinishLaunchingWithOptions: -// or in application:willFinishLaunchingWithOptions: +// Should be called in application:didFinishLaunchingWithOptions: or in application:willFinishLaunchingWithOptions: +// Final serverUrl is modified to $(serverUrl)/[ios|mac]/your.bundle.id/app.version + (void)setup:(NSString *)serverUrl withLaunchOptions:(NSDictionary *)options; // Alternative to the previous setup method if you integrated Alohalytics after initial release // and don't want to count app upgrades as new installs (and definitely know that it's an already existing user). diff --git a/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java b/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java index df3326bd97..019d5619b3 100644 --- a/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java +++ b/3party/Alohalytics/src/android/java/org/alohalytics/Statistics.java @@ -51,16 +51,16 @@ public class Statistics { return sDebugModeEnabled; } - public static void setup(final String serverUrl, final Context context) { + // Passed serverUrl will be modified to $(serverUrl)/android/packageName/versionCode + public static void setup(String serverUrl, final Context context) { final String storagePath = context.getFilesDir().getAbsolutePath() + "/Alohalytics/"; // Native code expects valid existing writable dir. (new File(storagePath)).mkdirs(); final Pair id = getInstallationId(context); - setupCPP(HttpTransport.class, serverUrl, storagePath, id.first); - // Calculate some basic statistics about installations/updates/launches. - String versionName = "", packageName = ""; + String versionName = "0", packageName = "0"; long installTime = 0, updateTime = 0; + int versionCode = 0; try { final android.content.pm.PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); if (packageInfo != null) { @@ -68,10 +68,17 @@ public class Statistics { versionName = packageInfo.versionName; installTime = packageInfo.firstInstallTime; updateTime = packageInfo.lastUpdateTime; + versionCode = packageInfo.versionCode; } } catch (android.content.pm.PackageManager.NameNotFoundException ex) { ex.printStackTrace(); } + // Take into an account trailing slash in the url. + serverUrl = serverUrl + (serverUrl.lastIndexOf('/') == serverUrl.length() - 1 ? "" : "/") + "android/" + packageName + "/" + versionCode; + // Initialize core C++ module before logging events. + setupCPP(HttpTransport.class, serverUrl, storagePath, id.first); + + // Calculate some basic statistics about installations/updates/launches. final SharedPreferences prefs = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); Location lastKnownLocation = null; if (SystemInfo.hasPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, context)) { diff --git a/3party/Alohalytics/src/apple/alohalytics_objc.mm b/3party/Alohalytics/src/apple/alohalytics_objc.mm index 7a847db190..23356d4096 100644 --- a/3party/Alohalytics/src/apple/alohalytics_objc.mm +++ b/3party/Alohalytics/src/apple/alohalytics_objc.mm @@ -333,9 +333,23 @@ bool IsConnectionActive() { } + (void)setup:(NSString *)serverUrl andFirstLaunch:(BOOL)isFirstLaunch withLaunchOptions:(NSDictionary *)options { + const NSBundle * bundle = [NSBundle mainBundle]; + NSString * bundleIdentifier = [bundle bundleIdentifier]; + NSString * version = [[bundle infoDictionary] objectForKey:@"CFBundleShortVersionString"]; + // Remove trailing slash in the url if it's present. + const NSInteger indexOfLastChar = serverUrl.length - 1; + if ([serverUrl characterAtIndex:indexOfLastChar] == '/') { + serverUrl = [serverUrl substringToIndex:indexOfLastChar]; + } + // Final serverUrl is modified to $(serverUrl)/[ios|mac]/your.bundle.id/app.version +#if (TARGET_OS_IPHONE > 0) + serverUrl = [serverUrl stringByAppendingFormat:@"/ios/%@/%@", bundleIdentifier, version]; +#else + serverUrl = [serverUrl stringByAppendingFormat:@"/mac/%@/%@", bundleIdentifier, version]; +#endif #if (TARGET_OS_IPHONE > 0) // Initialize User Agent later, as it takes significant time at startup. - dispatch_async(dispatch_get_main_queue(), ^(void) { + dispatch_async(dispatch_get_main_queue(), ^{ gBrowserUserAgent = [[[UIWebView alloc] initWithFrame:CGRectZero] stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; if (gBrowserUserAgent) { Stats::Instance().LogEvent("$browserUserAgent", ToStdString(gBrowserUserAgent)); @@ -358,9 +372,7 @@ bool IsConnectionActive() { // Calculate some basic statistics about installations/updates/launches. NSUserDefaults * userDataBase = [NSUserDefaults standardUserDefaults]; NSString * installedVersion = [userDataBase objectForKey:@"AlohalyticsInstalledVersion"]; - NSBundle * bundle = [NSBundle mainBundle]; if (installationId.second && isFirstLaunch && installedVersion == nil) { - NSString * version = [[bundle infoDictionary] objectForKey:@"CFBundleShortVersionString"]; // 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". instance.LogEvent("$install", {{"CFBundleShortVersionString", [version UTF8String]}, @@ -374,7 +386,6 @@ bool IsConnectionActive() { static_cast(options); // Unused variable warning fix. #endif // TARGET_OS_IPHONE } else { - NSString * version = [[bundle infoDictionary] objectForKey:@"CFBundleShortVersionString"]; if (installedVersion == nil || ![installedVersion isEqualToString:version]) { instance.LogEvent("$update", {{"CFBundleShortVersionString", [version UTF8String]}, {"documentsTimestampMillis", PathTimestampMillis([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject])}, diff --git a/android/build.gradle b/android/build.gradle index 0d54f9f3e0..ea3fcf2b48 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -224,7 +224,6 @@ android { jniDebuggable true // Enable jni debug build zipAlignEnabled true android.sourceSets.debug.setRoot('flavors/debug') - buildConfigField 'String', 'STATISTICS_URL', propStatisticsDevelopmentUrl } release { @@ -239,7 +238,6 @@ android { versionNameSuffix '-beta' signingConfig signingConfigs.mapswithme android.sourceSets.beta.setRoot('flavors/beta') - buildConfigField 'String', 'STATISTICS_URL', propStatisticsDevelopmentUrl } } diff --git a/android/gradle.properties b/android/gradle.properties index a32d39f096..2965b42cb9 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -6,5 +6,4 @@ propVersionName=4.4.1 propDebugNdkFlags=V=1 NDK_DEBUG=1 DEBUG=1 propReleaseNdkFlags=V=1 NDK_DEBUG=0 PRODUCTION=1 -propStatisticsUrl="http://localhost:8080/4" -propStatisticsDevelopmentUrl="http://localhost:8080/dev" +propStatisticsUrl="http://localhost:8080" diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 4e719001f9..3898e68bc2 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -154,10 +154,8 @@ void InitLocalizedStrings() // Initialize Alohalytics statistics engine. #ifndef OMIM_PRODUCTION [Alohalytics setDebugMode:YES]; - NSString * serverUrl = @"http://localhost:8080/dev"; -#else - NSString * serverUrl = @"http://localhost:8080/4"; #endif + [Alohalytics setup:@"http://localhost:8080" andFirstLaunch:[MapsAppDelegate isFirstAppLaunch] withLaunchOptions:launchOptions]; NSURL *url = launchOptions[UIApplicationLaunchOptionsURLKey]; if (url != nil) @@ -165,8 +163,6 @@ void InitLocalizedStrings() [HttpThread setDownloadIndicatorProtocol:[MapsAppDelegate theApp]]; - [Alohalytics setup:serverUrl andFirstLaunch:[MapsAppDelegate isFirstAppLaunch] withLaunchOptions:launchOptions]; - [[Statistics instance] startSessionWithLaunchOptions:launchOptions]; [self trackWatchUser];