forked from twobitlabs/AnalyticsKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalyticsKitApsalarProvider.m
102 lines (81 loc) · 3.36 KB
/
AnalyticsKitApsalarProvider.m
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
93
94
95
96
97
98
99
100
101
102
//
// AnalyticsKitApsalarProvider.m
// TeamStream
//
// Created by Susan Detwiler on 1/26/12.
// Copyright (c) 2012 Two Bit Labs. All rights reserved.
//
#import "AnalyticsKitApsalarProvider.h"
#import "Apsalar.h"
@implementation AnalyticsKitApsalarProvider
@synthesize apiKey = _apiKey;
@synthesize secret = _secret;
-(id<AnalyticsKitProvider>)initWithAPIKey:(NSString *)apiKey andSecret:(NSString *)apsalarSecret andLaunchOptions:(NSDictionary *)options{
self = [super init];
if (self) {
[Apsalar startSession:apiKey withKey:apsalarSecret andLaunchOptions:options];
self.apiKey = apiKey;
self.secret = apsalarSecret;
}
return self;
}
#pragma mark -
#pragma mark Lifecycle
-(void)applicationWillEnterForeground{
[Apsalar reStartSession:self.apiKey withKey:self.secret];
}
-(void)applicationDidEnterBackground{
[Apsalar endSession];
}
-(void)applicationWillTerminate {
[Apsalar endSession];
self.apiKey = nil;
self.secret = nil;
}
-(void)uncaughtException:(NSException *)exception{
NSString *message = [NSString stringWithFormat:@"Crash on iOS %@", [[UIDevice currentDevice] systemVersion]];
[self logError:@"Uncaught Exception" message:message exception:exception];
}
#pragma mark -
#pragma mark Event Logging
-(void)logScreen:(NSString *)screenName{
[Apsalar event:[@"Screen - " stringByAppendingString:screenName]];
}
-(void)logEvent:(NSString *)value {
[Apsalar event:value];
}
-(void)logEvent:(NSString *)event withProperty:(NSString *)key andValue:(NSString *)value {
[Apsalar eventWithArgs: event, key, value, nil];
}
-(void)logEvent:(NSString *)event withProperties:(NSDictionary *)dict {
[Apsalar event:event withArgs:dict];
}
//Apsalar doesn't do timed events, so just log as a regular event
-(void)logEvent:(NSString *)eventName timed:(BOOL)timed{
[Apsalar event:eventName];
}
-(void)logEvent:(NSString *)eventName withProperties:(NSDictionary *)dict timed:(BOOL)timed{
[Apsalar event:eventName withArgs:dict];
}
//this is a no-op as Apsalar doesn't do timed events
-(void)endTimedEvent:(NSString *)eventName withProperties:(NSDictionary *)dict{}
-(void)logError:(NSString *)name message:(NSString *)message exception:(NSException *)exception{
[Apsalar event:@"Exceptions" withArgs:[NSDictionary dictionaryWithObjectsAndKeys:
name, @"name",
message, @"message",
[exception name], @"ename",
[exception reason], @"reason",
[exception userInfo], @"userInfo",
nil]];
}
-(void)logError:(NSString *)name message:(NSString *)message error:(NSError *)error{
[Apsalar event:@"Errors" withArgs:[NSDictionary dictionaryWithObjectsAndKeys:
name, @"name",
message, @"message",
[error localizedDescription], @"description",
[NSString stringWithFormat:@"%d", [error code]], @"code",
[error domain], @"domain",
[[error userInfo] description], @"userInfo",
nil]];
}
@end