Reporting Pageviews Using Swift 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 typeUnique attributeMethod
Homepage--reportHomePageView
CategoryCategories: A full hierarchy of category names. Category names must be identical to the categories in the product feed, including capitalization.reportCategoryPageView
ProductSKU: A string of the main SKU in the page. Must match a SKU in the product feed.reportProductPageView
CartCart: A list of SKUs in the cart. Must match SKUs in the product feed.
If the cart is empty pass an empty list.
reportCartPageView
OtherData: 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

ParameterData Structure Type
pageLocation
Required
String
pageReferrerString? = nil
pageLocaleString? = nil

Example

func reportHomePageView() async {
        let result = await DYSdk.shared().pageViews.reportHomePageView(
            pageLocation: "screenName",
            pageReferrer: "otherScreenName", // Optional
            pageLocale: "en" // Optional
        )

        switch result.status {
        case .success:
            // A pageview has been reported successfully
            break

        case .warning:
            // A pageview has been reported successfully, however, warnings have been returned
            if let warnings = result.warnings {
                // Handle the warnings
            }

        case .error:
            // Failed
            if let error = result.error {
                // Handle the error
            }
        }
    }

reportCategoryPageView

Returns DYResult

ParameterData Structure Type
categories (required)[String]?
pageLocation (required)String
pageReferrerString? = nil
pageLocaleString? = nil

Example

  func reportCategoryPageView() async {
        let result = await DYSdk.shared().pageViews.reportCategoryPageView(
            pageLocation: "screenName",
            categories: ["category-1", "category-2"],
            pageReferrer: "otherScreenName", // Optional
            pageLocale: "en" // Optional
        )
    }

reportProductPageView

Returns DYResult

ParameterData Structure Type
sku
Required)
String
pageLocation
Required)
String
pageReferrerString? = nil
pageLocaleString? = nil

Example

 func reportProductPageView() async {
        let result = await DYSdk.shared().pageViews.reportProductPageView(
            pageLocation: "screenName",
            sku: "sku-1"
        )

        switch result.status {
        case .success:
            // A pageview has been reported successfully
            break

        case .warning:
            // A pageview has been reported successfully, however, warnings have been returned
            if let warnings = result.warnings {
                // Handle the warnings
            }

        case .error:
            // Failed
            if let error = result.error {
                // Handle the error
            }
        }
    }

reportCartPageView

Returns DYResult

ParameterData Structure Type
cart
Required)
[String]?
pageLocation
Required)
String
pageReferrerString? = nil
pageLocaleString? = ni

Example

 func reportCartPageView() async {
        let result = await DYSdk.shared().pageViews.reportCartPageView(
            pageLocation: "screenName",
            cart: ["sku-1","sku-2"]
        )

        switch result.status {
        case .success:
            // A pageview has been reported successfully
            break

        case .warning:
            // A pageview has been reported successfully, however, warnings have been returned
            if let warnings = result.warnings {
                // Handle the warnings
            }

        case .error:
            // Failed
            if let error = result.error {
                // Handle the error
            }
        }
    }

reportOtherPageView

Returns DYResult

ParameterData Structure Type
data
Required)
String
pageLocation
Required)
String
pageReferrerString? = nil
pageLocaleString? = nil

Example

   func reportOtherPageView() async {
        let result = await DYSdk.shared().pageViews.reportOtherPageView(
            pageLocation: "screenName",
            data: "otherData"
        )

        switch result.status {
        case .success:
            // A pageview has been reported successfully
            break

        case .warning:
            // A pageview has been reported successfully, however, warnings have been returned
            if let warnings = result.warnings {
                // Handle the warnings
            }

        case .error:
            // Failed
            if let error = result.error {
                // Handle the error
            }
        }
    }