Streamline analytics properties.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 8d796cc26a
commit 013bf62f7c

@ -795,7 +795,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[DeviceSleepManager.sharedInstance removeBlockWithBlockObject:self];
[OWSAnalytics appLaunchDidComplete];
[AppVersion.instance appLaunchDidComplete];
[self ensureRootViewController];

@ -38,8 +38,6 @@ typedef NS_ENUM(NSUInteger, OWSAnalyticsSeverity) {
+ (void)appLaunchDidBegin;
+ (void)appLaunchDidComplete;
+ (long)orderOfMagnitudeOf:(long)value;
@end

@ -3,20 +3,14 @@
//
#import "OWSAnalytics.h"
#import "AppVersion.h"
#import "OWSQueues.h"
#import "TSStorageManager.h"
#import <CocoaLumberjack/CocoaLumberjack.h>
#import <Reachability/Reachability.h>
#include <sys/sysctl.h>
NS_ASSUME_NONNULL_BEGIN
#if TARGET_IPHONE_SIMULATOR
#define NO_SIGNAL_ANALYTICS
#else
#ifdef DEBUG
// TODO: Disable analytics for debug builds.
@ -24,14 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
#endif
#endif
NSString *const kOWSAnalytics_EventsCollection = @"kOWSAnalytics_EventsCollection";
NSString *const kOWSAnalytics_Collection = @"kOWSAnalytics_Collection";
NSString *const kOWSAnalytics_KeyLaunchCount = @"kOWSAnalytics_KeyLaunchCount";
NSString *const kOWSAnalytics_KeyLaunchCompleteCount = @"kOWSAnalytics_KeyLaunchCompleteCount";
// Percentage of analytics events to discard. 0 <= x <= 100.
const int kOWSAnalytics_DiscardFrequency = 0;
@ -54,9 +42,6 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
@property (atomic) BOOL hasRequestInFlight;
@property (atomic) NSNumber *launchCount;
@property (atomic) NSNumber *launchCompleteCount;
@end
#pragma mark -
@ -276,25 +261,46 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
return queue;
}
- (NSDictionary<NSString *, id> *)eventSuperProperties
- (NSString *)operatingSystemVersionString
{
NSMutableDictionary<NSString *, id> *result = [NSMutableDictionary new];
if (AppVersion.instance.firstAppVersion) {
result[@"app_version_first"] = AppVersion.instance.firstAppVersion;
}
if (AppVersion.instance.lastAppVersion) {
result[@"app_version_last"] = AppVersion.instance.lastAppVersion;
}
if (AppVersion.instance.currentAppVersion) {
result[@"app_version_current"] = AppVersion.instance.currentAppVersion;
static NSString *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSOperatingSystemVersion operatingSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
result = [NSString stringWithFormat:@"%zd.%zd.%zd",
operatingSystemVersion.majorVersion,
operatingSystemVersion.minorVersion,
operatingSystemVersion.patchVersion];
});
return result;
}
NSNumber *launchCount = self.launchCount;
if (launchCount) {
result[@"launch_count"] = @([self orderOfMagnitudeOf:launchCount.longValue]);
- (NSString *)deviceHardwareModel
{
static NSString *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
size_t size;
char *kHwModel = "hw.model";
sysctlbyname(kHwModel, NULL, &size, NULL, 0);
char *answer = malloc(size);
sysctlbyname(kHwModel, answer, &size, NULL, 0);
result = [NSString stringWithCString:answer encoding:NSUTF8StringEncoding];
free(answer);
});
return result;
}
// TODO: Order of magnitude: thread count.
// TODO: Order of magnitude: total message count.
- (NSDictionary<NSString *, id> *)eventSuperProperties
{
NSMutableDictionary<NSString *, id> *result = [NSMutableDictionary new];
result[@"app_version"] = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
result[@"platform"] = @"ios";
result[@"ios_version"] = self.operatingSystemVersionString;
result[@"device_model"] = self.deviceHardwareModel;
return result;
}
@ -426,42 +432,6 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
- (void)appLaunchDidBegin
{
OWSProdInfo(@"app_launch");
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
NSNumber *oldLaunchCount =
[transaction objectForKey:kOWSAnalytics_KeyLaunchCount inCollection:kOWSAnalytics_Collection];
NSNumber *newLaunchCount = @(oldLaunchCount.longValue + 1);
self.launchCount = newLaunchCount;
NSNumber *oldLaunchCompleteCount =
[transaction objectForKey:kOWSAnalytics_KeyLaunchCompleteCount inCollection:kOWSAnalytics_Collection];
self.launchCompleteCount = @(oldLaunchCompleteCount.longValue);
}];
[self.dbConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[transaction setObject:self.launchCount
forKey:kOWSAnalytics_KeyLaunchCount
inCollection:kOWSAnalytics_Collection];
}];
}
+ (void)appLaunchDidComplete
{
[self.sharedInstance appLaunchDidComplete];
}
- (void)appLaunchDidComplete
{
OWSProdInfo(@"app_launch_complete");
self.launchCompleteCount = @(self.launchCompleteCount.longValue + 1);
[self.dbConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[transaction setObject:self.launchCompleteCount
forKey:kOWSAnalytics_KeyLaunchCompleteCount
inCollection:kOWSAnalytics_Collection];
}];
}
#pragma mark - Logging

Loading…
Cancel
Save