Skip to content

Instantly share code, notes, and snippets.

@willrust
Last active August 29, 2015 14:03
Show Gist options
  • Save willrust/1a6f819147e9d2a1c470 to your computer and use it in GitHub Desktop.
Save willrust/1a6f819147e9d2a1c470 to your computer and use it in GitHub Desktop.
Recording view duration as a property in KISSmetrics iOS SDK v2
//In your ViewControllers: (Replace "someViewDuration" with an appropriate name for each view)
NSTimeInterval appearedAtTime;
- (void)viewWillAppear:(BOOL)animated {
appearedAtTime = [[NSDate date] timeIntervalSince1970];
}
- (void)viewWillDisappear:(BOOL)animated {
int duration = (int)round([[NSDate date] timeIntervalSince1970] - appearedAtTime);
[[KISSmetricsAPI sharedAPI] set:@{@"someViewDuration" : @(duration)}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment