Braze
Braze is an analytics and marketing automation product. You can track Rover events into Braze to use it for either or both using the following sample integration. You may need to customize it to get the best value out of the tool.
Sending Rover events to Braze
After integrating both the Rover and Braze SDKs into your project, your goal will be to send all the Rover events to Braze as Braze custom events.
Conversion Tracking
A method for including the Rover conversion tracking tags is to continually append them to a Braze custom attribute array. Braze arrays are ordered sets with a size limit that act as a FIFO (first-in, first-out), and so old conversion tracking tags will eventually rotate out of the Braze array, which typically have a limit of 100.
Experience Presented
NotificationCenter.default.addObserver(forName: ExperienceViewController.experiencePresentedNotification, object: nil, queue: nil) { notification in
let experience = notification.userInfo?[ExperienceViewController.experienceUserInfoKey] as! Experience
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name
]
if let campaignID = notification.userInfo?[ExperienceViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
Appboy.sharedInstance()!.logCustomEvent("Rover Experience Presented", withProperties: attributes)
}
Experience Dismissed
NotificationCenter.default.addObserver(forName: ExperienceViewController.experienceDismissedNotification, object: nil, queue: nil) { notification in
let experience = notification.userInfo?[ExperienceViewController.experienceUserInfoKey] as! Experience
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name
]
if let campaignID = notification.userInfo?[ExperienceViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
Appboy.sharedInstance()!.logCustomEvent("Rover Experience Dismissed", withProperties: attributes)
}
Experience Viewed
This event describes the session (duration, primarily) spent viewing a Rover Experience.
NotificationCenter.default.addObserver(forName: ExperienceViewController.experienceViewedNotification, object: nil, queue: nil) { notification in
let experience = notification.userInfo?[ExperienceViewController.experienceUserInfoKey] as! Experience
let duration = notification.userInfo?[ExperienceViewController.durationUserInfoKey] as! Double
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name,
"duration": String(describing: duration)
]
if let campaignID = notification.userInfo?[ExperienceViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
Appboy.sharedInstance()!.logCustomEvent("Rover Experience Viewed", withProperties: attributes)
}
Screen Presented
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
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name,
"screenID": screen.id,
"screenName": screen.name
]
if let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
Appboy.sharedInstance()!.logCustomEvent("Rover Screen Presented", withProperties: attributes)
}
Screen Dismissed
NotificationCenter.default.addObserver(forName: ScreenViewController.screenDismissedNotification, object: nil, queue: nil) { notification in
let experience = notification.userInfo?[ScreenViewController.experienceUserInfoKey] as! Experience
let screen = notification.userInfo?[ScreenViewController.screenUserInfoKey] as! Screen
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name,
"screenID": screen.id,
"screenName": screen.name
]
if let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
Appboy.sharedInstance()!.logCustomEvent("Rover Screen Dismissed", withProperties: attributes)
}
Screen Viewed
This event describes the session (duration, primarily) spent viewing an individual screen within a Rover Experience.
NotificationCenter.default.addObserver(forName: ScreenViewController.screenViewedNotification, object: nil, queue: nil) { notification in
let experience = notification.userInfo?[ScreenViewController.experienceUserInfoKey] as! Experience
let screen = notification.userInfo?[ScreenViewController.screenUserInfoKey] as! Screen
let duration = notification.userInfo?[ScreenViewController.durationUserInfoKey] as! Double
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name,
"screenID": screen.id,
"screenName": screen.name,
"duration": String(describing: duration)
]
if let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
if let conversionTag = screen.conversion?.tag {
Appboy.sharedInstance()?.user.addToCustomAttributeArray(withKey: "rover_conversions", value: conversionTag)
}
Appboy.sharedInstance()!.logCustomEvent("Rover Screen Viewed", withProperties: attributes)
}
Block Tapped
NotificationCenter.default.addObserver(forName: ScreenViewController.blockTappedNotification, 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
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name,
"screenID": screen.id,
"screenName": screen.name,
"blockID": block.id,
"blockName": block.name,
]
if let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
if let conversionTag = block.conversion?.tag {
Appboy.sharedInstance()?.user.addToCustomAttributeArray(withKey: "rover_conversions", value: conversionTag)
}
Appboy.sharedInstance()!.logCustomEvent("Rover Block Tapped", withProperties: attributes)
}
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 pollID = block.pollID(containedBy: experience.id)
let optionID = option.id
var attributes: [String: String] = [
"experienceID": experience.id,
"experienceName": experience.name,
"screenID": screen.id,
"screenName": screen.name,
"blockID": block.id,
"blockName": block.name,
"optionID": option.id,
"optionText": option.text.rawValue
]
if let campaignID = notification.userInfo?[ScreenViewController.campaignIDUserInfoKey] as? String {
attributes["campaignID"] = campaignID
}
// Retrieving poll option text to append selected poll answer to conversion tag
let formattedPollOption = option.text.rawValue.replacingOccurrences(of: " ", with: "_").lowercased()
if let conversionTag = block.conversion?.tag {
Appboy.sharedInstance()?.user.addToCustomAttributeArray(withKey: "rover_conversions", value: "\(conversionTag)_\(formattedPollOption)")
}
Appboy.sharedInstance()!.logCustomEvent("Rover Poll Answered", withProperties: attributes)
}