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 67 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.
  • ".instant_search" if the current product was opened from the Instant Search tool.
  • ".full_searchif the current product was opened from the Full Search tool.
codestringrequired in some cases

This parameter can contain one of the values:

  • This parameter should have a unique code of the product recommendations block if the currently viewed product is from the recommendations block. The unique code is available in the PersonaClick account in the "data-recommender-code" attribute of each block.
  • This parameter should have a search query in the value if the product is viewed from the Instant or Full Search tool.

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, amount: product_amount), recommendedBy: params) { callback }

NameTypeRequirementDescription
product_idstringrequiredThe ID of the product added to the cart
product_amountnumberoptionally

The total value of the amount of product added to the cart. Default: 1.

For example:

  1. A user has added the current product to the cart in the amount of 3 pieces. The request should have the "product_amount" value of 3.
  2. Then the user decides to add 2 more pieces of the current product (bringing the total to 5). The second request should have the "product_amount" value of 5.
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.
  • ".instant_search" if the current product was opened from the Instant Search tool.
  • ".full_searchif the current product was opened from the Full Search tool.
codestringrequired in some cases

This parameter can contain one of the values:

  • This parameter should have a unique code of the product recommendations block if the currently viewed product is from the recommendations block. The unique code is available in the PersonaClick account in the "data-recommender-code" attribute of each block.
  • This parameter should have a search query in the value if the product is viewed from the Instant or Full Search tool.

Example of use

let recData = RecomendedBy(type: .dynamic, code: "b934b6ba2eb6202b8922d6a3fb8b3271")
sdk.track(event: .productAddedToCart(id: "100500", amount: 2), 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, deliveryAddress, deliveryType, promocode, paymentType, taxFree)) { callback }

Request parameters

NameTypeRequirementDescription
productsarrayrequiredAn array of purchased products. See the table below for details.
orderIdstringoptionally

Internal store Order ID. If not specified, the system will create its internal ID. Synchronization of order statuses, in this case, won't be available.

Please note that order IDs in UUID format aren't displayed in the dashboard. Instead of UUDI, "---" will be displayed. To avoid this, add any prefix to this.

totalValuedoubleoptionallyThe final order value, including all discounts. If not specified, the system will calculate the order value based on prices from the product feed.
deliveryAddressstringoptionallyDelivery address. Any text.
deliveryTypestringoptionallyDelivery Type, e.g. "courier", "self_pickup", "delivery", "pickup_point", etc.
promocodestringoptionally

Promo code that was used.

If a promo code from the list uploaded to the account has been used, it'll be marked as used.

paymentTypestringoptionallyPayment method. Any string value. For example: "cash", "card", "wire".
taxFreestringoptionallyIt sets whether the order was placed with Tax-Free or not.


Product properties:

NameTypeRequirementDiscription
idstringrequiredProduct ID
amountintrequiredProduct Quantity
pricefloatoptionallyProduct Price

Example of use

sdk.track(event: .orderCreated(orderId: "N100500", totalValue: 750.12, products: [(id: "37", amount: 3, price: 11.45), (id: "187", amount: 1, price: 715.77)])) { 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: .productRemovedFromFavorities(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: .productRemovedFromFavorities(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")
    }
}



sdk.track(event: .synchronizeFavorites(items) { callback }
NameTypeRequirementDescription
issarrayrequired

Array with wish list product IDs. 

Use an empty array to clear the wishlist.

callbackfunctionoptionallyCallback function to catch success or error
sdk.track(event: .synchronizeCart(items: ["784", "785"])) { trackResponse in
    print("Cart synchronized callback")
    switch trackResponse {
        case let .success(response):
			// success
        case let .failure(error):
			// error
    }
}

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