-
Notifications
You must be signed in to change notification settings - Fork 565
/
AppDelegate.m
executable file
·63 lines (46 loc) · 2.22 KB
/
AppDelegate.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
//
// AppDelegate.m
// tvOS_Example
//
// Created by Yarden Eitan on 5/31/16.
// Copyright © 2016 Mixpanel. All rights reserved.
//
@import Mixpanel;
#import "AppDelegate.h"
// IMPORTANT!!! replace with your api token from https://mixpanel.com/account/
#define MIXPANEL_TOKEN @"6e8cf49a783398b5768f24f105a95fb5"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.mixpanel = [Mixpanel sharedInstanceWithToken:MIXPANEL_TOKEN launchOptions:nil];
self.mixpanel.flushInterval = 20; // defaults to 60 seconds
// Set some super properties, which will be added to every tracked event
[self.mixpanel registerSuperProperties:@{@"Plan": @"Premium"}];
// Name a user in Mixpanel Streams
self.mixpanel.nameTag = @"Walter Sobchak";
// Start timing the session, then we'll have a duration when the user leaves the app
[self.mixpanel timeEvent:@"Session"];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
[self.mixpanel track:@"Session"];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"%@ background task %lu cut short", self, (unsigned long)self.bgTask);
[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"%@ starting background task %lu", self, (unsigned long)self.bgTask);
// track some events and set some people properties
Mixpanel *mixpanel = [Mixpanel sharedInstance];
[mixpanel registerSuperProperties:@{@"Background Super Property": @"Hi!"}];
[mixpanel track:@"Background Event"];
[mixpanel.people set:@"Entered Background" to:[NSDate date]];
NSLog(@"%@ ending background task %lu", self, (unsigned long)self.bgTask);
[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
});
NSLog(@"%@ dispatched background task %lu", self, (unsigned long)self.bgTask);
}
@end