forked from orta/ARAnalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARAnalytics.m
854 lines (715 loc) · 28.8 KB
/
ARAnalytics.m
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
#import "ARAnalytics.h"
#import "ARAnalyticalProvider.h"
#import "ARAnalyticsProviders.h"
static ARAnalytics *_sharedAnalytics;
static BOOL _ARLogShouldPrintStdout = YES;
@interface ARAnalytics ()
@property (readwrite, nonatomic, strong) NSMutableDictionary *superProperties;
@property (readwrite, nonatomic, strong) NSMutableDictionary *eventsDictionary;
@property (readwrite, nonatomic, copy) NSSet *providers;
@end
#if TARGET_OS_IPHONE
#import "ARNavigationControllerDelegateProxy.h"
@interface ARAnalytics ()
{
ARNavigationControllerDelegateProxy *_proxyDelegate;
}
@property (strong, readonly) ARNavigationControllerDelegateProxy *proxyDelegate;
@end
#endif
#if !TARGET_OS_IPHONE
@implementation UIViewController @end
@implementation UINavigationController @end
#endif
@implementation ARAnalytics
+ (void)initialize
{
static dispatch_once_t pred;
dispatch_once(&pred, ^{
_sharedAnalytics = [[ARAnalytics alloc] init];
_sharedAnalytics.providers = [NSSet set];
_sharedAnalytics.superProperties = [NSMutableDictionary dictionary];
});
}
+ (void)logShouldPrintStdout:(BOOL)shouldPrint
{
_ARLogShouldPrintStdout = shouldPrint;
}
#pragma mark -
#pragma mark Analytics Setup
// By using the constants at the bottom you can
+ (void)setupWithAnalytics:(NSDictionary *)analyticsDictionary
{
if (analyticsDictionary[ARTestFlightAppToken]) {
[self setupTestFlightWithAppToken:analyticsDictionary[ARTestFlightAppToken]];
}
if (analyticsDictionary[ARFlurryAPIKey]) {
[self setupFlurryWithAPIKey:analyticsDictionary[ARFlurryAPIKey]];
}
if (analyticsDictionary[ARGoogleAnalyticsID]) {
[self setupGoogleAnalyticsWithID:analyticsDictionary[ARGoogleAnalyticsID]];
}
if (analyticsDictionary[ARKISSMetricsAPIKey]) {
[self setupKISSMetricsWithAPIKey:analyticsDictionary[ARKISSMetricsAPIKey]];
}
if (analyticsDictionary[ARLocalyticsAppKey]) {
[self setupLocalyticsWithAppKey:analyticsDictionary[ARLocalyticsAppKey]];
}
if (analyticsDictionary[ARMixpanelToken]) {
// ARMixpanelHost is nil if you want the default provider. So we can make
// the presumption of it here.
[self setupMixpanelWithToken:analyticsDictionary[ARMixpanelToken] andHost:analyticsDictionary[ARMixpanelHost]];
}
if (analyticsDictionary[ARCountlyAppKey]) {
// ARCountlyHost is nil if you want the cloud host.
// If the host URL is not nil the it should be provided without the slash at the end.
[self setupCountlyWithAppKey:analyticsDictionary[ARCountlyAppKey] andHost:analyticsDictionary[ARCountlyHost]];
}
if (analyticsDictionary[ARBugsnagAPIKey]) {
[self setupBugsnagWithAPIKey:analyticsDictionary[ARBugsnagAPIKey]];
}
if (analyticsDictionary[ARHelpshiftAppID] && analyticsDictionary[ARHelpshiftDomainName] && analyticsDictionary[ARHelpshiftAPIKey]) {
[self setupHelpshiftWithAppID:analyticsDictionary[ARHelpshiftAppID] domainName:analyticsDictionary[ARHelpshiftDomainName] apiKey:analyticsDictionary[ARHelpshiftAPIKey]];
}
if (analyticsDictionary[ARTapstreamAccountName] && analyticsDictionary[ARTapstreamDeveloperSecret]) {
[self setupTapstreamWithAccountName:analyticsDictionary[ARTapstreamAccountName] developerSecret:analyticsDictionary[ARTapstreamDeveloperSecret] config:analyticsDictionary[ARTapstreamConfig]];
}
if (analyticsDictionary[ARNewRelicAppToken]) {
[self setupNewRelicWithAppToken:analyticsDictionary[ARNewRelicAppToken]];
}
if (analyticsDictionary[ARAmplitudeAPIKey]) {
[self setupAmplitudeWithAPIKey:analyticsDictionary[ARAmplitudeAPIKey]];
}
if (analyticsDictionary[ARHockeyAppBetaID]) {
[self setupHockeyAppWithBetaID:analyticsDictionary[ARHockeyAppBetaID] liveID:analyticsDictionary[ARHockeyAppLiveID]];
}
if (analyticsDictionary[ARParseApplicationID] && analyticsDictionary[ARParseClientKey]) {
[self setupParseAnalyticsWithApplicationID:analyticsDictionary[ARParseApplicationID] clientKey:analyticsDictionary[ARParseClientKey]];
}
if (analyticsDictionary[ARHeapAppID]) {
[self setupHeapAnalyticsWithApplicationID:analyticsDictionary[ARHeapAppID]];
}
if (analyticsDictionary[ARChartbeatID]) {
[self setupChartbeatWithApplicationID:analyticsDictionary[ARChartbeatID]];
}
if (analyticsDictionary[ARUMengAnalyticsID]) {
[self setupUMengAnalyticsIDWithAppkey:analyticsDictionary[ARUMengAnalyticsID]];
}
if (analyticsDictionary[ARLibratoEmail] && analyticsDictionary[ARLibratoToken]) {
[self setupLibratoWithEmail:analyticsDictionary[ARLibratoEmail] token:analyticsDictionary[ARLibratoToken] prefix:analyticsDictionary[ARLibratoPrefix]];
}
if (analyticsDictionary[ARSegmentioWriteKey]) {
[self setupSegmentioWithWriteKey:analyticsDictionary[ARSegmentioWriteKey] integrations:analyticsDictionary[ARSegmentioIntegrationsKey]];
}
if (analyticsDictionary[ARSwrveAppID] && analyticsDictionary[ARSwrveAPIKey]) {
[self setupSwrveWithAppID:analyticsDictionary[ARSwrveAppID] apiKey:analyticsDictionary[ARSwrveAPIKey]];
}
if (analyticsDictionary[ARAppsFlyerAppID] && analyticsDictionary[ARAppsFlyerDevKey]) {
[self setupAppsFlyerWithAppID:analyticsDictionary[ARAppsFlyerAppID] devKey:analyticsDictionary[ARAppsFlyerDevKey]];
}
if (analyticsDictionary[ARYandexMobileMetricaAPIKey]) {
[self setupYandexMobileMetricaWithAPIKey:analyticsDictionary[ARYandexMobileMetricaAPIKey]];
}
if (analyticsDictionary[ARAdjustAppTokenKey]) {
[self setupAdjustWithAppToken:analyticsDictionary[ARAdjustAppTokenKey] andConfigurationDelegate:nil];
}
if (analyticsDictionary[ARSnowplowURL]) {
[self setupSnowplowWithAddress:analyticsDictionary[ARSnowplowURL]];
}
if (analyticsDictionary[ARSentryID]) {
[self setupSentryWithID:analyticsDictionary[ARSentryID]];
}
if (analyticsDictionary[ARIntercomAppID] && analyticsDictionary[ARIntercomAPIKey]) {
[self setupIntercomWithAppID:analyticsDictionary[ARIntercomAppID] apiKey:analyticsDictionary[ARIntercomAPIKey]];
}
if (analyticsDictionary[ARKeenProjectID] && analyticsDictionary[ARKeenWriteKey] && analyticsDictionary[ARKeenReadKey]) {
[self setupKeenWithProjectID:analyticsDictionary[ARKeenProjectID] andWriteKey:analyticsDictionary[ARKeenWriteKey] andReadKey:analyticsDictionary[ARKeenReadKey]];
}
if (analyticsDictionary[ARAdobeData]) {
[self setupAdobeWithData:analyticsDictionary[ARAdobeData] otherSettings:analyticsDictionary[ARAdobeSettings]];
}
if (analyticsDictionary[ARInstallTrackerApplicationID]) {
[self setupInstallTrackerWithApplicationID:analyticsDictionary[ARInstallTrackerApplicationID]];
}
if (analyticsDictionary[ARAppseeAPIKey]) {
[self setupAppseeWithAPIKey:analyticsDictionary[ARAppseeAPIKey]];
}
if (analyticsDictionary[ARMobileAppTrackerAdvertiserID] &&
analyticsDictionary[ARMobileAppTrackerConversionKey] &&
analyticsDictionary[ARMobileAppTrackerAllowedEvents]) {
[self setupMobileAppTrackerWithAdvertiserID:analyticsDictionary[ARMobileAppTrackerAdvertiserID]
conversionKey:analyticsDictionary[ARMobileAppTrackerConversionKey]
allowedEvents:analyticsDictionary[ARMobileAppTrackerAllowedEvents]];
}
if (analyticsDictionary[ARLaunchKitAPIToken]) {
[self setupLaunchKitWithAPIToken:analyticsDictionary[ARLaunchKitAPIToken]];
}
// Add future integrations here:
// Crashlytics / Crittercism should stay at the bottom of this method,
// as they both need to register exceptions, and you'd only use one.
if (analyticsDictionary[ARCrashlyticsAPIKey]) {
[self setupCrashlyticsWithAPIKey:analyticsDictionary[ARCrashlyticsAPIKey]];
}
if (analyticsDictionary[ARFabricKits]) {
[self setupFabricWithKits:analyticsDictionary[ARFabricKits]];
}
if (analyticsDictionary[ARCrittercismAppID]) {
[self setupCrittercismWithAppID:analyticsDictionary[ARCrittercismAppID]];
}
}
+ (void)setupProvider:(ARAnalyticalProvider*)provider
{
_sharedAnalytics.providers = [_sharedAnalytics.providers setByAddingObject:provider];
}
+ (void)removeProvider:(ARAnalyticalProvider *)provider
{
NSMutableSet *mutableSet = [NSMutableSet setWithSet:_sharedAnalytics.providers];
[mutableSet removeObject:provider];
_sharedAnalytics.providers = mutableSet;
}
+ (NSSet *)currentProviders
{
return _sharedAnalytics.providers;
}
+ (ARAnalyticalProvider *)providerInstanceOfClass:(Class)ProviderClass
{
// Check whether the ProviderClass is subclass of ARAnalyticalProvider or not
if (![ProviderClass isSubclassOfClass:ARAnalyticalProvider.class]) {
return nil;
}
// Find the instance by enumerating the providers set
ARAnalyticalProvider *__block providerInstance = nil;
[_sharedAnalytics.providers enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
// Get the proivder and return it
if ((*stop = [obj isKindOfClass:ProviderClass])) {
providerInstance = obj;
}
}];
return providerInstance;
}
+ (void)setupTestFlightWithAppToken:(NSString *)token
{
#ifdef AR_TESTFLIGHT_EXISTS
TestFlightProvider *provider = [[TestFlightProvider alloc] initWithIdentifier:token];
[self setupProvider:provider];
#endif
}
+ (void)setupCrashlyticsWithAPIKey:(NSString *)key
{
#ifdef AR_CRASHLYTICS_EXISTS
CrashlyticsProvider *provider = [[CrashlyticsProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupFabricWithKits:(NSArray *)kits
{
#ifdef AR_FABRIC_EXISTS
FabricProvider *provider = [[FabricProvider alloc] initWithKits:kits];
if (provider){
[self setupProvider:provider];
}
#endif
}
+ (void)setupMixpanelWithToken:(NSString *)token
{
#ifdef AR_MIXPANEL_EXISTS
[self setupMixpanelWithToken:token andHost:nil];
#endif
}
+ (void)setupMixpanelWithToken:(NSString *)token andHost:(NSString *)host
{
#ifdef AR_MIXPANEL_EXISTS
MixpanelProvider *provider = [[MixpanelProvider alloc] initWithIdentifier:token andHost:host];
[self setupProvider:provider];
#endif
}
+ (void)setupFlurryWithAPIKey:(NSString *)key
{
#ifdef AR_FLURRY_EXISTS
FlurryProvider *provider = [[FlurryProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupGoogleAnalyticsWithID:(NSString *)identifier
{
#ifdef AR_GOOGLEANALYTICS_EXISTS
GoogleAnalyticsProvider *provider = [[GoogleAnalyticsProvider alloc] initWithIdentifier:identifier];
[self setupProvider:provider];
#endif
}
+ (void)setupFirebaseAnalytics
{
#ifdef AR_FIREBASE_EXISTS
FirebaseProvider *provider = [[FirebaseProvider alloc] initWithIdentifier:nil];
[self setupProvider:provider];
#endif
}
+ (void)setupLocalyticsWithAppKey:(NSString *)key
{
#ifdef AR_LOCALYTICS_EXISTS
LocalyticsProvider *provider = [[LocalyticsProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupKISSMetricsWithAPIKey:(NSString *)key
{
#ifdef AR_KISSMETRICS_EXISTS
KISSMetricsProvider *provider = [[KISSMetricsProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupCrittercismWithAppID:(NSString *)appID
{
#ifdef AR_CRITTERCISM_EXISTS
CrittercismProvider *provider = [[CrittercismProvider alloc] initWithIdentifier:appID];
[self setupProvider:provider];
#endif
}
+ (void)setupCountlyWithAppKey:(NSString *)key andHost:(NSString *)host
{
#ifdef AR_COUNTLY_EXISTS
CountlyProvider *provider = [[CountlyProvider alloc] initWithAppKey:key andHost:host];
[self setupProvider:provider];
#endif
}
+ (void)setupBugsnagWithAPIKey:(NSString *)key
{
#ifdef AR_BUGSNAG_EXISTS
BugsnagProvider *provider = [[BugsnagProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupHelpshiftWithAppID:(NSString *)appID domainName:(NSString *)domainName apiKey:(NSString *)apiKey
{
#ifdef AR_HELPSHIFT_EXISTS
HelpshiftProvider *provider = [[HelpshiftProvider alloc] initWithAppID:appID domainName:domainName apiKey:apiKey];
[self setupProvider:provider];
#endif
}
+ (void)setupTapstreamWithAccountName:(NSString *)accountName developerSecret:(NSString *)developerSecret
{
#ifdef AR_TAPSTREAM_EXISTS
TapstreamProvider *provider = [[TapstreamProvider alloc] initWithAccountName:accountName developerSecret:developerSecret];
[self setupProvider:provider];
#endif
}
+ (void)setupTapstreamWithAccountName:(NSString *)accountName developerSecret:(NSString *)developerSecret config:(TSConfig *)config
{
#ifdef AR_TAPSTREAM_EXISTS
TapstreamProvider *provider = [[TapstreamProvider alloc] initWithAccountName:accountName developerSecret:developerSecret config:config];
[self setupProvider:provider];
#endif
}
+ (void)setupNewRelicWithAppToken:(NSString *)token
{
#ifdef AR_NEWRELIC_EXISTS
NewRelicProvider *provider = [[NewRelicProvider alloc] initWithIdentifier:token];
[self setupProvider:provider];
#endif
}
+ (void)setupAmplitudeWithAPIKey:(NSString *)key
{
#ifdef AR_AMPLITUDE_EXISTS
AmplitudeProvider *provider = [[AmplitudeProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupHockeyAppWithBetaID:(NSString *)betaID
{
#ifdef AR_HOCKEYAPP_EXISTS
[self setupHockeyAppWithBetaID:betaID liveID:nil];
#endif
}
+ (void)setupHockeyAppWithBetaID:(NSString *)betaID liveID:(NSString *)liveID
{
#ifdef AR_HOCKEYAPP_EXISTS
HockeyAppProvider *provider = [[HockeyAppProvider alloc] initWithBetaIdentifier:betaID liveIdentifier:liveID];
[self setupProvider:provider];
#endif
}
+ (void)setupParseAnalyticsWithApplicationID:(NSString *)appID clientKey:(NSString *)clientKey
{
#ifdef AR_PARSEANALYTICS_EXISTS
ParseAnalyticsProvider *provider = [[ParseAnalyticsProvider alloc] initWithApplicationID:appID clientKey:clientKey];
[self setupProvider:provider];
#endif
}
+ (void)setupHeapAnalyticsWithApplicationID:(NSString *)appID
{
#ifdef AR_HEAPANALYTICS_EXISTS
HeapAnalyticsProvider *provider = [[HeapAnalyticsProvider alloc] initWithIdentifier:appID];
[self setupProvider:provider];
#endif
}
+ (void)setupChartbeatWithApplicationID:(NSString *)appID
{
#ifdef AR_CHARTBEAT_EXISTS
ChartbeatProvider *provider = [[ChartbeatProvider alloc] initWithIdentifier:appID];
[self setupProvider:provider];
#endif
}
+ (void)setupUMengAnalyticsIDWithAppkey:(NSString *)appID
{
#ifdef AR_UMENGANALYTICS_EXISTS
UMengAnalyticsProvider *provider = [[UMengAnalyticsProvider alloc] initWithIdentifier:appID];
[self setupProvider:provider];
#endif
}
+ (void)setupLibratoWithEmail:(NSString *)email token:(NSString *)token prefix:(NSString *)prefix
{
#ifdef AR_LIBRATO_EXISTS
LibratoProvider *provider = [[LibratoProvider alloc] initWithEmail:email token:token prefix:prefix];
[self setupProvider:provider];
#endif
}
+ (void)setupSegmentioWithWriteKey:(NSString *)key integrations:(NSArray *)integrations
{
#ifdef AR_SEGMENTIO_EXISTS
SegmentioProvider *provider = [[SegmentioProvider alloc] initWithIdentifier:key integrations:integrations];
[self setupProvider:provider];
#endif
}
+ (void)setupSwrveWithAppID:(NSString *)appID apiKey:(NSString *)apiKey
{
#ifdef AR_SWRVE_EXISTS
SwrveProvider *provider = [[SwrveProvider alloc] initWithAppID:appID apiKey:apiKey];
[self setupProvider:provider];
#endif
}
+ (void)setupYandexMobileMetricaWithAPIKey:(NSString *)key
{
#ifdef AR_YANDEXMOBILEMETRICA_EXISTS
YandexMobileMetricaProvider *provider = [[YandexMobileMetricaProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupAdjustWithAppToken:(NSString *)token andConfigurationDelegate:(id<AdjustDelegate>)delegate
{
#ifdef AR_ADJUST_EXISTS
AdjustProvider *provider = [[AdjustProvider alloc] initWithIdentifier:token andConfigurationDelegate:delegate];
[self setupProvider:provider];
#endif
}
+ (void)setupAppsFlyerWithAppID:(NSString *)appID devKey:(NSString *)devKey
{
#ifdef AR_APPSFLYER_EXISTS
AppsFlyerProvider *provider = [[AppsFlyerProvider alloc] initWithAppID:appID devKey:devKey];
[self setupProvider:provider];
#endif
}
+ (void)setupBranchWithAPIKey:(NSString *)key {
#ifdef AR_BRANCH_EXISTS
BranchProvider *provider = [[BranchProvider alloc] initWithAPIKey:key];
[self setupProvider:provider];
#endif
}
+ (void)setupSnowplowWithAddress:(NSString *)address
{
#ifdef AR_SNOWPLOW_EXISTS
SnowplowProvider *provider = [[SnowplowProvider alloc] initWithAddress:address];
[self setupProvider:provider];
#endif
}
+ (void)setupSentryWithID:(NSString *)identifier
{
#ifdef AR_SENTRY_EXISTS
SentryProvider *provider = [[SentryProvider alloc] initWithIdentifier:identifier];
[self setupProvider:provider];
#endif
}
+ (void)setupIntercomWithAppID:(NSString *)identifier apiKey:(NSString *)apiKey
{
#ifdef AR_INTERCOM_EXISTS
IntercomProvider *provider = [[IntercomProvider alloc] initWithWithAppID:identifier apiKey:apiKey];
[self setupProvider:provider];
#endif
}
+ (void)setupKeenWithProjectID:(NSString *)projectId andWriteKey:(NSString *)writeKey andReadKey:(NSString *)readKey
{
#ifdef AR_KEEN_EXISTS
KeenProvider *provider = [[KeenProvider alloc] initWithProjectID:projectId andWriteKey:writeKey andReadKey:readKey];
[self setupProvider:provider];
#endif
}
+ (void)setupAdobeWithData:(NSDictionary *)additionalData otherSettings:(NSDictionary *)settings {
#ifdef AR_ADOBE_EXISTS
AdobeProvider *provider = [[AdobeProvider alloc] initWithData:additionalData settings:settings];
[self setupProvider:provider];
#endif
}
+ (void)setupInstallTrackerWithApplicationID:(NSString *)applicationID
{
#ifdef AR_INSTALLTRACKER_EXISTS
InstallTrackerProvider *provider = [[InstallTrackerProvider alloc] initWithIdentifier:applicationID];
[self setupProvider:provider];
#endif
}
+ (void)setupAppseeWithAPIKey:(NSString *)key
{
#ifdef AR_APPSEE_EXISTS
AppseeProvider *provider = [[AppseeProvider alloc] initWithIdentifier:key];
[self setupProvider:provider];
#endif
}
+ (void)setupMobileAppTrackerWithAdvertiserID:(NSString *)advertiserID conversionKey:(NSString *)conversionKey allowedEvents:(NSArray *)allowedEvents {
#ifdef AR_MOBILEAPPTRACKER_EXISTS
MobileAppTrackerProvider *provider = [[MobileAppTrackerProvider alloc] initWithAdvertiserId:advertiserID
conversionKey:conversionKey
allowedEvents:allowedEvents];
[self setupProvider:provider];
#endif
}
+ (void)setupLaunchKitWithAPIToken:(NSString *)token {
#ifdef AR_LAUNCHKIT_EXISTS
LaunchKitProvider *provider = [[LaunchKitProvider alloc] initWithIdentifier:token];
[self setupProvider:provider];
#endif
}
+ (void)setupLeanplumWithAppId:(NSString *)appId developmentKey:(NSString *)developmentKey productionKey:(NSString *)productionKey {
#ifdef AR_LEANPLUM_EXISTS
LeanplumProvider *provider = [[LeanplumProvider alloc] initWithAppId:appId developmentKey:developmentKey productionKey:productionKey];
[self setupProvider:provider];
#endif
}
+ (void)setupAppboy {
#ifdef AR_APPBOY_EXISTS
AppboyProvider *provider = [[AppboyProvider alloc] initWithIdentifier:nil];
[self setupProvider:provider];
#endif
}
#pragma mark -
#pragma mark User Setup
+ (void)identifyUserWithID:(NSString *)userID andEmailAddress:(NSString *)email
{
[self identifyUserWithID:userID anonymousID:nil andEmailAddress:email];
}
+ (void)identifyUserWithID:(NSString *)userID anonymousID:(NSString *)anonymousID andEmailAddress:(NSString *)email
{
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider identifyUserWithID:userID anonymousID:anonymousID andEmailAddress:email];
}];
}
+ (void)setUserProperty:(NSString *)property toValue:(id)value
{
if (value == nil) {
NSLog(@"ARAnalytics: Value cannot be nil ( %@ ) ", property);
return;
}
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider setUserProperty:property toValue:value];
}];
}
+ (void)incrementUserProperty:(NSString *)counterName byInt:(NSInteger)amount
{
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider incrementUserProperty:counterName byInt:@(amount)];
}];
}
#pragma mark -
#pragma mark Events
+ (void)event:(NSString *)event
{
[self event:event withProperties:nil];
}
+ (void)event:(NSString *)event withProperties:(NSDictionary *)properties
{
NSMutableDictionary *fullProperties = [NSMutableDictionary dictionaryWithDictionary:properties];
[fullProperties addEntriesFromDictionary:_sharedAnalytics.superProperties];
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider event:event withProperties:fullProperties];
}];
}
+ (void)addEventSuperProperties:(NSDictionary *)superProperties
{
[_sharedAnalytics.superProperties addEntriesFromDictionary:superProperties];
}
+ (void)removeEventSuperProperty:(NSString *)key;
{
[_sharedAnalytics.superProperties removeObjectForKey:key];
}
+ (void)removeEventSuperProperties:(NSArray *)keys;
{
[_sharedAnalytics.superProperties removeObjectsForKeys:keys];
}
#pragma mark -
#pragma mark Errors
+ (void)error:(NSError *)error
{
[self error:error withMessage:nil];
}
+ (void)error:(NSError *)error withMessage:(NSString *)message
{
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider error:error withMessage:message];
}];
}
#pragma mark -
#pragma mark Screen views
+ (void)pageView:(NSString *)pageTitle
{
[self pageView:pageTitle withProperties:nil];
}
+ (void)pageView:(NSString *)pageTitle withProperties:(NSDictionary *)properties
{
if (!pageTitle) return;
NSMutableDictionary *fullProperties = [properties ?: @{} mutableCopy];
[fullProperties addEntriesFromDictionary:_sharedAnalytics.superProperties];
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider didShowNewPageView:pageTitle withProperties:fullProperties];
}];
}
#pragma mark -
#pragma mark Monitor Navigation Controller
+ (void)monitorNavigationViewController:(UINavigationController *)controller
{
[self monitorNavigationController:controller];
}
+ (void)monitorNavigationController:(UINavigationController *)controller
{
#if TARGET_OS_IPHONE
// Set a new original delegate on the proxy
_sharedAnalytics.proxyDelegate.originalDelegate = controller.delegate;
// Then set the new controllers delegate as the proxy
controller.delegate = _sharedAnalytics.proxyDelegate;
#endif
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
#if TARGET_OS_IPHONE
[self.class pageView:viewController.title];
#endif
}
#if TARGET_OS_IPHONE
/// Lazily loaded
- (ARNavigationControllerDelegateProxy *)proxyDelegate
{
if (!_proxyDelegate) {
_proxyDelegate = [[ARNavigationControllerDelegateProxy alloc] initWithAnalyticsDelegate:self];
}
return _proxyDelegate;
}
#endif
#pragma mark -
#pragma mark Timing Events
+ (void)startTimingEvent:(NSString *)event
{
if (!_sharedAnalytics.eventsDictionary) {
_sharedAnalytics.eventsDictionary = [NSMutableDictionary dictionary];
}
_sharedAnalytics.eventsDictionary[event] = [NSDate date];
}
+ (void)finishTimingEvent:(NSString *)event
{
[self finishTimingEvent:event withProperties:nil];
}
+ (void)finishTimingEvent:(NSString *)event withProperties:(NSDictionary *)properties
{
NSDate *startDate = _sharedAnalytics.eventsDictionary[event];
if (!startDate) {
NSLog(@"ARAnalytics: finish timing event (%@) called without a corrosponding start timing event", event);
return;
}
NSTimeInterval eventInterval = [[NSDate date] timeIntervalSinceDate:startDate];
[_sharedAnalytics.eventsDictionary removeObjectForKey:event];
NSMutableDictionary *fullProperties = [NSMutableDictionary dictionaryWithDictionary:properties];
[fullProperties addEntriesFromDictionary:_sharedAnalytics.superProperties];
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider logTimingEvent:event withInterval:@(eventInterval) properties:fullProperties];
}];
}
#pragma mark -
#pragma mark Util
- (void)iterateThroughProviders:(void(^)(ARAnalyticalProvider *provider))providerBlock
{
for (ARAnalyticalProvider *provider in self.providers) {
providerBlock(provider);
}
}
@end
void ARLog (NSString *format, ...) {
va_list argList;
va_start(argList, format);
ARLogv(format, argList);
va_end(argList);
}
void ARLogv (NSString *format, va_list argList) {
if (format == nil) {
if (_ARLogShouldPrintStdout) {
printf("nil \n");
}
return;
}
@autoreleasepool {
NSString *parsedFormatString = [[NSString alloc] initWithFormat:format arguments:argList];
parsedFormatString = [parsedFormatString stringByReplacingOccurrencesOfString:@"%%" withString:@"%%%%"];
if (_ARLogShouldPrintStdout) {
printf("ARLog : %s\n", parsedFormatString.UTF8String);
}
[_sharedAnalytics iterateThroughProviders:^(ARAnalyticalProvider *provider) {
[provider remoteLog:parsedFormatString];
}];
}
}
void ARAnalyticsEvent (NSString *event, NSDictionary *properties) {
@try {
[ARAnalytics event:event withProperties:properties];
}
@catch (NSException *exception) {
NSLog(@"ARAnalytics: Exception raised when handling event %@ - %@ - %@", event, exception.name, exception.reason);
}
}
NSString * const ARCountlyAppKey = @"ARCountlyAppKey";
NSString * const ARCountlyHost = @"ARCountlyHost";
NSString * const ARTestFlightAppToken = @"ARTestFlight";
NSString * const ARCrashlyticsAPIKey = @"ARCrashlytics";
NSString * const ARFabricKits = @"ARFabricKits";
NSString * const ARMixpanelToken = @"ARMixpanel";
NSString * const ARMixpanelHost = @"ARMixpanelHost";
NSString * const ARFlurryAPIKey = @"ARFlurry";
NSString * const ARBugsnagAPIKey = @"ARBugsnag";
NSString * const ARLocalyticsAppKey = @"ARLocalytics";
NSString * const ARKISSMetricsAPIKey = @"ARKISSMetrics";
NSString * const ARCrittercismAppID = @"ARCrittercism";
NSString * const ARGoogleAnalyticsID = @"ARGoogleAnalytics";
NSString * const ARHelpshiftAppID = @"ARHelpshiftAppID";
NSString * const ARHelpshiftDomainName = @"ARHelpshiftDomainName";
NSString * const ARHelpshiftAPIKey = @"ARHelpshiftAPIKey";
NSString * const ARTapstreamAccountName = @"ARTapstreamAccountName";
NSString * const ARTapstreamDeveloperSecret = @"ARTapstreamDeveloperSecret";
NSString * const ARTapstreamConfig = @"ARTapstreamConfig";
NSString * const ARNewRelicAppToken = @"ARNewRelicAppToken";
NSString * const ARAmplitudeAPIKey = @"ARAmplitudeAPIKey";
NSString * const ARHockeyAppLiveID = @"ARHockeyAppLiveID";
NSString * const ARHockeyAppBetaID = @"ARHockeyAppBetaID";
NSString * const ARParseApplicationID = @"ARParseApplicationID";
NSString * const ARParseClientKey = @"ARParseClientKey";
NSString * const ARHeapAppID = @"ARHeapAppID";
NSString * const ARChartbeatID = @"ARChartbeatID";
NSString * const ARUMengAnalyticsID = @"ARUMengAnalyticsID";
NSString * const ARLibratoEmail = @"ARLibratoEmail";
NSString * const ARLibratoToken = @"ARLibratoToken";
NSString * const ARLibratoPrefix = @"ARLibratoPrefix";
NSString * const ARSegmentioWriteKey = @"ARSegmentioWriteKey";
NSString * const ARSegmentioIntegrationsKey = @"ARSegmentioIntegrationsKey";
NSString * const ARSwrveAppID = @"ARSwrveAppID";
NSString * const ARSwrveAPIKey = @"ARSwrveAPIKey";
NSString * const ARYandexMobileMetricaAPIKey = @"ARYandexMobileMetricaAPIKey";
NSString * const ARAdjustAppTokenKey = @"ARAdjustAppTokenKey";
NSString * const ARAppsFlyerAppID = @"ARAppsFlyerAppID";
NSString * const ARAppsFlyerDevKey = @"ARAppsFlyerDevKey";
NSString * const ARBranchAPIKey = @"ARBranchAPIKey";
NSString * const ARSnowplowURL = @"ARSnowplowURL";
NSString * const ARSentryID = @"ARSentryID";
NSString * const ARIntercomAppID = @"ARIntercomAppID";
NSString * const ARIntercomAPIKey = @"ARIntercomAPIKey";
NSString * const ARKeenProjectID = @"ARKeenProjectID";
NSString * const ARKeenWriteKey = @"ARKeenWriteKey";
NSString * const ARKeenReadKey = @"ARKeenReadKey";
NSString * const ARAdobeData = @"ARAdobeData";
NSString * const ARAdobeSettings = @"ARAdobeSettings";
NSString * const ARInstallTrackerApplicationID = @"ARInstallTrackerApplicationID";
NSString * const ARAppseeAPIKey = @"ARAppseeAPIKey";
NSString * const ARMobileAppTrackerAdvertiserID = @"ARMobileAppTrackerAdvertiserID";
NSString * const ARMobileAppTrackerConversionKey = @"ARMobileAppTrackerConversionKey";
NSString * const ARMobileAppTrackerAllowedEvents = @"ARMobileAppTrackerAllowedEvents";
NSString * const ARLaunchKitAPIToken = @"ARLaunchKitAPIToken";