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

[iOS] Generate and send a turnstile event when map view event is queued #3713

Merged
merged 1 commit into from
Feb 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 41 additions & 36 deletions platform/ios/src/MGLMapboxEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ - (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 @@ -429,38 +424,42 @@ - (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];

if (!vid) return;

NSDictionary *vevt = @{@"event" : MGLEventTypeAppUserTurnstile,
@"created" : [strongSelf.rfc3339DateFormatter stringFromDate:[NSDate date]],
@"appBundleId" : strongSelf.appBundleId,
@"vendorId": vid,
@"version": @(version),
@"instance": strongSelf.instanceID};

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

// Flush
[strongSelf flush];

if ([strongSelf debugLoggingEnabled]) {
[strongSelf writeEventToLocalDebugLog:vevt];
}


static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_async(_serialQueue, ^{

MGLMapboxEvents *strongSelf = weakSelf;

if ( ! strongSelf) return;

// Build only IDFV event
NSString *vid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

if (!vid) return;

NSDictionary *vevt = @{@"event" : MGLEventTypeAppUserTurnstile,
@"created" : [strongSelf.rfc3339DateFormatter stringFromDate:[NSDate date]],
@"appBundleId" : strongSelf.appBundleId,
@"vendorId": vid,
@"version": @(version),
@"instance": strongSelf.instanceID};

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

// Flush
[strongSelf flush];

if ([strongSelf debugLoggingEnabled]) {
[strongSelf writeEventToLocalDebugLog:vevt];
}

});
});
}

Expand All @@ -484,13 +483,18 @@ - (void) pushEvent:(NSString *)event withAttributes:(MGLMapboxEventAttributes *)
MGLMapboxEvents *strongSelf = weakSelf;

if ( ! strongSelf) return;

if (!event) return;

// If it's a map load event then turn the Mapbox Turnstile to count app users
if ([event isEqualToString:MGLEventTypeMapLoad]) {
[self pushTurnstileEvent];
}

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

if (!event) return;

MGLMutableMapboxEventAttributes *evt = [MGLMutableMapboxEventAttributes dictionaryWithDictionary:attributeDictionary];
// mapbox-events stock attributes
Expand Down Expand Up @@ -520,6 +524,7 @@ - (void) pushEvent:(NSString *)event withAttributes:(MGLMapboxEventAttributes *)

// Put On The Queue
[_eventQueue addObject:finalEvent];


// Has Flush Limit Been Reached?
if (_eventQueue.count >= MGLMaximumEventsPerFlush) {
Expand Down