简体   繁体   中英

Event Duration in mobile analytics?

我正在为我的iphone应用程序使用Localytics移动分析。例如,用户花了多少时间查看屏幕...在flurry..api中可以使用...但在Localytics中可以使用吗?

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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM