Reporting Events Using Swift SDK

Events are used to track meaningful user interactions (purchase, add to cart, form completion, rating a product, and so on) for the purpose of behavioral targeting, reporting, and recommendations. Learn more about Events.

Use the DYSdk object to report events to Dynamic Yield.

Required events per vertical

reportPurchaseEvent

Mandatory event for e-commerce sections

Returns DYResult

ParameterData Structure
name: String
Required
String
value: Float
Required
Float
currencyCurrencyType? = nil
uniqueTransactionIdString? = nil
cart
Required
[Cartinneritem]
CartInnerItem.productIdString
CartInnerItem.quantityInt
CartInnerItem.ItempriceFloat

Example

 func reportPurchaseEvent() async {
        let cartItems = [
            CartInnerItem(
                productId: "product-id",
                quantity: 2,
                itemPrice: 8.0
            )
        ]

        let result = await DYSdk.shared().events.reportPurchaseEvent(
            eventName: "purchase-event",
            value: 5.3,
            currency: .idr,
            uniqueTransactionId: "unique-id",
            cart: cartItems
        )
        // Check the result status
    }

reportAddToCartEvent

Mandatory event for e-commerce sections

Returns DYResult

ParameterData Structure
name
Required
String
value
Required
Float
currencyCurrencyType? = nil
quantity
Required
Int
productId
Required
String
cart<CartInnerItem>? = nil
CartInnerItem.productIdString
CartInnerItem.quantityInt
CartInnerItem.ItempriceFloat

Example

 func reportAddToCartEvent() async {
        let cartItems = [
            CartInnerItem(
                productId: "product-id-red-shirt",
                quantity: 2,
                itemPrice: 8.0
            )
        ]

        let result = await DYSdk.shared().events.reportAddToCartEvent(
            eventName: "add-to-cart-event",
            value: 5.3,
            currency: .idr,
            productId: "product-id",
            quantity: 3,
            cart: cartItems
        )
        // Check the result status
    }

reportApplicationEvent

Mandatory event for Financial Institute sections

Returns DYResult

ParameterData Structure
name
Required
String
value
Required
Float
currencyCurrencyType? = nil
quantity
Required
Int
productId
Required
String
cart[CartInnerItem]? = nil
CartInnerItem.productIdString
CartInnerItem.quantityInt
CartInnerItem.ItempriceFloat

Example

func reportApplicationEvent() async {
        let cartItems = [
            CartInnerItem(
                productId: "application-id",
                quantity: 2,
                itemPrice: 8.0
            )
        ]

        let result = await DYSdk.shared().events.reportApplicationEvent(
            eventName: "application-event",
            value: 5.3,
            currency: .idr,
            productId: "application-id",
            quantity: 3,
            cart: cartItems
        )
        // Check the result status
    }

reportSubmissionEvent

Mandatory event for Financial Institute sections

Returns DYResult

ParameterData Structure
name: String
Required
String
value: Float
Required
Float
currencyCurrencyType? = nil
uniqueTransactionIdString? = nil
cart:
Required
[CartInnerItem]
CartInnerItem.productIdString
CartInnerItem.quantityInt
CartInnerItem.ItempriceFloat

Example

  func reportSubmissionEvent() async {
        let cartItems = [
            CartInnerItem(
                productId: "product-id",
                quantity: 2,
                itemPrice: 8.0
            )
        ]

        let result = await DYSdk.shared().events.reportSubmissionEvent(
            eventName: "submission-event",
            value: 5.3,
            currency: .idr,
            uniqueTransactionId: "unique-id",
            cart: cartItems
        )
        // Check the result status
    }

Events used for cross-channel identification

reportSignUpEvent

Returns DYResult

ParameterData Structure
name
Required
String
cuidTypeString?
cuidString? = nil
secondaryIdentifiers[SecondaryIdentifier]? =nil
secondaryIdentifiers.typeString
secondaryIdentifiers.valueString

Example

  func reportSignUpEvent() async {
        let secondaryIdentifiers = [
            SecondaryIdentifier(
                type: "phoneNumber",
                value: "+972503803434"
            )
        ]

        let result = await DYSdk.shared().events.reportSignUpEvent(
            eventName: "sign-in-event",
            cuidType: "email",
            cuid: "cuid",
            secondaryIdentifiers: secondaryIdentifiers
        )
        // Check the result status
    }

reportLoginEvent

Returns DYResult

ParameterData Structure
name
Required
String
cuidType
Required
String
cuid
Required
String? = nil
secondaryIdentifiers[SecondaryIdentifier]? =nil
secondaryIdentifiers.typeString
secondaryIdentifiers.valueString

