Skip to content
Browse files

Added ApSalar support

  • Loading branch information...
1 parent f695398 commit 8c3020bb636d133a0c55444d34bce59888b8078b @sherpachick sherpachick committed Jan 30, 2012
Showing with 191 additions and 22 deletions.
  1. +14 −0 AnalyticsKit.h
  2. +13 −13 AnalyticsKit.m
  3. +18 −0 AnalyticsKitApsalarProvider.h
  4. +102 −0 AnalyticsKitApsalarProvider.m
  5. +1 −1 AnalyticsKitFlurryProvider.m
  6. +1 −5 AnalyticsKitLocalyitcsProvider.m
  7. +42 −3 README.md
View
14 AnalyticsKit.h
@@ -8,6 +8,19 @@
#import <Foundation/Foundation.h>
+#pragma mark -
+#pragma mark Macros - Logging
+
+#define AKLOG(fmt, ...) NSLog(@"%s:%d (%s): " fmt, __FILE__, __LINE__, __func__, ## __VA_ARGS__)
+#ifdef DEBUG
+#define AKINFO(fmt, ...) AKLOG(fmt, ## __VA_ARGS__)
+#else
+// do nothing
+#define AKINFO(fmt, ...)
+#endif
+
+#define AKERROR(fmt, ...) AKLOG(fmt, ## __VA_ARGS__)
+
@protocol AnalyticsKitProvider <NSObject>
// Lifecycle
@@ -16,6 +29,7 @@
-(void)applicationWillTerminate;
-(void)uncaughtException:(NSException *)exception;
+//Logging events
-(void)logScreen:(NSString *)screenName;
-(void)logEvent:(NSString *)value;
-(void)logEvent:(NSString *)event withProperty:(NSString *)key andValue:(NSString *)value;
View
26 AnalyticsKit.m
@@ -21,93 +21,93 @@ +(void)initializeLoggers:(NSArray *)loggers {
}
+(void)applicationWillEnterForeground {
- INFO(@"");
+ AKINFO(@"");
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger applicationWillEnterForeground];
}
}
+(void)applicationDidEnterBackground {
- INFO(@"");
+ AKINFO(@"");
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger applicationDidEnterBackground];
}
}
+(void)applicationWillTerminate {
- INFO(@"");
+ AKINFO(@"");
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger applicationWillTerminate];
}
}
+(void)uncaughtException:(NSException *)exception {
- INFO(@"");
+ AKINFO(@"");
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger uncaughtException:exception];
}
}
+(void)logScreen:(NSString *)screenName {
- INFO(@"%@", screenName);
+ AKINFO(@"%@", screenName);
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logScreen:screenName];
}
}
+(void)logEvent:(NSString *)event {
- INFO(@"%@", event);
+ AKINFO(@"%@", event);
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logEvent:event];
}
}
+(void)logEvent:(NSString *)event withProperties:(NSDictionary *)dict {
- INFO(@"%@ withProperties: %@", event, dict);
+ AKINFO(@"%@ withProperties: %@", event, dict);
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logEvent:event withProperties:dict];
}
}
+(void)logEvent:(NSString *)event withProperty:(NSString *)property andValue:(NSString *)value {
- INFO(@"%@ withProperty: %@ andValue: %@", event, property, value);
+ AKINFO(@"%@ withProperty: %@ andValue: %@", event, property, value);
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logEvent:event withProperty:property andValue:value];
}
}
+(void)logEvent:(NSString *)eventName timed:(BOOL)timed{
- INFO(@"%@ timed: %@", eventName, timed ? @"YES" : @"NO");
+ AKINFO(@"%@ timed: %@", eventName, timed ? @"YES" : @"NO");
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logEvent:eventName timed:timed];
}
}
+(void)logEvent:(NSString *)eventName withProperties:(NSDictionary *)dict timed:(BOOL)timed{
- INFO(@"%@ withProperties: %@ timed: %@", eventName, dict, timed ? @"YES" : @"NO");
+ AKINFO(@"%@ withProperties: %@ timed: %@", eventName, dict, timed ? @"YES" : @"NO");
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logEvent:eventName withProperties:dict timed:timed];
}
}
+(void)endTimedEvent:(NSString *)eventName withProperties:(NSDictionary *)dict{
- INFO(@"%@ withProperties: %@ ended", eventName, dict);
+ AKINFO(@"%@ withProperties: %@ ended", eventName, dict);
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger endTimedEvent:eventName withProperties:dict];
}
}
+(void)logError:(NSString *)name message:(NSString *)message exception:(NSException *)exception {
- ERROR(@"%@: %@", name, message);
+ AKERROR(@"%@: %@", name, message);
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logError:name message:message exception:exception];
}
}
+(void)logError:(NSString *)name message:(NSString *)message error:(NSError *)error {
- ERROR(@"%@: %@", name, message);
+ AKERROR(@"%@: %@", name, message);
for (id<AnalyticsKitProvider> logger in _loggers) {
[logger logError:name message:message error:error];
}
View
18 AnalyticsKitApsalarProvider.h
@@ -0,0 +1,18 @@
+//
+// AnalyticsKitApsalarProvider.h
+// TeamStream
+//
+// Created by Susan Detwiler on 1/26/12.
+// Copyright (c) 2012 Bleacher Report. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface AnalyticsKitApsalarProvider : NSObject <AnalyticsKitProvider>
+
+@property(retain)NSString *apiKey;
+@property(retain)NSString *secret;
+
+-(id<AnalyticsKitProvider>)initWithAPIKey:(NSString *)apiKey andSecret:(NSString *)apsalarSecret andLaunchOptions:(NSDictionary *)options;
+
+@end
View
102 AnalyticsKitApsalarProvider.m
@@ -0,0 +1,102 @@
+//
+// AnalyticsKitApsalarProvider.m
+// TeamStream
+//
+// Created by Susan Detwiler on 1/26/12.
+// Copyright (c) 2012 Bleacher Report. 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
View
2 AnalyticsKitFlurryProvider.m
@@ -14,7 +14,7 @@ @implementation AnalyticsKitFlurryProvider
-(id<AnalyticsKitProvider>)initWithAPIKey:(NSString *)apiKey {
self = [super init];
if (self) {
- [FlurryAnalytics startSession:(NSString *)apiKey];
+ [FlurryAnalytics startSession:apiKey];
}
return self;
}
View
6 AnalyticsKitLocalyitcsProvider.m
@@ -20,25 +20,21 @@ @implementation AnalyticsKitLocalyitcsProvider
}
-(void)applicationWillEnterForeground {
- INFO(@"");
[[LocalyticsSession sharedLocalyticsSession] resume];
[[LocalyticsSession sharedLocalyticsSession] upload];
}
-(void)applicationDidEnterBackground {
- INFO(@"");
[[LocalyticsSession sharedLocalyticsSession] close];
[[LocalyticsSession sharedLocalyticsSession] upload];
}
--(void)applicationWillTerminate {
- INFO(@"");
+-(void)applicationWillTerminate {
[[LocalyticsSession sharedLocalyticsSession] close];
[[LocalyticsSession sharedLocalyticsSession] upload];
}
-(void)uncaughtException:(NSException *)exception {
- INFO(@"%@", exception);
[[LocalyticsSession sharedLocalyticsSession] tagEvent:@"Uncaught Exceptions" attributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[exception name], @"ename",
View
45 README.md
@@ -5,12 +5,51 @@ INTRODUCTION
The goal of AnalyticsKit is to provide a consistent API for analytics
regardless of which analytics provider you're using behind the scenes.
-USAGE
-=====
-TODO
+The benefit of using AnalyticsKit is that if you decide to start using a new
+analytics provider, or add an additional one, you need to write/change much less code!
+
INCLUDED PROVIDERS
==================
TestFlight
Localytics
Flurry
+Apsalar
+
+
+USAGE
+=====
+1. Download the provider's SDK and add it to your project
+
+2. In your AppDelegate's applicationDidFinishLaunchingWithOptions (or in a method called from there), create an AnalyticsKit*Provider (where * is the provider); add it to your loggers array; and call initializeLoggers
+
+/******* SAMPLE CODE
+ // Create the AnalyticsKitApsalarProvider
+ NSString *apsalarKey = @"myAPIKey";
+ NSString *apsalarSecret = @"mySecret";
+
+//if you don't want your simulator activity to be logged, use bogus keys
+#if (TARGET_IPHONE_SIMULATOR)
+ apsalarKey = @"XXXXXXXXXXXXXXXXXXXX";
+ apsalarSecret = @"XXXXXXXXXXXXXXXXXXXX";
+#endif
+
+ NSMutableArray *loggers = [[NSMutableArray arrayWithObject:[[[AnalyticsKitApsalarProvider alloc] initWithAPIKey:apsalarKey andSecret:apsalarSecret andLaunchOptions:launchOptions] autorelease]] retain];
+
+//if you are using more than one analytics provider, create as many AnalyticsKit*Providers as you need,
+//and add them to loggers array
+
+ //initialize AnalyticsKit to send messages to Flurry and TestFlight
+ [AnalyticsKit initializeLoggers:loggers];
+
+**************/
+
+3. Where significant events occur, call AnalyticsKit logEvent: or other appropriate method. Example:
+ [AnalyticsKit logEvent:@"Notifications - Displaying Webview For Notification" withProperties:eventDict];
+
+4. You may also want to make AnalyticsKit calls at application lifecycle events, such as applicationDidEnterBackground, applicationWillTerminate, applicationWillEnterForeground
+
+----> SEE ANALYTICSKIT.H for an overview of the methods available. Doublecheck that the methods you call are implemented in the AnalyticsKit*Provider.m that you are using!
+
+
+

0 comments on commit 8c3020b

Please sign in to comment.
Something went wrong with that request. Please try again.