androidiphoneipadios4localytics

Event Duration in mobile analytics?


I am using Localytics mobile analytics for my iphone app.for example , how much time the user has spent for seeing screen...it is possible in flurry..api is available...but it is possible in Localytics ?


Solution

  • The best way to do this with Localytics is to fire an event when the screen is closed recording the time as a bucketed event attribute. This way you'll have a nice pie chart showing you how often the screen is viewed as well as the ability to see how many users have viewed the screen, what devices it is most used on and all the other metrics that Localytics lets you view your events by.

    To fire this event you want to do something like:

    // When you show the screen
    NSDate *date = [NSDate date]; // save this somewhere
    
    // When you close the screen:   
    // Find elapsed time and convert to milliseconds
    // Use (-) modifier to conversion since receiver is earlier than now
    unsigned int seconds = (unsigned int)([date timeIntervalSinceNow] * -1.0);
    
    NSDictionary *dictionary =
         [NSDictionary dictionaryWithObjectsAndKeys:
         [self bucketizeSeconds:seconds],
         @"View Time",
         nil];
    [[LocalyticsSession sharedLocalyticsSession] 
      tagEvent:@"Intro Screen viewed" 
      attributes:dictionary];
    

    This relies on a bucketizing function:

    - (NSString *) bucketizeSeconds:(unsigned int)seconds
    {
      unsigned int secondBuckets[9] = {3, 10, 30, 60, 180, 600, 1800, 3600, -1};
      NSArray *secondBucketNames = [NSArray arrayWithObjects: 
         @"0 - 3 seconds", 
         @"3 - 10 seconds", @"10 - 30 seconds", @"30 - 60 seconds",
         @"1 - 3 minutes", @"3 - 10 minutes", @"10 - 30 minutes", @"30 - 60 minutes",
         @"> 1 hour", nil];
    
      for(unsigned int i=0; i < (sizeof secondBuckets) / (sizeof secondBuckets[0]); i++) 
      {
        if(secondBuckets[i] > seconds) 
        {
          return [secondBucketNames objectAtIndex: i];
        }       
      }
    
      return @"error";
    }