I'm trying to use GA with a Swift project.
I installed the SDK correctly but I can't send Screen Measurements manually because some objects are not found.
Here's the code given by Google:
// May return nil if a tracker has not already been initialized with a
// property ID.
id tracker = [[GAI sharedInstance] defaultTracker];
// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:kGAIScreenName
value:@"Home Screen"];
// New SDK versions
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
Here's my code:
let tracker = GAI.sharedInstance()
tracker.setValue(kGai, forKey: "/index")
tracker.send(GAIDictionaryBuilder.createScreenView().build)
And here's the errors I get:
Use of unresolved identifier 'kGAIScreenName'
Use of unresolved identifier 'GAIDictionaryBuilder'
I imported GAI.h in my BridingHeader and added frameworks to the build file, no errors on this side.
Thanks!
OK so I just added GAI.h to my bridging header but didn't add others header files. And thanks DPLusV I also didn't translated correctly Obj-C to Swift.
Here is my final code which works:
[EDIT] SWIFT 3
I followed the instructions in
https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift
up till pod installation
I already had a GoogleService-Info.plist file there I enabled the google analytics
Then I did some hit and trial methods to make it work
And finally I found some thing which worked for me
I put this piece of code in View Controller(s) where ever it was needed.
Hope this help someone. Thanks