- Created by Andrey Veprikov, last modified on Sept 06, 2022
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 39 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}
Name | Type | Requirement | Description |
---|---|---|---|
product_id | string | required | The ID of the current product |
params | RecomendedBy Class | required is some cases | Tuple with additional request parameters. See description below |
callback | function | optionally | Callback function to catch success or error |
RecomendedBy Class Properties
Name | Type | Requirement | Description |
---|---|---|---|
type | enum string | required in some cases | This property should be set to ".dynamic" if the current product was opened from the recommendation block. See example below. |
code | string | required in some cases | This parameter can contain one of the values:
|
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 }
Name | Type | Requirement | Description |
---|---|---|---|
category_id | string | required | The ID of the current category. |
callback | function | optionally | Callback 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 }
Name | Type | Requirement | Description |
---|---|---|---|
product_id | string | required | The ID of the product added to the cart |
params | RecomendedBy Class | required is some cases | Tuple with additional request parameters. See description below |
callback | function | optionally | Callback function to catch success or error |
RecomendedBy Class Properties
Name | Type | Requirement | Description |
---|---|---|---|
type | enum string | required in some cases | This property should be set to ".dynamic" if the current product was added to the cart from the recommendation block. See example below. |
code | string | required in some cases | This parameter can contain one of the values:
|
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 }
Name | Type | Requirement | Description |
---|---|---|---|
product_id | string | required | The ID of the product removed from the cart |
callback | function | optionally | Callback 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 }
Name | Type | Requirement | Description |
---|---|---|---|
cart_items | array of "CartItem" objects | required | Array of objects with product properties in the cart. The "CartItem" object supports properties:
See example below. |
callback | function | optionally | Callback 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
Name | Type | Requirement | Description |
---|---|---|---|
products | array | required | An array of purchased products. See the table below for details. |
orderId | string | optionally | 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. |
totalValue | number | optionally | The 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:
Name | Type | Requirement | Discription |
---|---|---|---|
id | string | required | Product ID. |
amount | number | required | Product 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 }
Name | Type | Requirement | Description |
---|---|---|---|
search_query | string | required | Search 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 }
Name | Type | Requirement | Description |
---|---|---|---|
product_id | string | required | The ID of the product added to the wishlist |
callback | function | optionally | Callback 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 }
Name | Type | Requirement | Description |
---|---|---|---|
product_id | string | required | The ID of the product removed from the wishlist |
callback | function | optionally | Callback 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)
Name | Type | Requirement | Description |
---|---|---|---|
custom_event_key | string | required | Unique custom event key. Must be pre-created in the PersonaClick account: Settings > Custom events. |
category | string | optionally | A category is a name that you supply as a way to group some event's properties. |
label | string | optionally | With labels, you can provide additional information for events that you need. |
value | number | optionally | The 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)
Name | Type | Requirement | Description |
---|---|---|---|
source | enum string | required | One of the string enum values. Available values:
The "src.type" value in the "payload" of the campaign should be used to define the value for this parameter. See Payload Examples. |
code | string | required | 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")
Page Navigation
Related Pages
-
Page:
-
Page:
-
Page:
-
Page:
-
Page:
-
Page:
-
Page:
- No labels