forked from organicmaps/organicmaps
[alohalytics] Use unique statistic urls for each bundle name and app version.
This commit is contained in:
parent
94d6fa8fe0
commit
4a67563188
6 changed files with 30 additions and 19 deletions
|
@ -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).
|
||||
|
|
|
@ -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<String, Boolean> 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)) {
|
||||
|
|
|
@ -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<void>(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])},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Add table
Reference in a new issue