2017-01-03 12 views
1

Google Analyticsと統合されたObjective-Cアプリがあります。今、私はSwiftで書かれたアプリを統合しようとしています。Swiftのカスタム寸法

私のObjective-Cのコードがあります:

- (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]]; 
} 

と私は迅速

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()) 

    } 

にしようとしているが、私はGAIFieldsは一切のメンバーcustomDimensionを持っていないそうです。次に、Swiftのコードはどのようにすべきでしょうか?

答えて

1

それは私の仕事:

func signInGoogleAnalytics() { 
    let tracker = GAI.sharedInstance().defaultTracker 
    tracker.set(kGAIUserId, value: txtStore.text) 

    let dimensionUsuarioLogado = "\(txtUser.text)" 
    let dimensionLoja = "\(txtStore.text)" 

    tracker.send(GAIDictionaryBuilder.createScreenView().set(dimensionUsuarioLogado, forKey: GAIFields.customDimensionForIndex(1)).build() as NSDictionary as [NSObject : AnyObject]) 

    tracker.send(GAIDictionaryBuilder.createScreenView().set(dimensionLoja, forKey: GAIFields.customDimensionForIndex(2)).build() as NSDictionary as [NSObject : AnyObject]) 
}