summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorBrad Leege <bleege@gmail.com>2015-05-20 15:56:18 -0500
committerBrad Leege <bleege@gmail.com>2015-05-20 15:56:18 -0500
commit8f8631963b66a0442e6b5fbc920a58d72e7ae1d7 (patch)
tree40b1c477d13a5ec3ec440155d348b85d02d8d689 /platform
parent51618c35d79cfb237e62e70993182e87903c3ccd (diff)
parenta47438d42adddad9838048cb4c5996a3eadb1c6b (diff)
downloadqtlocation-mapboxgl-8f8631963b66a0442e6b5fbc920a58d72e7ae1d7.tar.gz
Merge pull request #1603 from mapbox/1595-internal-billing
Counting App Users For Billing
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLMapboxEvents.h1
-rw-r--r--platform/ios/MGLMapboxEvents.m36
2 files changed, 36 insertions, 1 deletions
diff --git a/platform/ios/MGLMapboxEvents.h b/platform/ios/MGLMapboxEvents.h
index 94aa8be783..00de64a8b0 100644
--- a/platform/ios/MGLMapboxEvents.h
+++ b/platform/ios/MGLMapboxEvents.h
@@ -1,5 +1,6 @@
#import <Foundation/Foundation.h>
+extern NSString *const MGLEventTypeAppUserTurnstile;
extern NSString *const MGLEventTypeMapLoad;
extern NSString *const MGLEventTypeMapTap;
extern NSString *const MGLEventTypeMapDragEnd;
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index 98bfe21cfe..011040097a 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -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";
@@ -277,6 +278,11 @@ 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;
}
@@ -315,6 +321,7 @@ const NSTimeInterval MGLFlushInterval = 60;
[[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];
@@ -414,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
+ [strongSelf flush];
+ });
+}
+
// Can be called from any thread. Can be called rapidly from
// the UI thread, so performance is paramount.
//
@@ -430,9 +462,11 @@ const NSTimeInterval MGLFlushInterval = 60;
__weak MGLMapboxEvents *weakSelf = self;
dispatch_async(_serialQueue, ^{
+
MGLMapboxEvents *strongSelf = weakSelf;
+
if ( ! strongSelf) return;
-
+
// Metrics Collection Has Been Paused
if (_paused) {
return;