Question

I currently have multiple tabs within my application. What I would like to do is record the amount of time the user spends in the selected tab using Flurry Analytics. Usually I would start recording when viewDidAppear is call and stop recording when the viewDidDisappear method is called.

viewDidAppear

[Flurry logEvent:@"Tab_News" withParameters:nil timed:YES];

viewDidDisappear

[Flurry endTimedEvent:@"Tab_News" withParameters:nil];

My problem is that when a video gets played within the tab the viewDidDisappear and viewDidAppear methods get called even thought the user doesnt physically leave the tab.

Please help me with suggestions as to how I can circumvent this.

Was it helpful?

Solution

Create a BOOL called videoPlaying to track if a video is being played. When you play the video set it to YES. In viewDidDisappear only endTimedEvent if (videoPlaying == NO)

The same applies to viewDidAppear. If videoPlaying == YES don't logEvent and then set videoPlaying = NO.

Something like this:

- (void)viewDidLoad
{
    _videoPlaying = NO;
}

- (void)viewDidAppear
{
    if (_videoPlaying == YES) {
        _videoPlaying = NO;
    } else {
        [Flurry logEvent:@"Tab_News" withParameters:nil timed:YES];
    }
}

- (void)viewDidDisappear
{
   if (_videoPlaying == NO) {
      [Flurry endTimedEvent:@"Tab_News" withParameters:nil];
   }
}

- (void)playVideo
{
    _videoPlaying = YES;
    // Play video
}

OTHER TIPS

If you're targeting iOS 6, you can do the following:

- (void)viewDidLoad {
    [super viewDidLoad];
    [Flurry logEvent:@"Tab_News" withParameters:nil timed:YES];
}

- (void)dealloc {
    [Flurry endTimedEvent:@"Tab_News" withParameters:nil];
}

This is valid if you present this ViewController as soon as it's loaded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top