Skip to content

Commit

Permalink
session timing example
Browse files Browse the repository at this point in the history
  • Loading branch information
neilrahilly committed Oct 18, 2012
1 parent a57d822 commit 3d4202e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HelloMixpanel/HelloMixpanel/AppDelegate.h
Expand Up @@ -29,4 +29,6 @@

@property (strong, nonatomic) Mixpanel *mixpanel;

@property (strong, nonatomic, retain) NSDate *startTime;

@end
20 changes: 18 additions & 2 deletions HelloMixpanel/HelloMixpanel/AppDelegate.m
Expand Up @@ -29,6 +29,7 @@ @implementation AppDelegate

- (void)dealloc
{
[_startTime release];
[_window release];
[_viewController release];
[super dealloc];
Expand All @@ -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";
Expand All @@ -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];
}
Expand All @@ -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.