Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Google Analytics in Swift 2 or 3

I have a problem with Swift 2 (Swift 3) and Google Analytics.

This is the line with the problem:

tracker.send(GAIDictionaryBuilder.createScreenView().build()) 

Xcode tell's me:

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

like image 963
BilalReffas Avatar asked Apr 09 '15 18:04

BilalReffas


People also ask

How do I add Google Analytics to 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.

What is analytics in Swift?

Analytics-Swift enables you to process and track the history of a payload, while Segment controls the API and prevents unintended operations. Analytics-Swift also offers default implementations to help you maintain destinations and integrations.

What is Google Analytics in android?

Google Analytics collects usage and behavior data for your web app. The SDK logs two primary types of information: Events: What is happening in your app, such as user actions, system events, or errors.


2 Answers

Update for Swift 3 (2016.10.19)

let tracker = GAI.sharedInstance().defaultTracker let build = (GAIDictionaryBuilder.createScreenView().build() as NSDictionary) as! [AnyHashable: Any] tracker?.send(build) 

Still an ugly approach, let me know if there's an cleaner conversion.


Original

Same here, struggling to resolve tons of errors.

What I did (deprecated):

var build = GAIDictionaryBuilder.createAppView().build() as [NSObject : AnyObject] tracker.send(build) 

Edit (2015)

Thanks to @George Poulos. . Recently they updated the options, now createAppView is deprecated, should use createScreenView instead.

var build = GAIDictionaryBuilder.createScreenView().build() as [NSObject : AnyObject] tracker.send(build) 
like image 114
Shali Liu Avatar answered Sep 20 '22 19:09

Shali Liu


In addition to the accepted answer:

Changed this:

tracker.send(GAIDictionaryBuilder.createEventWithCategory("UX", action: "User sign in", label: nil, value: nil).build()) 

To this:

tracker.send(GAIDictionaryBuilder.createEventWithCategory("UX", action: "User sign in", label: nil, value: nil).build()  as [NSObject : AnyObject]) 
like image 42
Esqarrouth Avatar answered Sep 19 '22 19:09

Esqarrouth