Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 37 Next »

Product View

Method Objective

REQUIRED The method gives the system an understanding of the product viewed by the user.

Syntax and parameters

sdk.track(event: .productView(id: product_id), recommendedBy: params) {callback}

NameTypeRequirementDescription
product_idstringrequiredThe ID of the current product
paramsRecomendedBy Classrequired is some casesTuple with additional request parameters. See description below
callbackfunctionoptionallyCallback function to catch success or error

RecomendedBy Class Properties

NameTypeRequirementDescription
typeenum stringrequired in some casesThis property should be set to ".dynamic" if the current product was opened from the recommendation block. See example below.
codestringrequired in some casesThis property should have a unique code for the product recommendations block if the current product was opened from the recommendation block. The unique code is available in the PersonaClick account in the "data-recommender-code" attribute of each block.

Example of use

let recData = RecomendedBy(type: .dynamic, code: "b934b6ba2eb6202b8922d6a3fb8b3271")
sdk.track(event: .productView(id: "100500"), recommendedBy: recData) { trackResponse in
    print("Product viewed callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}



Category View

Method Objective

REQUIRED The method gives the system an understanding of the category viewed by the user.

The API will respond with an error for categories unknown to the system. The system only knows the categories from the product feed (XML) or the HTTP import of the category list.

Syntax and parameters

sdk.track(event: .categoryView(id: category_id)) { callback }

NameTypeRequirementDescription
category_idstringrequiredThe ID of the current category.
callbackfunctionoptionallyCallback function to catch success or error

Example of use

sdk.track(event: .categoryView(id: "146")) { trackResponse in
    print("Category viewed callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}



Adding a product to the cart

Method Objective

REQUIRED The method gives the system an understanding of the product added to the cart by the user.

Syntax and parameters

sdk.track(event: .productAddedToCart(id: product_id), recommendedBy: params) { callback }

NameTypeRequirementDescription
product_idstringrequiredThe ID of the product added to the cart
paramsRecomendedBy Classrequired is some casesTuple with additional request parameters. See description below
callbackfunctionoptionallyCallback function to catch success or error

RecomendedBy Class Properties

NameTypeRequirementDescription
typeenum stringrequired in some casesThis property should be set to ".dynamic" if the current product was added to the cart from the recommendation block. See example below.
codestringrequired in some casesThis property should have a unique code for the product recommendations block if the current product was added to the cart from the recommendation block. The unique code is available in the PersonaClick account in the "data-recommender-code" attribute of each block.

Example of use

let recData = RecomendedBy(type: .dynamic, code: "b934b6ba2eb6202b8922d6a3fb8b3271")
sdk.track(event: .productAddedToCart(id: "100500"), recommendedBy: recData) { trackResponse in
    print("Product added to the cart callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}



Removing a product from the cart

Method Objective

REQUIRED The method gives the system an understanding of the product removed from the cart by the user.

Syntax and parameters

sdk.track(event: .productRemovedFromCart(id: product_id)) { callback }

NameTypeRequirementDescription
product_idstringrequiredThe ID of the product removed from the cart
callbackfunctionoptionallyCallback function to catch success or error

Example of use

sdk.track(event: .productRemovedFromCart(id: "100500")) { trackResponse in
    print("Product removed from the cart callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}



Update the current cart

Method Objective

REQUIRED The method updates the whole cart on the system side.

This method is required for use on the cart page when the user does certain actions there: when the user visits the page, changes the quantity of a product in the cart, removes a product from the cart, or clears the cart completely.

This method can be used on the product page as an alternative to the "Add to cart" and "Remove from cart" methods if you have access to the entire cart on the product page.

Syntax and parameters

sdk.track(event: .synchronizeCart(items: cart_items)) { callback }

NameTypeRequirementDescription
cart_itemsarray of "CartItem" objectsrequired

Array of objects with product properties in the cart. 

The "CartItem" object supports properties:

  • productId - ID of the product in the cart (required)
  • quantity - quantity of the product in the cart ( required)

See example below.

callbackfunctionoptionallyCallback function to catch success or error

Example of use

sdk.track(event: .synchronizeCart(items: [CartItem(productId: "784", quantity: 1), CartItem(productId: "785", quantity: 3)])) { trackResponse in
    print("Cart synchronized callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}


Successful checkout

Method Objective

REQUIRED The method gives the system information about the successful checkout, its products, and other information related to the checkout.

Syntax and parameters

sdk.track(event: .orderCreated(orderId, totalValue, products)) { callback }

Request parameters

NameTypeRequirementDescription
productsarrayrequiredAn array of purchased products. See the table below for details.
orderIdstringoptionallyInternal store Order ID. If not specified, the system will create its internal ID. Synchronization of order statuses, in this case, won't be available.
totalValuenumberoptionallyThe final order value, including all discounts. If not specified, the system will calculate the order value based on prices from the product feed.


Product properties:

NameTypeRequirementDiscription
idstringrequiredProduct ID.
amountnumberrequiredProduct Quantity.

Example of use

sdk.track(event: .orderCreated(orderId: "N100500", totalValue: 750, products: [(id: "37", amount: 3), (id: "187", amount: 1)])) { trackResponse in
    print("Order is created callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}



Search Request

Method Objective

The method gives the system an understanding of the user's search queries.

Syntax and parameters

sdk.track(event: .search(query: search_query)) { callback }
NameTypeRequirementDescription
search_querystringrequiredSearch query phrase

Example of use

sdk.track(event: .search(query: "to be or not to be")) { trackResponse in
    print("The search request is sent")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}


Adding a product to the wishlist

Method Objective

The method gives the system an understanding the user has added a product to the wishlist.

Syntax and parameters

sdk.track(event: .productAddedToFavorities(id: product_id)) { callback }

NameTypeRequirementDescription
product_idstringrequiredThe ID of the product added to the wishlist
callbackfunctionoptionallyCallback function to catch success or error

Example of use

sdk.track(event: .productAddedToFavorities(id: "100500")) { trackResponse in
    print("Product added to the wishlist callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}



Removing a product from the wishlist

Method Objective

The method gives the system an understanding the user has removed a product from the wishlist.

Syntax and parameters

sdk.track(event: .productRemovedToFavorities(id: product_id)) { callback }

NameTypeRequirementDescription
product_idstringrequiredThe ID of the product removed from the wishlist
callbackfunctionoptionallyCallback function to catch success or error

Example of use

sdk.track(event: .productRemovedToFavorities(id: "100500")) { trackResponse in
    print("Product removed from the wishlist callback")
    switch trackResponse {
        case let .success(response):
            print("Successful")
        case let .failure(error):
            switch error {
                case .custom(let customError):
                    print("Error: ", customError)
                default:
                    print("Error: ", error.localizedDescription)
            }
            fatalError("Task failed successfully")
    }
}


Custom event

Method Objective

The method gives the system an understanding that some user event has happened.

Before you can use custom events, you must create them in the PersonaClick account: Settings > Custom events.

Syntax and parameters

sdk.trackEvent(event: custom_event_key, category, label, value)
NameTypeRequirementDescription
custom_event_keystringrequiredUnique custom event key. Must be pre-created in the PersonaClick account: Settings > Custom events.
categorystringoptionallyA category is a name that you supply as a way to group some event's properties.
labelstringoptionallyWith labels, you can provide additional information for events that you need.
valuenumberoptionallyThe value property can be any integer and can be used to send a specific value in an event.

Examples of use

sdk.trackEvent(event: "my_event")

sdk.trackEvent(event: "my_event", category: "my_category", label: "my_label", value: 100500)


Source Tracking

Method Objective

The method gives the system an understanding that the user jumped from the campaign message: bulk, chain, transactional.

Syntax and parameters

sdk.trackSource(source, code)

NameTypeRequirementDescription
sourceenum stringrequired

One of the string enum values. Available values:

  • .bulk
  • .chain
  • .transactional

The "src.type" value in the "payload" of the campaign should be used to define the value for this parameter. See Payload Examples.

codestringrequired

Unique campaign code

The "src.id" value in the "payload" of the campaign should be used to define the value for this parameter. See Payload Examples.

Example of use

sdk.trackSource(source: .chain, code: "100500146")
  • No labels