Last active
August 29, 2015 14:05
-
-
Save mgdombrowski/9a91711df2317dcf0cfb to your computer and use it in GitHub Desktop.
track view duration and upload as a Localytics event attribute for charting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "XYZViewController.h" | |
#import "LocalyticsSession.h" | |
@interface XYZViewController () | |
@end | |
@implementation XYZViewController | |
static NSDate *startOfOverallTime; | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
{ | |
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
if (self) { | |
// Custom initialization | |
} | |
return self; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
} | |
- (void)viewDidAppear:(BOOL)animated | |
{ | |
[super viewDidAppear:animated]; | |
//Localytics screen tag | |
[[LocalyticsSession shared] tagScreen:@"XYZ screen"]; | |
//start duration | |
startOfOverallTime = [[NSDate date] retain]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)viewDidDisappear:(BOOL)animated { | |
[super viewDidDisappear:(BOOL)animated]; | |
//duration calculation | |
NSString *duration; | |
NSDate *endOfOverallTime = [NSDate date]; | |
NSTimeInterval overallTimeTaken = [endOfOverallTime timeIntervalSinceDate:startOfOverallTime]; | |
[startOfOverallTime release]; | |
//add duration to attributes dictionary | |
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: | |
overallTimeTaken, | |
@"Duration", | |
nil]; | |
//upload as attribute to Localytics | |
[[LocalyticsSession shared] tagEvent:@"XYZ Screen Summary" attributes:dictionary]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment