Permalink
Browse files

session timing example

  • Loading branch information...
1 parent a57d822 commit 3d4202ed8692646ae15d43a4363ddbc1e8bcfdfe @neilrahilly neilrahilly committed Oct 18, 2012
Showing with 20 additions and 2 deletions.
  1. +2 −0 HelloMixpanel/HelloMixpanel/AppDelegate.h
  2. +18 −2 HelloMixpanel/HelloMixpanel/AppDelegate.m
@@ -29,4 +29,6 @@
@property (strong, nonatomic) Mixpanel *mixpanel;
+@property (strong, nonatomic, retain) NSDate *startTime;
+
@end
@@ -29,6 +29,7 @@ @implementation AppDelegate
- (void)dealloc
{
+ [_startTime release];
[_window release];
[_viewController release];
[super dealloc];
@@ -43,8 +44,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Initialize the MixpanelAPI object
self.mixpanel = [Mixpanel sharedInstanceWithToken:MIXPANEL_TOKEN];
- // Set the upload interval to 5 seconds for demonstration purposes. This would be overkill for most applications.
- self.mixpanel.flushInterval = 5; // defaults to 60 seconds
+ // Set the upload interval to 10 seconds for demonstration purposes. This would be overkill for most applications.
+ self.mixpanel.flushInterval = 10; // defaults to 60 seconds
// Name a user in Mixpanel Streams
self.mixpanel.nameTag = @"Walter Sobchak";
@@ -61,6 +62,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}
+#pragma mark * Push notifications
+
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
[self.mixpanel.people addPushDeviceToken:devToken];
}
@@ -82,4 +85,17 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
[alert release];
}
+#pragma mark * Session timing example
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ self.startTime = [NSDate date];
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ NSNumber *seconds = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSinceDate:self.startTime]];
+ [[Mixpanel sharedInstance] track:@"Session" properties:[NSDictionary dictionaryWithObject:seconds forKey:@"Length"]];
+}
+
@end

0 comments on commit 3d4202e

Please sign in to comment.