Rutger Huijsmans Rutger Huijsmans - 5 days ago 6
Swift Question

Setting up Google Analytics iOS Swift

I'm trying to setup Google analytics for my app but I do not know how to make a distinction between Production and Testing environments. I also do not how to track a specific user. Are these points even possible?

How I'm currently able to measure if ANYONE lands on a screen in ANY environment is through the following code:

let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: "LandingViewController")

let builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])


What I want to do is:

- post a user id along with the information logged by GA

- post the APIs base URL that the environment is using back to GA

Answer

One way to do this is to send the user id and the api base URL as custom dimensions. See https://support.google.com/analytics/answer/2709828?hl=en

tracker.set(GAIFields.customDimensionForIndex(1), value: userId)
tracker.set(GAIFields.customDimensionForIndex(2), value: baseURL)

Another way to distinguish between Production and Testing is to set up an entirely separate tracking id for Testing - as mentioned by Marta

Comments