Reporting Events Using React Native 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

import { boolVal, CurrencyType, events, EventType, listVal, mapVal, numVal, SortOrderType, strVal, VideoProgressType, type SupportedValue } from '@DynamicYield/react-native-sdk'

async function reportPurchaseEvent() {
    await events.reportPurchaseEvent({
        name: "purchase-event",
        value: 5.3,
        currency: CurrencyType.IDR,
        uniqueTransactionId: "unique-id",
        cart: [
            {
                productId: "product-id",
                quantity: 2,
                itemPrice: 8
            }
        ]
    }).then((result) => {
        switch (result.status) {
            case 'SUCCESS':
                //A purchase event has been reported successfully
                break;
            case 'WARNING':
                result.warnings?.forEach(warning => {
                    // Log the warnings
                });
                break;
            case 'ERROR':
                const error = result.error
                //do something with the error
                break;
        }
    }).catch((error) => {
        //handle error
    });
}

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

async function reportAddToCartEvent() {
    await events.reportAddToCartEvent({
        name: "add-to-cart-event",
        value: 5.3,
        currency: CurrencyType.IDR,
        productId: "product-id",
        quantity: 3,
        cart: [
            {
                productId: "product-id-red-shirt",
                quantity: 2,
                itemPrice: 8
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

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

async function reportApplicationEvent() {
    await events.reportApplicationEvent({
        name: "application-event",
        value: 5.3,
        currency: CurrencyType.IDR,
        productId: "application-id",
        quantity: 3,
        cart: [
            {
                productId: "application-id",
                quantity: 2,
                itemPrice: 8
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

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

async function reportSubmissionEvent() {
    await events.reportSubmissionEvent({
        name: "submission-event",
        value: 5.3,
        currency: CurrencyType.IDR,
        uniqueTransactionId: "unique-id",
        cart: [
            {
                productId: "product-id",
                quantity: 2,
                itemPrice: 8
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

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

async function reportSignUpEvent() {
    await events.reportSignUpEvent({
        name: "sign-in-event",
        cuidType: "email",
        cuid: "cuid",
        secondaryIdentifiers: [
            {
                type: "phoneNumber",
                value: "+972503803434"
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportLoginEvent

Returns DYResult

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

Example

async function reportLoginEvent() {
    await events.reportLoginEvent({
        name: "log-in-event",
        cuidType: "email",
        cuid: "cuid",
        secondaryIdentifiers: [
            {
                type: "phoneNumber",
                value: "+972503803434"
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportIdentifyUserEvent

Returns DYResult

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

Example

async function reportIdentifyUserEvent() {
    await events.reportIdentifyUserEvent({
        name: "identify-user-id-event",
        cuidType: "email",
        cuid: "cuid",
        secondaryIdentifiers: [
            {
                type: "phoneNumber",
                value: "+972503803434"
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportNewsletterEvent

Returns DYResult

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

Example

 async function reportNewsletterEvent() {
    await events.reportNewsletterEvent({
        name: "news-letter-event",
        cuidType: "email",
        cuid: "cuid",
        secondaryIdentifiers: [
            {
                type: "phoneNumber",
                value: "+972503803434"
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

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

async function reportRemoveFromCartEvent() {
    await events.reportRemoveFromCartEvent({
        name: "submission-event",
        value: 5.3,
        currency: CurrencyType.IDR,
        productId: "product-id",
        quantity: 1,
        cart: [
            {
                productId: "product-id",
                quantity: 2,
                itemPrice: 8
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

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

async function reportSyncCartEvent() {
    await events.reportSyncCartEvent({
        name: "sync-cart-event",
        value: 5.3,
        currency: CurrencyType.IDR,
        cart: [
            {
                productId: "product-id",
                quantity: 2,
                itemPrice: 8
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportMessageOptInEvent

Returns DYResult

Note: We recommend implementing this event on the server-side where the push-id is generated.

ParameterData Structure
pushId
Required
String

Example

async function reportPushOptInEvent() {
    await events.reportPushOptInEvent({
        name: "report-push-opt-in-event",
        pushId: "97597d39-ed90-4cd4-8dba-99f8676d8348"
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportMessageOptOutEvent

Returns DYResult

Note: We recommend implementing this event on the server-side where the push-id is generated.

ParameterData Structure
pushId
Required
Stirng

Example

async function reportPushOptOutEvent() {
    await events.reportPushOptOutEvent({
        name: "report-push-opt-out-event",
        pushId: "97597d39-ed90-4cd4-8dba-99f8676d8348"
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportInformAffinityEvent

Returns DYResult

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

Example

async function reportInformAffinityEvent() {
    await events.reportInformAffinityEvent({
        name: "report-inform-affinity",
        source: "source",
        data: [
            {
                attribute: "attribute",
                values: ["value-1", "value-2"]
            }
        ]
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportAddToWishListEvent

Returns DYResult

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

Example

async function reportAddToWishListEvent() {
    await events.reportAddToWishListEvent({
        name: "add-to-wish-list-event",
        productId: "productId",
        size: "medium"
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

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

async function reportVideoWatchEvent() {
    await events.reportVideoWatchEvent({
        name: "report-video-watch-event",
        itemId: "itemId",
        categories: ["category-1", "category-2"],
        autoplay: true,
        progress: VideoProgressType.PREROLL_FINISHED,
        progressPercent: 3
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportKeywordSearchEvent

Returns DYResult

ParameterData Structure
name
Required
String
keywords
Required
String

Example

async function reportKeywordSearchEvent() {
    await events.reportKeywordSearchEvent({
        name: "keyword-search-event",
        keywords: "search"
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportChangeAttributesEvent

Returns DYResult

ParameterData Structure
name
Required
String
attributeType
Required
String
attributeValue
Required
String

Example

async function reportChangeAttributesEvent() {
    await events.reportChangeAttributesEvent({
        name: "change-attribute-event",
        attributeType: "price",
        attributeValue: "5"
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportFilterItemsEvent

Returns DYResult

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

Example

async function reportFilterItemsEvent() {
    await events.reportFilterItemsEvent({
        name: "filter-items-event",
        filterType: "someType",
        filterStringValue: "value"
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportSortItemsEvent

Returns DYResult

ParameterData Structure
name
Required
String
sortBy
Required
String
sortOrder
Required
SortOrderType

*Example

async function reportSortItemsEvent() {
    await events.reportSortItemsEvent({
        name: "sort-items-event",
        sortBy: "price",
        sortOrder: SortOrderType.ASC
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

reportPromoCodeEnterEvent

Returns DYResult

ParameterData Structure
name
Required
String
code
Required
Float

Example

async function reportSingleEvent() {
    await events.reportPromoCodeEnterEvent({
        name: "promoCodeEvent",
        code: "code-example"
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

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
String
properties
Required
CustomProperties

Example

async function reportCustomEvent() {
    await events.reportCustomEvent({
        name: "custom-event-name",
        map: new Map<string, SupportedValue>([
            ['color', strVal('red')],
            ['size', numVal(38)],
            ['list', listVal([strVal('a'), numVal(1), null])],
            ['map', mapVal({ inner: boolVal(false) })]
        ])
    }).then((result) => {
        // Check the result status
    }).catch((error) => {
        // Handle error
    });
}

Reporting multiple events

reportEvents

Returns DYResult

ParameterData Structure
DYEvent
Required
[DYEvent]

Example

async function reportMultiEvent() {
    await events.reportEvents({
        events: [
            [
                EventType.PromoCodeEnter,
                {
                    name: 'pre-define-event',
                    code: 'code'
                }
            ],
            [
                EventType.Custom,
                {
                    name: 'dynamic-custom-event',
                    map: new Map<string, SupportedValue>([
                        ['map', mapVal({ inner: boolVal(false) })]
                    ])
                }
            ],
            [
                EventType.Custom,
                {
                    name: 'second-test-custom-event',
                    map: new Map<string, SupportedValue>([
                        ['parameterInt', numVal(1)],
                        ['parameterFloat', numVal(5.2)]
                    ])
                }
            ]
        ]
    }).then((result) => {
    }).catch((error) => {
        // Handle error
    });
}