Example

  func reportLoginEvent() async {
        let secondaryIdentifiers = [
            SecondaryIdentifier(
                type: "phoneNumber",
                value: "+972503803434"
            )
        ]

        let result = await DYSdk.shared().events.reportLoginEvent(
            eventName: "log-in-event",
            cuidType: "email",
            cuid: "cuid",
            secondaryIdentifiers: secondaryIdentifiers
        )
        // Check the result status
    }

reportIdentifyUserEvent

Returns DYResult

ParameterData Structure
name
Required
String
cuidType
Required
String
cuidString? = nil
secondaryIdentifiers[SecondaryIdentifier]? =nil
secondaryIdentifiers.typeString
secondaryIdentifiers.valueString

Example

func reportIdentifyUserEvent() async {
        let secondaryIdentifiers = [
            SecondaryIdentifier(
                type: "phoneNumber",
                value: "+972503803434"
            )
        ]

        let result = await DYSdk.shared().events.reportIdentifyUserEvent(
            eventName: "identify-user-id-event",
            cuidType: "email",
            cuid: "cuid",
            secondaryIdentifiers: secondaryIdentifiers
        )
        // Check the result status
    }

reportNewsletterEvent

Returns DYResult

ParameterData Structure
name
Required
String
cuidTypeString?
cuidString? = nil
secondaryIdentifiers[SecondaryIdentifier]? =nil
secondaryIdentifiers.typeString
secondaryIdentifiers.valueString

Example

    func reportNewsletterEvent() async {
        let secondaryIdentifiers = [
            SecondaryIdentifier(
                type: "phoneNumber",
                value: "+972503803434"
            )
        ]

        let result = await DYSdk.shared().events.reportNewsletterEvent(
            eventName: "news-letter-event",
            cuidType: "email",
            cuid: "cuid",
            secondaryIdentifiers: secondaryIdentifiers
        )
        // Check the result status
    }

Additional event schemas

reportRemoveFromCartEvent

Returns DYResult

ParameterData Structure
name
Required
String
value
Required
Float
quantity
Required
int
productId
Required
String
currencyCurrencyType? = nil
cart[CartInnerItem]? = nil
CartInnerItem.productIdString
CartInnerItem.quantityint
CartInnerItem.ItempriceFloat

Example

 func reportRemoveFromCartEvent() async {
        let cartItems = [
            CartInnerItem(
                productId: "product-id",
                quantity: 2,
                itemPrice: 8.0
            )
        ]

        let result = await DYSdk.shared().events.reportRemoveFromCartEvent(
            eventName: "submission-event",
            value: 5.3,
            currency: .idr,
            productId: "product-id",
            quantity: 1,
            cart: cartItems
        )
        // Check the result status
    }

reportSyncCartEvent

Returns DYResult

ParameterData Structure
name
Required
String
value
Required
Float
currency
Required
CurrencyType? = nil
cart[CartInnerItem]? = nil
CartInnerItem.productIdString
CartInnerItem.quantityint
CartInnerItem.ItempriceFloat

Example

 func reportSyncCartEvent() async {
        let cartItems = [
            CartInnerItem(
                productId: "product-id",
                quantity: 2,
                itemPrice: 8.0
            )
        ]

        let result = await DYSdk.shared().events.reportSyncCartEvent(
            eventName: "submission-event",
            value: 5.3,
            currency: .idr,
            cart: cartItems
        )
        // Check the result status
    }

reportMessageOptInEvent

Returns DYResult

ParameterData Structure
name
Required
String
cuidType
Required
CuidType
plainTextEmailString?
externalIdString?l

Example

 func reportMessageOptInEvent() async {
        let result = await DYSdk.shared().events.reportMessageOptInEvent(
            eventName: "message-opt-in-event",
            cuidType: .email,
            plainTextEmail: "a@a",
            externalId: "externalId"
        )
        // Check the result status
    }

reportMessageOptOutEvent

Returns DYResult

ParameterData Structure
name
Required
String
cuidType
Required
CuidType
plainTextEmailString?
externalIdString?l

Example

  func reportMessageOptOutEvent() async {
        let result = await DYSdk.shared().events.reportMessageOptOutEvent(
            eventName: "message-opt-out-event",
            cuidType: .email,
            plainTextEmail: "a@a",
            externalId: "externalId"
        )
        // Check the result status
    }

reportInformAffinityEvent

Returns DYResult

ParameterData Structure
name
Required
String
sourceString? = nil
data
Required
[InformAffinityData]

Example

