Firebase 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.

Note that Google directs you to use Google Analytics for Firebase on Android as opposed to the old Google Analytics SDK for Android.


Mapping Rover Events to Google Analytics Events

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.


Create a Listener for Rover Events

Rover.shared?.eventEmitter?.addEventListener(object : RoverEventListener {
     // see below for implementations.
}

Experience Presented

Use a Google Analytics Screen View.

override fun onExperiencePresented(event: RoverEvent.ExperiencePresented) {
    val properties = Bundle()
    properties.putString("experienceID", event.experience.id)
    properties.putString("experienceName", event.experience.name)
    if(event.campaignId != null) {
        properties.putString("campaignID", event.campaignId)
    }

    firebaseAnalytics.logEvent(
        "rover_experience_presented",
        properties
    )
}

Experience Dismissed

Use a generic Google Analytics event:

override fun onExperienceDismissed(event: RoverEvent.ExperienceDismissed) {
    val properties = Bundle()
    properties.putString("experienceID", event.experience.id)
    properties.putString("experienceName", event.experience.name)
    if(event.campaignId != null) {
        properties.putString("campaignID", event.campaignId)
    }

    firebaseAnalytics.logEvent(
        "rover_experience_dismissed",
        properties
    )
}

Experience Viewed

This event describes the session (duration, primarily) spent viewing a Rover Experience. Google Analytics’ built-in session tracking does not give you a way to distinguish between separate experiences, so we’ll manually track session information computed by Rover itself instead.

override fun onExperienceViewed(event: RoverEvent.ExperienceViewed) {
    val properties = Bundle()
    properties.putString("experienceID", event.experience.id)
    properties.putString("experienceName", event.experience.name)
    properties.putInt("duration", event.duration)
    if(event.campaignId != null) {
        properties.putString("campaignID", event.campaignId)
    }

    firebaseAnalytics.logEvent(
        "rover_experience_viewed",
        properties
    )
}

Screen Presented

Use a Google Analytics Screen View. This will also start a Google Analytics session for the experience screen.

override fun onScreenPresented(event: RoverEvent.ScreenPresented) {
    val properties = Bundle()
    properties.putString("experienceID", event.experience.id)
    properties.putString("experienceName", event.experience.name)
    properties.putString("screenID", event.screen.id)
    properties.putString("screenName", event.screen.name)
    if(event.campaignId != null) {
        properties.putString("campaignID", event.campaignId)
    }

    firebaseAnalytics.logEvent(
        "rover_screen_presented",
        properties
    )
}

Screen Dismissed

Use a generic Google Analytics event:

override fun onScreenDismissed(event: RoverEvent.ScreenDismissed) {
    val properties = Bundle()
    properties.putString("experienceID", event.experience.id)
    properties.putString("experienceName", event.experience.name)
    properties.putString("screenID", event.screen.id)
    properties.putString("screenName", event.screen.name)
    if(event.campaignId != null) {
        properties.putString("campaignID", event.campaignId)
    }

    firebaseAnalytics.logEvent(
        "rover_screen_dismissed",
        properties
    )
}

Screen Viewed

This event describes the session (duration, primarily) spent viewing a Rover Experience. Google Analytics’ built-in session tracking does not give you a way to distinguish between separate experiences, so we’ll manually track session information computed by Rover itself instead.

override fun onScreenViewed(event: RoverEvent.ScreenViewed) {
    val properties = Bundle()
    properties.putString("experienceID", event.experience.id)
    properties.putString("experienceName", event.experience.name)
    properties.putString("screenID", event.screen.id)
    properties.putString("screenName", event.screen.name)
    properties.putInt("duration", event.duration)
    if(event.campaignId != null) {
        properties.putString("campaignID", event.campaignId)
    }

    firebaseAnalytics.logEvent(
        "rover_screen_viewed",
        properties
    )
}

Block Tapped

Use a Google Analytics event:

override fun onBlockTapped(event: RoverEvent.BlockTapped) {
    val properties = Bundle()
    properties.putString("experienceID", event.experience.id)
    properties.putString("experienceName", event.experience.name)
    properties.putString("screenID", event.screen.id)
    properties.putString("screenName", event.screen.name)
    properties.putString("blockID", event.block.id)
    properties.putString("blockName", event.block.name)
    if(event.campaignId != null) {
        properties.putString("campaignID", event.campaignId)
    }

    firebaseAnalytics.logEvent(
        "rover_block_tapped",
        properties
    )
}