Complex Events
To gather more detailed event data, create a Complex Event such as Timers, Counters and Collections.
Timers and Counters
If, for example, you wanted to track how many times and for how long a user interacted with a specific screen, you can easily record this using MedialetsEvent's startTimerForKey and endTimerForKey. Below is pseudocode that shows how this is accomplished:
//where appropriate, instantiate the event object MedialetsEvent *screenEvent = [[MedialetsEvent alloc] initWithKey:@"Screen 1 Event"]; . . // screen is displayed [screenEvent startTimerForKey:@"DisplayDuration"]; [screenEvent incrementNumberForKey:@"DisplayCount"]; . . // screen is no longer displayed [screenEvent endTimerForKey:@["DisplayDuration"];
Collections
If, for example, you are writing a game and are storing the user's score for each level of the game in a Dictionary, you can easily associate this type of information with an event. Below is pseudocode that shows how this is accomplished:
NSDictionary *ammoDict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:10000], @"Bullets", [NSNumber numberWithInt:100], @"Missiles", [NSNumber numberWithInt:10], @"Nukes", nil]; NSTimeInterval appStoreTime = 13.6; MedialetsEvent *myEvent = [[MMEvent alloc] initWithKey:@"AppStorePurchase"]; [myEvent setString:@"Ammunition" forKey:@"Product"]; [myEvent setString:@"Ammo01" forKey:@"SKU"]; [myEvent setNumber:[NSNumber numberWithFloat:1.99] forKey:@"Price"]; [myEvent addNumbersFromDictionary:ammoDict]; [myEvent setDuration:appStoreTime forKey:@"AppStoreResponseTime"]; [[MedialetsAnalyticsManager sharedInstance] trackEvent:myEvent]; [myEvent release];
Observing and Recording Notifications
Notifications are a useful tool for sending events around your application without having to directly connect to (or even know about) all the objects that are interested in those events. The Medialets Mobile Analytics API makes it very easy to add the Analytics Manager to be an observer of your notifications.
| If you are not familiar with notifications, we suggest reading the Notification Programming Topics Developer Guide included in Apple's iPhone OS documentation. |
MyTwitterPoster *poster = [MyTwitterPoster sharedInstance]; // assume these are the names of the notifications sent by the poster object NSArray *names = [NSArray arrayWithObjects:@"postSucceeded", @"postFailed", nil]; [[MedialetsAnalyticsManager sharedInstance] observeNotifications:names fromObject:poster];