func reportInformAffinityEvent() async {
        let data = [
            InformAffinityData(
                attribute: "attribute",
                values: ["value-1", "value-2"]
            )
        ]

        let result = await DYSdk.shared().events.reportInformAffinityEvent(
            eventName: "report-inform-affinity",
            source: "source",
            data: data
        )
        // Check the result status
    }

reportAddToWishListEvent

Returns DYResult

ParameterData Structure
name
Required
String
productId
Required
String
sizeString? =nil

Example

 func reportAddToWishListEvent() async {
        let result = await DYSdk.shared().events.reportAddToWishListEvent(
            eventName: "add-to-wish-list-event",
            productId: "productId",
            size: "medium"
        )
    }

reportVideoWatchEvent

Returns DYResult

ParameterData Structure
name
Required
String
itemId
Required
String
autoplay
Required
Boolean
progress
Required
VideoProgressType
progressPercent
Required
CurrencyType? = nil
categories[String]? =nil

Example

 func reportVideoWatchEvent() async {
        let result = await DYSdk.shared().events.reportVideoWatchEvent(
            eventName: "report-video-watch-event",
            itemId: "itemId",
            categories: ["category-1", "category-2"],
            autoplay: true,
            progress: .videoProgress,
            progressPercent: 3
        )
        // Check the result status
    }

reportKeywordSearchEvent

Returns DYResult

ParameterData Structure
name
Required
String
keywords
Required
String

Example

func reportKeywordSearchEvent() async {
        let result = await DYSdk.shared().events.reportKeywordSearchEvent(
            eventName: "keyword-search-event",
            keywords: "search"
        )
        // Check the result status
    }

reportChangeAttributesEvent

Returns DYResult

ParameterData Structure
name
Required
String
attributeType
Required
String
attributeValue
Required
String

Example

  func reportChangeAttributesEvent() async {
        let result = await DYSdk.shared().events.reportChangeAttributesEvent(
            eventName: "change-attribute-event",
            attributeType: "price",
            attributeValue: "5"
        )
        // Check the result status
    }

reportFilterItemsEvent

Returns DYResult

ParameterData Structure
name
Required
String
filterType
Required
String
filterStringValueString? = nil
filterNumericValue
Required
int?=nil

Example

 func reportFilterItemsEvent() async {
        let result = await DYSdk.shared().events.reportFilterItemsEvent(
            eventName: "filter-items-event",
            filterType: "someType"
            filterStringValue: "value")
        // Check the result status
    }

reportSortItemsEvent

Returns DYResult

ParameterData Structure
name
Required
String
sortBy
Required
String
sortOrder
Required
SortOrderType

Example

func reportSortItemsEvent() async {
        let result = await DYSdk.shared().events.reportSortItemsEvent(
            eventName: "sort-items-event",
            sortBy: "price",
            sortOrder: .asc
        )
        // Check the result status
    }

reportPromoCodeEnterEvent

Returns DYResult

ParameterData Structure
name
Required
String
code
Required
Float

Example

   func reportPromoCodeEnterEvent() async {
        let result = await DYSdk.shared().events.reportPromoCodeEnterEvent(
            eventName: "promoCodeEvent",
            code: "code-example"
        )

        switch result.status {
        case .success:
            // Event reported successfully
            break
        case .warning:
            // Event reported successfully with warnings received from the server
            if let warnings = result.warnings {
                // Handle warnings
            }
            break
        case .error:
            // Failed
            if let error = result.error {
                // Handle the error
            }
            break
        }
    }

Custom Events

Use custom events to report events that are not defined in the SDK but are significant to your business.

reportCustomEvents

Returns DYResult

ParameterData Structure
name
Required
[DYEvent]
properties
Required
CustomProperties

Example

 func reportCustomEvent() async {
        let result = await DYSdk.shared().events.reportCustomEvents(
            name: "custom-event-name",
            properties: MyCustomProperties(color: "yellow", size: 8)
        )

        switch result.status {
        case .success:
            // Event reported successfully
            break
        case .warning:
            // Event reported successfully with warnings from the server
            if let warnings = result.warnings {
                // Handle warnings
            }
        case .error:
            // Failed
            if let error = result.error {
                // Handle the error
            }
        }
    }

Reporting multiple events

reportEvents

Returns DYResult

ParameterData Structure
DYEvent
Required
[DYEvent]

Example

 func reportMultiEvent() async {
        let result = await DYSdk.shared().events.reportEvents(
            events: DYEvent(
                name: "promo-code-event",
                properties: PromoCodeEnterEventProperties(code: "code-example")
            ),
            DYEvent(
                name: "keyword-search-event",
                properties: KeywordSearchEventProperties(keywords: "word-example")
            )
        )
    }

    struct MyCustomProperties: CustomProperties {
        var color: String
        var size: Int
    }