I have an Objective-C app that integrates with Google Analytics. Now, I'm trying to integrate an app written in Swift.
There's my Objective-C Code:
- (void) signInGoogleAnalytics {
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
// You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
// sent with all subsequent hits.
[tracker set:kGAIUserId
value:self.txtStoreCode.text];
NSString *dimensionUsuarioLogado = [NSString stringWithFormat:@"%@", _txtEmployee.text];
NSString *dimensionLoja = [NSString stringWithFormat:@"%@", _txtStoreCode.text];
[tracker send:[[[GAIDictionaryBuilder createScreenView] set:dimensionUsuarioLogado
forKey:[GAIFields customDimensionForIndex:1]] build]];
[tracker send:[[[GAIDictionaryBuilder createScreenView] set:dimensionLoja
forKey:[GAIFields customDimensionForIndex:2]] build]];
}
and I'm trying in swift
func signInGoogleAnalytics() {
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIUserId, value: txtStore.text)
var dimensionUsuarioLogado = "\(txtUser.text)"
var dimensionLoja = "\(txtStore.text)"
tracker.send(GAIDictionaryBuilder.createScreenView().set(dimensionUsuarioLogado, forKey: GAIFields.customDimension(forIndex: 1)).build())
tracker.send(GAIDictionaryBuilder.createScreenView().set(dimensionLoja, forKey: GAIFields.customDimension(forIndex: 1)).build())
}
but I'm getting GAIFields has no member customDimension. Then, how should be the code in Swift?
It worked for me: