Reporting Pageviews Using Kotlin SDK
To report a page view to Dynamic Yield for every screen viewed on your native app, use one of the methods described in the following table. Select the appropriate method based on the page type.
Note: If you have already called chooseVariations on a page with isImplicitImpressionMode set to true, do not report a page view. This would result in the same page view twice.
Page types and reporting methods
Page type | Unique attribute | Method |
---|---|---|
Homepage | -- | reportHomePageView |
Category | Categories: A full hierarchy of category names. Category names must be identical to the categories in the product feed, including capitalization. | reportCategoryPageView |
Product | SKU: A string of the main SKU in the page. Must match a SKU in the product feed. | reportProductPageView |
Cart | Cart: A list of SKUs in the cart. Must match SKUs in the product feed. If the cart is empty pass an empty list. | reportCartPageView |
Other | Data: A label to help identify other screen types. | reportOtherPageView |
All methods include the following additional attributes:
- pageLocation: The name of the screen.
- pageReferrer: The name of the previous screen.
- pageLocale: The language version of a page that was displayed, such as en_US. Use it only if you want to override the locale you previously set in the initialize method. Learn more about using country codes for locale.
reportHomePageView
Returns DYResult
Parameter | Data Structure Type |
---|---|
pageLocation Required | String |
pageReferrer | String? = null |
pageLocale | String? = null |
Example
private suspend fun reportHomePageView() {
var result = DYSdk.getInstance().pageViews.reportHomePageView(
pageLocation = "screenName",
pageReferrer = "otherScreenName", //Optional
pageLocale = "en" //Optional
)
when (result.status) {
ResultStatus.SUCCESS -> {
//A pageview has been reported successfully
}
ResultStatus.WARNING -> {
// A pageview has been reported successfully, however, warnings have been returned
result.warnings?.let { warnings ->
}
}
ResultStatus.ERROR -> {
//Failed
result.error?.let {
//Handle the error
}
}
}
}
reportCategoryPageView
Returns DYResult
Parameter | Data Structure Type |
---|---|
categories (required) | List<String>? |
pageLocation (required) | String |
pageReferrer | String? = null |
pageLocale | String? = null |
Example
private suspend fun reportCategoryPageView() {
var result = DYSdk.getInstance().pageViews.reportCategoryPageView(
pageLocation = "screenName",
categories = listOf("category-1", "category-2"),
pageReferrer = "otherScreenName", //Optional
pageLocale = "en" //Optional
)
}
reportProductPageView
Returns DYResult
Parameter | Data Structure Type |
---|---|
sku Required) | String |
pageLocation Required) | String |
pageReferrer | String? = null |
pageLocale | String? = null |
Example
private suspend fun reportProductPageView() {
var result = DYSdk.getInstance().pageViews.reportProductPageView(
pageLocation = "productScreen",
sku = "SKU123",
pageReferrer = "homeScreen",
pageLocale = "en",
)
}
reportCartPageView
Returns DYResult
Parameter | Data Structure Type |
---|---|
cart Required) | List<String>? |
pageLocation Required) | String |
pageReferrer | String? = null |
pageLocale | String? = null |
Example
private suspend fun reportCartPageView() {
var result = DYSdk.getInstance().pageViews.reportCartPageView(
pageLocation = "cartScreen",
cart = listOf("SKU123", "SKU456"),
pageReferrer = "homeScreen",
pageLocale = "en",
)
}
reportOtherPageView
Returns DYResult
Parameter | Data Structure Type |
---|---|
data Required) | String |
pageLocation Required) | String |
pageReferrer | String? = null |
pageLocale | String? = null |
Example
private suspend fun reportOtherPageView() {
var result = DYSdk.getInstance().pageViews.reportOtherPageView(
pageLocation = "payScreen",
data = "any-information",
pageReferrer = "homeScreen",
pageLocale = "en",
)
}
Updated 5 days ago