[iOS] Generate and send a turnstile event when map view event is queued
This change adds logic to push a turnstile event whenever a map view event is queued. It guards against sending the turnstile event more than once per session. Note that `pushTurnstileEvent` is actually a "force push" in that it flushes the queue and, since it enqueues a turnstile event, the flush's call to `postEvents` will attempt to send any queued events even if telemetry is paused. This has the side effect of defeating the other queue / timing / flush logic in place whenever map load (and now implicitly turnstile) events are pushed.
This commit is contained in:
@@ -275,11 +275,6 @@ const NSTimeInterval MGLFlushInterval = 60;
|
||||
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;
|
||||
}
|
||||
@@ -429,38 +424,42 @@ const NSTimeInterval MGLFlushInterval = 60;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (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];
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -484,13 +483,18 @@ const NSTimeInterval MGLFlushInterval = 60;
|
||||
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
|
||||
@@ -520,6 +524,7 @@ const NSTimeInterval MGLFlushInterval = 60;
|
||||
|
||||
// Put On The Queue
|
||||
[_eventQueue addObject:finalEvent];
|
||||
|
||||
|
||||
// Has Flush Limit Been Reached?
|
||||
if (_eventQueue.count >= MGLMaximumEventsPerFlush) {
|
||||
|
||||
Reference in New Issue
Block a user