Skip to content

Instantly share code, notes, and snippets.

@mgdombrowski
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgdombrowski/9a91711df2317dcf0cfb to your computer and use it in GitHub Desktop.
Save mgdombrowski/9a91711df2317dcf0cfb to your computer and use it in GitHub Desktop.
track view duration and upload as a Localytics event attribute for charting
#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