Data & Customization
Events and Analytics
The Rover 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 Rover's analytics features.
Rover
Naturally, Rover's own screens and experiences are tracked automatically - these APIs are only for tracking screen views for other features of your app or custom events.
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
method on the event is purpose-built for tracking screen views.
Swift:
Rover.shared?.resolve(EventQueue.self)?.trackScreenViewed(
screenName: "Article Detail",
contentID: "42",
contentName: "Kawhi Leonard continues to impress Doc Rivers"
)
Kotlin:
Rover.shared?.resolve(EventQueueServiceInterface::class.java)?.trackScreenViewed(
"Article Detail",
"42",
"Kawhi Leonard continues to impress Doc Rivers"
)
Only the first parameter, screenName, is required.
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 UIViewController
or Activity
/Fragment
the user is currently viewing. 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 views (and corresponding UIViewController
s) 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 "Article Detail View" view controller or fragment/activity 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.
*Swift:
Rover.shared?.resolve(EventQueue.self)?.trackScreenViewed(
screenName: "Article Detail",
contentID: "42",
contentName: "Kawhi Leonard continues to impress Doc Rivers"
)
Kotlin:
Rover.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 article detail view 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 EventQueue's addEvent()
method. Use these for discrete, transactional situations.
Swift:
Rover.shared?.resolve(EventQueue.self)?.addEvent(
EventInfo(
name: "Beer Purchased",
// You can specify a free-form dictionary here with simple types, such as Strings and Ints.
attributes: ["Beer Vendor": "Duff"]
)
)
Kotlin:
val attributes = mapOf("Beer Vendor" to "Duff")
val event = Event("Beer Purchased", attributes)
Rover.shared?.resolve(EventQueueServiceInterface::class.java)?.trackEvent(event)