Localytics

Localytics is an analytics and marketing automation product. You can track Rover events into Localytics 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.


Mapping Rover Events to Localytics Events

After integrating both the Rover and Localytics SDKs into your project, your goal will be to send the Rover events to Localytics as Localytics custom events. You can also tag Rover Experiences and Experience Screens as content to Localytics.


Experience Presented

Use the Localytics Content Viewed tag:

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
    }
    
    Localytics.tagContentViewed(experience.name, contentId: experience.id, contentType: "Rover Experience", attributes: attributes)
}

Experience Dismissed

Use the Localytics generic Event:

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
    }
    
    Localytics.tagEvent("Rover Experience Dismissed", attributes: attributes)
}

Experience Viewed

This event describes the session (duration, primarily) spent viewing a Rover Experience. It does not map directly to any Localytics concept, so use the Localytics generic Event:

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
    }
    
    Localytics.tagEvent("Rover Experience Viewed", attributes: attributes)
}

Screen Presented

Use the Localytics Content Viewed tag:

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
    }
    
    Localytics.tagContentViewed(screen.name, contentId: screen.id, contentType: "Rover Screen", attributes: attributes)
}

Screen Dismissed

Use the Localytics generic Event:

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
    }
    
    Localytics.tagEvent("Rover Screen Dismissed", attributes: attributes)
}

Screen Viewed

This event describes the session (duration, primarily) spent viewing an individual screen within a Rover Experience. It does not map directly to any Localytics concept, so use the Localytics generic Event:

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
    }
    
    Localytics.tagEvent("Rover Screen Viewed", attributes: attributes)
}

Block Tapped

Use the Localytics generic Event:

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
    }
    
    Localytics.tagEvent("Rover Block Tapped", attributes: attributes)
}

Poll Answered

Use the Localytics generic Event:

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
    
    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
    }
    
    Localytics.tagEvent("Rover Poll Answered", attributes: attributes)
}