Merge pull request #4549 from igrechuhin/statistics

[ios] Updated initial statistics state to enabled.
This commit is contained in:
Sergey Yershov 2016-10-25 15:10:58 +03:00 committed by GitHub
commit 87ca29db2d
6 changed files with 37 additions and 78 deletions

@ -1 +1 @@
Subproject commit 6fc3b425c324855b3a8bfdce706bdb32b1947cee
Subproject commit a3e1659ba90ed079b3021ea2fa45a628a832b8e3

View file

@ -20,6 +20,7 @@
+ (void)setCompassCalibrationEnabled:(BOOL)compassCalibrationEnabled;
+ (BOOL)statisticsEnabled;
+ (void)setStatisticsEnabled:(BOOL)statisticsEnabled;
+ (BOOL)autoNightModeEnabled;
+ (void)setAutoNightModeEnabled:(BOOL)autoNightModeEnabled;

View file

@ -1,12 +1,12 @@
#import "MWMSettings.h"
#import "MWMMapViewControlsManager.h"
#import "3party/Alohalytics/src/alohalytics_objc.h"
#include "Framework.h"
#include "platform/settings.hpp"
extern char const * kStatisticsEnabledSettingsKey;
namespace
{
char const * kAdForbiddenSettingsKey = "AdForbidden";
@ -15,6 +15,7 @@ char const * kAutoDownloadEnabledKey = "AutoDownloadEnabled";
char const * kZoomButtonsEnabledKey = "ZoomButtonsEnabled";
char const * kCompassCalibrationEnabledKey = "CompassCalibrationEnabled";
char const * kRoutingDisclaimerApprovedKey = "IsDisclaimerApproved";
char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
NSString * const kUDAutoNightModeOff = @"AutoNightModeOff";
NSString * const kSpotlightLocaleLanguageId = @"SpotlightLocaleLanguageId";
@ -98,6 +99,20 @@ NSString * const kSpotlightLocaleLanguageId = @"SpotlightLocaleLanguageId";
return enabled;
}
+ (void)setStatisticsEnabled:(BOOL)statisticsEnabled
{
if (statisticsEnabled)
{
[Alohalytics enable];
}
else
{
[Alohalytics logEvent:@"statisticsDisabled"];
[Alohalytics disable];
}
settings::Set(kStatisticsEnabledSettingsKey, static_cast<bool>(statisticsEnabled));
}
+ (BOOL)autoNightModeEnabled
{
return ![[NSUserDefaults standardUserDefaults] boolForKey:kUDAutoNightModeOff];

View file

@ -191,10 +191,7 @@ extern NSString * const kAlohalyticsTapEventKey;
kStatAction : kStatToggleStatistics,
kStatValue : (value ? kStatOn : kStatOff)
}];
if (value)
[[Statistics instance] enableOnNextAppLaunch];
else
[[Statistics instance] disableOnNextAppLaunch];
[MWMSettings setStatisticsEnabled:value];
}
else if (cell == self.perspectiveViewCell)
{

View file

@ -1,10 +1,6 @@
#import "StatisticsStrings.h"
@interface Statistics : NSObject
+ (bool)isStatisticsEnabledByDefault;
- (bool)isStatisticsEnabled;
- (void)enableOnNextAppLaunch;
- (void)disableOnNextAppLaunch;
// Should be called from the same method in AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

View file

@ -1,6 +1,7 @@
#import "Statistics.h"
#import "AppInfo.h"
#import "MWMCustomFacebookEvents.h"
#import "Statistics.h"
#import "MWMSettings.h"
#import "3party/Alohalytics/src/alohalytics_objc.h"
#import "Flurry.h"
@ -10,78 +11,23 @@
#include "platform/settings.hpp"
#include "base/macros.hpp"
// If you have a "missing header error" here, then please run configure.sh script in the root repo folder.
#import "../../../private.h"
char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
@interface Statistics ()
{
bool _enabled;
}
@property (nonatomic) NSDate * lastLocationLogTimestamp;
@property(nonatomic) NSDate * lastLocationLogTimestamp;
@end
@implementation Statistics
+ (bool)isStatisticsEnabledByDefault
{
#ifdef OMIM_PRODUCTION
return true;
#else
// Make developer's life a little bit easier.
[Alohalytics setDebugMode:YES];
return false;
#endif
}
- (instancetype)init
{
if ((self = [super init]))
{
_enabled = [Statistics isStatisticsEnabledByDefault];
// Note by AlexZ:
// _enabled should be persistent across app's process lifecycle. That's why we change
// _enabled property only once - when the app is launched. In this case we don't need additional
// checks and specific initializations for different 3party engines, code is much cleaner and safer
// (actually, we don't have a choice - 3party SDKs do not guarantee correctness if not initialized
// in application:didFinishLaunchingWithOptions:).
// The (only) drawback of this approach is that to actually disable or enable 3party engines,
// the app should be restarted.
(void)settings::Get(kStatisticsEnabledSettingsKey, _enabled);
if (_enabled)
[Alohalytics enable];
else
[Alohalytics disable];
}
return self;
}
- (bool)isStatisticsEnabled
{
return _enabled;
}
- (void)enableOnNextAppLaunch
{
// This setting will be checked and applied on the next launch.
settings::Set(kStatisticsEnabledSettingsKey, true);
// It does not make sense to log statisticsEnabled with Alohalytics here,
// as it will not be stored and logged anyway.
}
- (void)disableOnNextAppLaunch
{
// This setting will be checked and applied on the next launch.
settings::Set(kStatisticsEnabledSettingsKey, false);
[Alohalytics logEvent:@"statisticsDisabled"];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// _enabled should be already correctly set up in init method.
if (_enabled)
if ([MWMSettings statisticsEnabled])
{
[Flurry startSession:@(FLURRY_KEY)];
[Flurry logAllPageViewsForTarget:application.windows.firstObject.rootViewController];
@ -101,7 +47,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
- (void)logLocation:(CLLocation *)location
{
if (!_enabled)
if (![MWMSettings statisticsEnabled])
return;
if (!_lastLocationLogTimestamp || [[NSDate date] timeIntervalSinceDate:_lastLocationLogTimestamp] > (60 * 60 * 3))
{
@ -113,7 +59,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
- (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters
{
if (!_enabled)
if (![MWMSettings statisticsEnabled])
return;
NSMutableDictionary * params = [self addDefaultAttributesToParameters:parameters];
[Flurry logEvent:eventName withParameters:params];
@ -122,7 +68,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
- (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters atLocation:(CLLocation *)location
{
if (!_enabled)
if (![MWMSettings statisticsEnabled])
return;
NSMutableDictionary * params = [self addDefaultAttributesToParameters:parameters];
[Alohalytics logEvent:eventName withDictionary:params atLocation:location];
@ -152,7 +98,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
- (void)logApiUsage:(NSString *)programName
{
if (!_enabled)
if (![MWMSettings statisticsEnabled])
return;
if (programName)
[self logEvent:@"Api Usage" withParameters: @{@"Application Name" : programName}];
@ -162,7 +108,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
- (void)applicationDidBecomeActive
{
if (!_enabled)
if (![MWMSettings statisticsEnabled])
return;
[FBSDKAppEvents activateApp];
// Special FB events to improve marketing campaigns quality.
@ -176,6 +122,10 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
dispatch_once(&onceToken, ^
{
instance = [[Statistics alloc] init];
if ([MWMSettings statisticsEnabled])
[Alohalytics enable];
else
[Alohalytics disable];
});
return instance;
}