Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics not working with Swift 1.2 and Xcode 6.3 [duplicate]

I tried to use Google Analytics with my Swift 1.2 app using Xcode 6.3beta.

My bridging header works fine and contains:

#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"

I tried the following Swift code to track a page:

  var tracker2:GAITracker = GAI.sharedInstance().defaultTracker as GAITracker
  tracker2.set(kGAIScreenName, value:"Home Screen")
  tracker2.send(GAIDictionaryBuilder.createScreenView().build())

But the last line above raises the following error:

Cannot invoke 'send' with an argument list of type '(NSMutableDictionary!)'

I found similar questions like: Google Analytics not initialising in Swift, Using Google Analytics with Swift on iOS

What do I have to change to make the code above working with Swift 1.2?

like image 253
confile Avatar asked Apr 12 '15 16:04

confile


People also ask

How do I use Google Analytics with Swift?

simple bridging header file. Just add #import <Google/Analytics. h> in bridging header file. add import Google in every file you want to implement google analytics.

Does Google Analytics work on iOS?

Use Tag Manager with Google Analytics and Firebase. To get the latest mobile app report features in Google Analytics, use Firebase in your Android and iOS apps. Once enabled in your app, Google Analytics will automatically collect and report on built-in events and user properties.


1 Answers

I had the same problem. Here is how I got it to work

let build = GAIDictionaryBuilder.createAppView().set(screenName, forKey: kGAIScreenName).build() as NSDictionary
tracker.send(build as [NSObject : AnyObject])
like image 131
Vidal Graupera Avatar answered Sep 20 '22 03:09

Vidal Graupera