From cbcc3a3e4912077f78e63ea4e470342f894e1630 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 20 May 2015 15:05:56 -0500 Subject: [PATCH] #1595 - Separating pushTurnstileEvent from primary pushEvent infrastructure. Adding event, created, and appBundleId to posted Turnstile Event data model. --- platform/ios/MGLMapboxEvents.m | 45 ++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index b6daaab3b..db5949a31 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -280,7 +280,9 @@ const NSTimeInterval MGLFlushInterval = 60; }]; // Turn the Mapbox Turnstile to Count App Users - [self pushEvent:MGLEventTypeAppUserTurnstile withAttributes:nil]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ + [self pushTurnstileEvent]; + }); } return self; } @@ -419,6 +421,31 @@ 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]; + NSDictionary *vevt = @{@"event" : MGLEventTypeAppUserTurnstile, + @"created" : [strongSelf.rfc3339DateFormatter stringFromDate:[NSDate date]], + @"appBundleId" : strongSelf.appBundleId, + @"vendorId": vid}; + + // Add to Queue + [_eventQueue addObject:vevt]; + + // Flush + [self flush]; + }); +} + // Can be called from any thread. Can be called rapidly from // the UI thread, so performance is paramount. // @@ -440,20 +467,6 @@ const NSTimeInterval MGLFlushInterval = 60; if ( ! strongSelf) return; - if ([MGLEventTypeAppUserTurnstile isEqualToString:event]) { - // Build only IDFV event - NSString *vid = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; - NSDictionary *vevt = @{@"vendorId": vid}; - - // Add to Queue - [_eventQueue addObject:vevt]; - - // Flush - [self flush]; - - return; - } - // Metrics Collection Has Been Paused if (_paused) { return; @@ -502,7 +515,7 @@ const NSTimeInterval MGLFlushInterval = 60; [_eventQueue addObject:finalEvent]; // Has Flush Limit Been Reached? - if (_eventQueue.count >= MGLMaximumEventsPerFlush || [MGLEventTypeAppUserTurnstile isEqualToString:event]) { + if (_eventQueue.count >= MGLMaximumEventsPerFlush) { [strongSelf flush]; } else if (_eventQueue.count == 1) { // If this is first new event on queue start timer,