Mixpanel

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

After integrating both the Rover and Mixpanel SDKs into your project, your goal will be to send the Rover events to Mixpanel as Mixpanel events.


Experience Viewed

We’ll use Mixpanel’s time and track methods to aggregate the Presented and Dismissed events so a duration will be calculated by Mixpanel.

NotificationCenter.default.addObserver(forName: ExperienceViewController.experiencePresentedNotification, object: nil, queue: nil) { notification in    
    Mixpanel.mainInstance().time(event: "Rover Experience Viewed")
}
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
    }
    
    Mixpanel.mainInstance().track(event: "Rover Experience Viewed", properties: attributes)
}

Screen Viewed

We’ll use Mixpanel’s time and track methods to aggragate the Presented and Dismissed events so a duration will be calculated by Mixpanel.

NotificationCenter.default.addObserver(forName: ScreenViewController.screenPresentedNotification, object: nil, queue: nil) { notification in
    Mixpanel.mainInstance().time(event: "Rover Screen Viewed")
}
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
    }
    
    Mixpanel.mainInstance().track(event: "Rover Screen Viewed", properties: 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
    }
    
    Mixpanel.mainInstance().track(event: "Rover Block Tapped", properties: attributes)
}