From b763cf15ea0002f9d478d448529fac56191aa79d Mon Sep 17 00:00:00 2001 From: giomfo Date: Fri, 3 Jun 2016 16:38:02 +0200 Subject: [PATCH] Support GA services Remove useless Google dependencies. --- Podfile | 2 +- Podfile.lock | 24 +------------------ Vector/AppDelegate.m | 55 +++++++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/Podfile b/Podfile index 576314529..0e68689a9 100644 --- a/Podfile +++ b/Podfile @@ -24,7 +24,7 @@ pod 'MatrixKit', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :br pod 'GBDeviceInfo', '~> 3.4.0' -pod 'Google/Analytics' +pod 'GoogleAnalytics' end diff --git a/Podfile.lock b/Podfile.lock index 9cfa2a194..03b466ba2 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -20,26 +20,10 @@ PODS: - AFNetworking/UIKit (2.6.3): - AFNetworking/NSURLConnection - AFNetworking/NSURLSession - - FirebaseAnalytics (3.2.0): - - FirebaseInstanceID (~> 1.0) - - GoogleInterchangeUtilities (~> 1.2) - - GoogleSymbolUtilities (~> 1.1) - - GoogleUtilities (~> 1.3) - - FirebaseInstanceID (1.0.6) - GBDeviceInfo (3.4.1): - GBJailbreakDetection (~> 1.0) - GBJailbreakDetection (1.3.0) - - Google/Analytics (3.0.3): - - Google/Core - - GoogleAnalytics (~> 3.12) - - Google/Core (3.0.3): - - FirebaseAnalytics (~> 3.2) - GoogleAnalytics (3.14.0) - - GoogleInterchangeUtilities (1.2.1): - - GoogleSymbolUtilities (~> 1.0) - - GoogleSymbolUtilities (1.1.1) - - GoogleUtilities (1.3.1): - - GoogleSymbolUtilities (~> 1.0) - HPGrowingTextView (1.1) - libPhoneNumber-iOS (0.8.13) - MatrixKit (0.3.9): @@ -51,7 +35,7 @@ PODS: DEPENDENCIES: - GBDeviceInfo (~> 3.4.0) - - Google/Analytics + - GoogleAnalytics - MatrixKit (from `https://github.com/matrix-org/matrix-ios-kit.git`, branch `develop`) - MatrixSDK (from `https://github.com/matrix-org/matrix-ios-sdk.git`, branch `develop`) @@ -73,15 +57,9 @@ CHECKOUT OPTIONS: SPEC CHECKSUMS: AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60 - FirebaseAnalytics: 6f75b04e6bfb8e0b6e9ef298e04c24eea3b13863 - FirebaseInstanceID: d014d574053a2fe84478f12f7bae96979e7051bb GBDeviceInfo: bab0f43d351b6f641a626cd7d21492abef1afe46 GBJailbreakDetection: a216773574b62dddb6c876ffdb52c54ac05e27e0 - Google: 813c467362eabc11385f5a5cc9ad0cb651a58f4e GoogleAnalytics: 9be1afdb8deeac4bb5f13ca7f7d3b9db2a1f43dc - GoogleInterchangeUtilities: def8415a862effc67d549d5b5b0b9c7a2f97d4de - GoogleSymbolUtilities: 33117db1b5f290c6fbf259585e4885b4c84b98d7 - GoogleUtilities: 56c5ac05b7aa5dc417a1bb85221a9516e04d7032 HPGrowingTextView: 88a716d97fb853bcb08a4a08e4727da17efc9b19 libPhoneNumber-iOS: 3a37004baf779b4262ab29a31a87d2ae668159d4 MatrixKit: 9c8ceb305c33019bfe2c6f06512f60d80381ceb7 diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index b6a21d637..020a7d26b 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -16,7 +16,10 @@ #import "AppDelegate.h" -#import +// Google Analytics +#import "GAI.h" +#import "GAIFields.h" +#import "GAIDictionaryBuilder.h" #import "RecentsDataSource.h" #import "RoomDataSource.h" @@ -637,26 +640,36 @@ NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapSt // Check whether the user has enabled the sending of crash reports. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enableCrashReport"]) { - // Catch and log crashes - [MXLogger logCrashes:YES]; - [MXLogger setBuildVersion:[AppDelegate theDelegate].build]; - - // Configure tracker from GoogleService-Info.plist. - NSError *configureError; - [[GGLContext sharedInstance] configureWithError:&configureError]; - NSAssert(!configureError, @"Error configuring Google services: %@", configureError); - - // Optional: configure GAI options. - GAI *gai = [GAI sharedInstance]; - // Disable GA UncaughtException: their crash reports are quite limited (100 first chars of the stack trace) - // Let's MXLogger manage them - gai.trackUncaughtExceptions = NO; - - // Set Google Analytics dispatch interval to e.g. 20 seconds. - gai.dispatchInterval = 20; - - // Check if there is crash log to send to GA - [self checkExceptionToReport]; + // Retrieve trackerId from GoogleService-Info.plist. + NSString *googleServiceInfoPath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]; + NSDictionary *googleServiceInfo = [NSDictionary dictionaryWithContentsOfFile:googleServiceInfoPath]; + NSString *gaTrackingID = [googleServiceInfo objectForKey:@"TRACKING_ID"]; + if (gaTrackingID) + { + // Catch and log crashes + [MXLogger logCrashes:YES]; + [MXLogger setBuildVersion:[AppDelegate theDelegate].build]; + + // Configure GAI options. + GAI *gai = [GAI sharedInstance]; + + // Disable GA UncaughtException: their crash reports are quite limited (100 first chars of the stack trace) + // Let's MXLogger manage them + gai.trackUncaughtExceptions = NO; + + // Initialize it with the app tracker ID + [gai trackerWithTrackingId:gaTrackingID]; + + // Set Google Analytics dispatch interval to e.g. 20 seconds. + gai.dispatchInterval = 20; + + // Check if there is crash log to send to GA + [self checkExceptionToReport]; + } + else + { + NSLog(@"[AppDelegate] Unable to find tracker id for Google Analytics"); + } } else if ([[NSUserDefaults standardUserDefaults] objectForKey:@"enableCrashReport"]) {