diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-01-27 13:26:19 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-02-15 11:35:07 -0800 |
commit | 9891d0eb794df7a6fa69afd5c56bc371101d41fc (patch) | |
tree | a16c8ddbba870d7d1b6638b319af56f45e3150e2 /platform/ios/src/MGLMapboxEvents.m | |
parent | 14f81dbed53b65d29bb71ea3b2b4e3ef44c1f068 (diff) | |
download | qtlocation-mapboxgl-9891d0eb794df7a6fa69afd5c56bc371101d41fc.tar.gz |
[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.
Diffstat (limited to 'platform/ios/src/MGLMapboxEvents.m')
-rw-r--r-- | platform/ios/src/MGLMapboxEvents.m | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m index 567b0c3c90..b792a6af39 100644 --- a/platform/ios/src/MGLMapboxEvents.m +++ b/platform/ios/src/MGLMapboxEvents.m @@ -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) { |