Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Counting App Users For Billing #1603

Merged
merged 7 commits into from
May 20, 2015
1 change: 1 addition & 0 deletions platform/ios/MGLMapboxEvents.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <Foundation/Foundation.h>

extern NSString *const MGLEventTypeAppUserTurnstile;
extern NSString *const MGLEventTypeMapLoad;
extern NSString *const MGLEventTypeMapTap;
extern NSString *const MGLEventTypeMapDragEnd;
Expand Down
36 changes: 35 additions & 1 deletion platform/ios/MGLMapboxEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
static NSString *const MGLMapboxEventsUserAgent = @"MapboxEventsiOS/1.0";
static NSString *MGLMapboxEventsAPIBase = @"https://api.tiles.mapbox.com";

NSString *const MGLEventTypeAppUserTurnstile = @"appUserTurnstile";
NSString *const MGLEventTypeMapLoad = @"map.load";
NSString *const MGLEventTypeMapTap = @"map.click";
NSString *const MGLEventTypeMapDragEnd = @"map.dragend";
Expand Down Expand Up @@ -277,6 +278,11 @@ - (instancetype) init {
MGLMapboxEvents *strongSelf = weakSelf;
[strongSelf validate];
}];

// Turn the Mapbox Turnstile to Count App Users
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[self pushTurnstileEvent];
});
}
return self;
}
Expand Down Expand Up @@ -315,6 +321,7 @@ + (void)validate {
[[MGLMapboxEvents sharedManager] validate];
}

// Used to determine if Mapbox Metrics should be collected at any given point in time
- (void)validate {
MGLAssertIsMainThread();
BOOL enabledInSettings = [[self class] isEnabled];
Expand Down Expand Up @@ -414,6 +421,31 @@ - (void)startUpdatingLocation {
}
}

- (void) pushTurnstileEvent {

__weak MGLMapboxEvents *weakSelf = self;

dispatch_async(_serialQueue, ^{

MGLMapboxEvents *strongSelf = weakSelf;

if ( ! strongSelf) return;

// Build only IDFV event
NSString *vid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSDictionary *vevt = @{@"event" : MGLEventTypeAppUserTurnstile,
@"created" : [strongSelf.rfc3339DateFormatter stringFromDate:[NSDate date]],
@"appBundleId" : strongSelf.appBundleId,
@"vendorId": vid};

// Add to Queue
[_eventQueue addObject:vevt];

// Flush
[strongSelf flush];
});
}

// Can be called from any thread. Can be called rapidly from
// the UI thread, so performance is paramount.
//
Expand All @@ -430,9 +462,11 @@ - (void) pushEvent:(NSString *)event withAttributes:(NSDictionary *)attributeDic
__weak MGLMapboxEvents *weakSelf = self;

dispatch_async(_serialQueue, ^{

MGLMapboxEvents *strongSelf = weakSelf;

if ( ! strongSelf) return;

// Metrics Collection Has Been Paused
if (_paused) {
return;
Expand Down