From d4354fa4dbec63188f88aad53ca89162c507606b Mon Sep 17 00:00:00 2001 From: Nadia Barbosa Date: Fri, 5 Oct 2018 19:10:58 -0400 Subject: [PATCH] [ios] Log event when offline pack is created --- platform/darwin/src/MGLOfflineRegion_Private.h | 5 +++++ platform/darwin/src/MGLOfflineStorage.mm | 17 +++++++++++++++++ platform/darwin/src/MGLShapeOfflineRegion.mm | 15 +++++++++++++++ .../darwin/src/MGLTilePyramidOfflineRegion.mm | 15 +++++++++++++++ platform/ios/vendor/mapbox-events-ios | 2 +- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLOfflineRegion_Private.h b/platform/darwin/src/MGLOfflineRegion_Private.h index c1f3fd52006..75a023bcbb8 100644 --- a/platform/darwin/src/MGLOfflineRegion_Private.h +++ b/platform/darwin/src/MGLOfflineRegion_Private.h @@ -14,6 +14,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (const mbgl::OfflineRegionDefinition)offlineRegionDefinition; +/** + Attributes to be passed into the offline download start event + */ +@property (nonatomic, readonly) NSDictionary *offlineStartEventAttributes; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index fd6dd2f998d..27d6c708b2a 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -7,9 +7,15 @@ #import "MGLOfflinePack_Private.h" #import "MGLOfflineRegion_Private.h" #import "MGLTilePyramidOfflineRegion.h" +#import "MGLShapeOfflineRegion.h" #import "NSBundle+MGLAdditions.h" #import "NSValue+MGLAdditions.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MMEConstants.h" +#import "MGLMapboxEvents.h" +#endif + #include #include #include @@ -358,6 +364,17 @@ - (void)addPackForRegion:(id )region withContext:(NSData *)con if (completion) { completion(pack, error); } + + #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + NSMutableDictionary *offlineDownloadStartEventAttributes = [NSMutableDictionary dictionaryWithObject:MMEventTypeOfflineDownloadStart forKey:MMEEventKeyEvent]; + + if ([region conformsToProtocol:@protocol(MGLOfflineRegion_Private)]) { + NSDictionary *regionAttributes = ((id)region).offlineStartEventAttributes; + [offlineDownloadStartEventAttributes addEntriesFromDictionary:regionAttributes]; + } + + [MGLMapboxEvents pushEvent:MMEventTypeOfflineDownloadStart withAttributes:offlineDownloadStartEventAttributes]; + #endif }]; } diff --git a/platform/darwin/src/MGLShapeOfflineRegion.mm b/platform/darwin/src/MGLShapeOfflineRegion.mm index e1393f1199e..7a2de8a82bb 100644 --- a/platform/darwin/src/MGLShapeOfflineRegion.mm +++ b/platform/darwin/src/MGLShapeOfflineRegion.mm @@ -12,6 +12,10 @@ #import "MGLShape_Private.h" #import "MGLStyle.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MMEConstants.h" +#endif + @interface MGLShapeOfflineRegion () @end @@ -22,6 +26,17 @@ @implementation MGLShapeOfflineRegion { @synthesize styleURL = _styleURL; +-(NSDictionary *)offlineStartEventAttributes { + return @{ + #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + MMEEventKeyShapeForOfflineRegion: @"shaperegion", + MMEEventKeyMinZoomLevel: @(self.minimumZoomLevel), + MMEEventKeyMaxZoomLevel: @(self.maximumZoomLevel), + MMEEventKeyStyleURL: self.styleURL + #endif + }; +} + + (BOOL)supportsSecureCoding { return YES; } diff --git a/platform/darwin/src/MGLTilePyramidOfflineRegion.mm b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm index 0766d224da9..2e06be679ee 100644 --- a/platform/darwin/src/MGLTilePyramidOfflineRegion.mm +++ b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm @@ -9,6 +9,10 @@ #import "MGLGeometry_Private.h" #import "MGLStyle.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MMEConstants.h" +#endif + @interface MGLTilePyramidOfflineRegion () @end @@ -19,6 +23,17 @@ @implementation MGLTilePyramidOfflineRegion { @synthesize styleURL = _styleURL; +-(NSDictionary *)offlineStartEventAttributes { + return @{ + #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + MMEEventKeyShapeForOfflineRegion: @"tileregion", + MMEEventKeyMinZoomLevel: @(self.minimumZoomLevel), + MMEEventKeyMaxZoomLevel: @(self.maximumZoomLevel), + MMEEventKeyStyleURL: self.styleURL + #endif + }; +} + + (BOOL)supportsSecureCoding { return YES; } diff --git a/platform/ios/vendor/mapbox-events-ios b/platform/ios/vendor/mapbox-events-ios index d5e86d0a749..61fca377e82 160000 --- a/platform/ios/vendor/mapbox-events-ios +++ b/platform/ios/vendor/mapbox-events-ios @@ -1 +1 @@ -Subproject commit d5e86d0a749d94a8e5f032b9946f7683bdd8c8be +Subproject commit 61fca377e82b4cfb5e99feea1f465eff1dabbf4e