Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Statistics.mm « Statistics « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b2311b3f495f52ae8eb236ea697b6fff423a565f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#import "Statistics.h"
#import "Flurry.h"
#import "AppInfo.h"

#import "3party/Alohalytics/src/alohalytics_objc.h"

#include "platform/settings.hpp"

static constexpr char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";

@implementation Statistics

- (void)startSessionWithLaunchOptions:(NSDictionary *)launchOptions
{
  if (self.enabled)
  {
    [Flurry startSession:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlurryKey"]];
    [Flurry setSessionReportsOnPauseEnabled:NO];
  }
}

- (void)logLocation:(CLLocation *)location
{
  if (self.enabled)
  {
    static NSDate * lastUpdate;
    if (!lastUpdate || [[NSDate date] timeIntervalSinceDate:lastUpdate] > (60 * 60 * 3))
    {
      lastUpdate = [NSDate date];
      CLLocationCoordinate2D const coord = location.coordinate;
      [Flurry setLatitude:coord.latitude longitude:coord.longitude horizontalAccuracy:location.horizontalAccuracy verticalAccuracy:location.verticalAccuracy];
    }
  }
}

- (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters
{
  if (self.enabled)
    [Flurry logEvent:eventName withParameters:parameters];
}

- (void)logEvent:(NSString *)eventName
{
  [self logEvent:eventName withParameters:nil];
}

- (void)logInAppMessageEvent:(NSString *)eventName imageType:(NSString *)imageType
{
  NSString * language = [[NSLocale preferredLanguages] firstObject];
  AppInfo * info = [AppInfo sharedInfo];
  [self logEvent:eventName withParameters:@{@"Type": imageType, @"Country" : info.countryCode, @"Language" : language, @"Id" : info.uniqueId}];
}

- (void)logApiUsage:(NSString *)programName
{
  if (programName)
    [self logEvent:@"Api Usage" withParameters: @{@"Application Name" : programName}];
  else
    [self logEvent:@"Api Usage" withParameters: @{@"Application Name" : @"Error passing nil as SourceApp name."}];
}

- (BOOL)enabled
{
#ifdef DEBUG
  bool statisticsEnabled = false;
#else
  bool statisticsEnabled = true;
#endif
  (void)Settings::Get(kStatisticsEnabledSettingsKey, statisticsEnabled);
  return statisticsEnabled;
}

- (void)setEnabled:(BOOL)enabled
{
  Settings::Set(kStatisticsEnabledSettingsKey, static_cast<bool>(enabled));
  if (enabled)
    [Alohalytics enable];
  else
    [Alohalytics disable];
}

+ (instancetype)instance
{
  static Statistics * instance;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    instance = [[Statistics alloc] init];
  });
  return instance;
}

@end