1
votes

I am trying to send custom dimensions as data from my app to the google analytics dashboard. I have successfully got screenviews and events showing in Google Analytics.

Below is my code for sending the custom dimension

  func logScreenTrackingWithCustomDimension(screenName: String, data: AnyObject) {     
    let customDimension =  data
                let tracker = GAI.sharedInstance().defaultTracker
                tracker.set(GAIFields.customDimensionForIndex(1), value: customDimension as! String)
                tracker.set(kGAIScreenName, value: screenName)
                tracker.send(GAIDictionaryBuilder.createScreenView().set(customDimension as! String, forKey: GAIFields.customDimensionForIndex(1)).build() as NSDictionary as [NSObject : AnyObject])
            }

the function argument "data" is the string value I am passing in from another controller where I call this function.

I have also set up the dimension correctly within google analytics

P.S i am tracking screenviews and events for the above code and they show up in google analytics. Just not the actual data of the dimension which is not being tracked for some reason

Any help would really be appreciated because I am trying to track a product ID when click on a product screen. This will enable me to see what products are being viewed etc.

Thanks

1

1 Answers

0
votes

For dimensions, use this:

let customDimension =  data as! String
tracker.set(GAIFields.customDimension(for: UInt(indexNo)), value: customDimension)