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.


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
    }
    
    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
    }
    
    Appboy.sharedInstance()!.logCustomEvent("Rover Block Tapped", withProperties: attributes)
}