Google Analytics
Google Analytics is an analytics product. You can track Rover events into it using the following sample integration. You may need to customize it to get the best value out of the tool.
Tracking Screen Views
After integrating both the Rover and Google Analytics SDKs into your project, your goal will be to send the Rover events to Google Analytics as suitable GA events.
NotificationCenter.default.addObserver(forName: ScreenViewController.screenPresentedNotification, object: nil, queue: nil) { notification in
let experience = notification.userInfo?[ScreenViewController.experienceUserInfoKey] as! Experience
let screen = notification.userInfo?[ScreenViewController.screenUserInfoKey] as! Screen
let block = notification.userInfo?[ScreenViewController.blockUserInfoKey] as! Block
let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String
guard let tracker = GAI.sharedInstance().defaultTracker else { return }
tracker.set(kGAIScreenName, value: "Rover / \(experience.name) / \(screen.name)")
guard let builder = GAIDictionaryBuilder.createScreenView() else { return }
tracker.send(builder.build() as [NSObject : AnyObject])
}
Additional Events
Rover Block Tapped
NotificationCenter.default.addObserver(forName: ScreenViewController.blockTappedNotification, object: nil, queue: nil) { notification in
let block = notification.userInfo?[ScreenViewController.blockUserInfoKey] as! Block
let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String
guard let tracker = GAI.sharedInstance().defaultTracker else { return }
guard let builder = GAIDictionaryBuilder.createEvent(withCategory: "Rover Block", action: "Tapped", label: block.name, value: nil) else { return }
tracker.send(builder.build() as [NSObject : AnyObject])
}
Rover Poll Answered
NotificationCenter.default.addObserver(forName: ScreenViewController.pollAnsweredNotification, object: nil, queue: nil) { notification in
let experience = notification.userInfo?[ExperienceViewController.experienceUserInfoKey] as! Experience
let screen = notification.userInfo?[ScreenViewController.screenUserInfoKey] as! Screen
let block = notification.userInfo?[ScreenViewController.blockUserInfoKey] as! PollBlock
let option = notification.userInfo?[ScreenViewController.optionUserInfoKey] as! PollOption
let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String
guard let tracker = GAI.sharedInstance().defaultTracker else { return }
guard let builder = GAIDictionaryBuilder.createEvent(withCategory: "Rover Poll", action: "Answered", label: option.text.rawValue, value: nil) else { return }
tracker.send(builder.build() as [NSObject : AnyObject])
}
Custom Dimensions
If you wish to track additional information from Rover into Google Analytics, you may do so using Custom Dimensions.
You must manually create Custom Dimensions in your Google Analytics settings web interface for any Rover properties you wish to include before you continue.
Then, using the indices you assigned to the Rover properties of interest, you
will set them as the names for the parameters for the Rover properties on GA’s
tracker
object used above in the above examples.
The following are code snippets you may use within the above examples for tracking the Screen View, Block Tapped, and Poll Tapped respectively. They include most of the Rover properties you might like to use as Google Analytics custom dimensions.
NB. For the purposes of illustration, we have numbered them from Custom Dimension index #1, but in your setup they may well be different.
For Screen Views:
let tracker = ... // insert the following lines after this one:
tracker.set(GAIFields.customDimension(for: 1), value: experience.id)
tracker.set(GAIFields.customDimension(for: 2), value: experience.name)
tracker.set(GAIFields.customDimension(for: 3), value: screen.id)
tracker.set(GAIFields.customDimension(for: 4), value: screen.name)
For the “Rover Block Tapped” event:
// insert after the above:
tracker.set(GAIFields.customDimension(for: 5), value: block.id)
tracker.set(GAIFields.customDimension(for: 6), value: block.name)
And finally, you may include the following for “Rover Poll Answered”:
// insert after the above:
tracker.set(GAIFields.customDimension(for: 7), value: option.id)