12

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?

Community
  • 1
  • 1
Michael
  • 32,527
  • 49
  • 210
  • 370

1 Answers1

24

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])
Vidal Graupera
  • 558
  • 5
  • 7