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?
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.
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.
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With