Skip to content

Events and Analytics

Sam Woodall edited this page Feb 6, 2020 · 3 revisions

The RoverCampaigns SDK allows you to track events representing behaviors or actions users have taken in your app. These events can be used to trigger automated campaigns and viewed in analytics.

Screen Views

The most important event you will want to track is a "Screen Viewed" event. This should be tracked every time the user views a screen in your app. The trackScreenViewed(screenName, contentID, contentName) method on the EventQueueService is purpose-built for tracking screen views.

RoverCampaigns.shared?.resolve(EventQueueServiceInterface::class.java)?.trackScreenViewed(
    "Article Detail",
    "42",
    "Kawhi Leonard continues to impress Doc Rivers"
)

The trackScreenViewed(screenName, contentID, contentName) method accepts three parameters.

screenName

The screenName parameter is the only one that is required. It should be a static name that describes the current view of your app. In most cases the screenName should reflect the name of the Activity or Fragment the user is currently viewing. If a Fragment only represents a small portion of the screen in an Activity then only the Activity should track a "Screen Viewed" event. The screenName would be the name of the Activity. It is important that the screenName does not change and is consistent every time the event is tracked for a given screen. The screenName can be any valid string. It can contain special characters, spaces and its case will be preserved.

Slash Notation

If your app has many screens it can be useful to group screens into logical sections by using "Slash Notation". For example, if your app contains a "Stats" section with individual Fragments for "Team Stats" and "Player Stats" it is conventional to prefix their names with a common group name, separated by a slash:

  • screenName: "Stats / Player Stats"
  • screenName: "Stats / Team Stats"

This is helpful when viewing screen views in analytics and enables filtering by logical groups.

contentID and contentName

For screens that track dynamic content it can be useful to include information about what the screen is currently displaying. For example, an ArticleDetailActivity that fetches an article by ID and displays it to the user should include information about the current article when the screen is viewed. The contentID and contentName parameters are provided for this purpose. Lets revisit the code sample from above.

RoverCampaigns.shared?.resolve(EventQueueServiceInterface::class.java)?.trackScreenViewed(
    "Article Detail",
    "42",
    "Kawhi Leonard continues to impress Doc Rivers"
)

In this example the screenName is "Article Detail". This never changes. Every time the user views the screen corresponding to the ArticleDetailActivity the screenName will be the same. The contentID contains the ID of the specific article being viewed and the contentName contains the article's name or title.

Custom Events

For events other than screen views you can track events with the EventQueueService's trackEvent(event, attributes) method. Use these for discrete, transactional situations.

val attributes = mapOf("Beer Vendor" to "Duff")
val event = Event("Beer Purchased", attributes)

RoverCampaigns.shared?.resolve(EventQueueServiceInterface::class.java)?.trackEvent(event)
Clone this wiki locally