Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Log event when offline pack is created
Browse files Browse the repository at this point in the history
  • Loading branch information
captainbarbosa committed Oct 23, 2018
1 parent 28bc4b2 commit 5f1d419
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions platform/darwin/src/MGLOfflineRegion_Private.h
Expand Up @@ -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
17 changes: 17 additions & 0 deletions platform/darwin/src/MGLOfflineStorage.mm
Expand Up @@ -7,11 +7,17 @@
#import "MGLOfflinePack_Private.h"
#import "MGLOfflineRegion_Private.h"
#import "MGLTilePyramidOfflineRegion.h"
#import "MGLShapeOfflineRegion.h"
#import "NSBundle+MGLAdditions.h"
#import "NSValue+MGLAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "NSData+MGLAdditions.h"

#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MMEConstants.h"
#import "MGLMapboxEvents.h"
#endif

#include <mbgl/actor/actor.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <mbgl/storage/resource_transform.hpp>
Expand Down Expand Up @@ -361,6 +367,17 @@ - (void)addPackForRegion:(id <MGLOfflineRegion>)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<MGLOfflineRegion_Private>)region).offlineStartEventAttributes;
[offlineDownloadStartEventAttributes addEntriesFromDictionary:regionAttributes];
}

[MGLMapboxEvents pushEvent:MMEventTypeOfflineDownloadStart withAttributes:offlineDownloadStartEventAttributes];
#endif
}];
}

Expand Down
15 changes: 15 additions & 0 deletions platform/darwin/src/MGLShapeOfflineRegion.mm
Expand Up @@ -12,6 +12,10 @@
#import "MGLShape_Private.h"
#import "MGLStyle.h"

#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MMEConstants.h"
#endif

@interface MGLShapeOfflineRegion () <MGLOfflineRegion_Private, MGLShapeOfflineRegion_Private>

@end
Expand All @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions platform/darwin/src/MGLTilePyramidOfflineRegion.mm
Expand Up @@ -9,6 +9,10 @@
#import "MGLGeometry_Private.h"
#import "MGLStyle.h"

#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MMEConstants.h"
#endif

@interface MGLTilePyramidOfflineRegion () <MGLOfflineRegion_Private, MGLTilePyramidOfflineRegion_Private>

@end
Expand All @@ -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;
}
Expand Down

0 comments on commit 5f1d419

Please sign in to comment.