summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLMetricsManager.m
blob: 75dc593aa7e363157cdefe9833709df768608ee1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "MGLMetricsManager_Private.h"
#if TARGET_OS_IOS
#import "MGLMapboxEvents.h"
#endif

NSString * const kMGLPerformanceMetric = @"mobile.performance_trace";

@implementation MGLMetricsManager

+ (instancetype)sharedManager
{
    static dispatch_once_t once;
    static id sharedConfiguration;
    dispatch_once(&once, ^{
        sharedConfiguration = [[self alloc] init];
    });
    return sharedConfiguration;
}

- (void)handleMetricEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
    if ([self.delegate shouldHandleMetric:metricType]) {
        [self.delegate didCollectMetric:metricType withAttributes:attributes];
    }
}

#if TARGET_OS_IOS
- (void)pushMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
    
    NSString *eventName;
    
    switch (metricType) {
        case MGLMetricTypePerformance:
            eventName = kMGLPerformanceMetric;
            break;
            
        default:
            break;
    }
    
    [MGLMapboxEvents pushEvent:eventName withAttributes:attributes];

}
#endif

@end