ConstructorIO
public class ConstructorIO : CIOSessionManagerDelegate
The main class to be used for getting autocomplete results and tracking behavioural data.
-
Initializes a ConstructorIO Client
Usage Example:
/// Create the client config let config = ConstructorIOConfig( apiKey: "YOUR API KEY", resultCount: AutocompleteResultCount(numResultsForSection: ["Search Suggestions" : 3, "Products" : 0]), ) /// Create the client instance let constructorIO = ConstructorIO(config: config)
Declaration
Swift
public init(config: ConstructorIOConfig)
Parameters
config
A configuration object containing the API Key, Test Cell Information, Segments, etc.
-
Get autocomplete suggestions for a query.
Usage Example:
let autocompleteQuery = CIOAutocompleteQuery(query: "apple", numResults: 5, numResultsForSection: ["Products": 6, "Search Suggestions": 8]) constructorIO.autocomplete(forQuery: autocompleteQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func autocomplete(forQuery query: CIOAutocompleteQuery, completionHandler: @escaping AutocompleteQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to autocomplete on and additional options.
completionHandler
The callback to execute on completion.
-
Get search results for a query.
Usage Example:
let facetFilters = [(key: "Nutrition", value: "Organic"), (key: "Nutrition", value: "Natural"), (key: "Brand", value: "Kraft Foods")] let searchQuery = CIOSearchQuery(query: "red", filters: CIOQueryFilters(groupFilter: nil, facetFilters: facetFilters), page: 1, perPage: 30, section: "Products") constructorIO.search(forQuery: searchQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func search(forQuery query: CIOSearchQuery, completionHandler: @escaping SearchQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to search for and additional options.
completionHandler
The callback to execute on completion.
-
Get browse results for a query.
Usage Example:
let facetFilters = [(key: "Nutrition", value: "Organic"), (key: "Nutrition", value: "Natural"), (key: "Brand", value: "Kraft Foods")] let browseQuery = CIOBrowseQuery(filterName: "group_id", filterValue: "Pantry", filters: CIOQueryFilters(groupFilter: nil, facetFilters: facetFilters), page: 1, perPage: 30, section: "Products") constructorIO.browse(forQuery: browseQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func browse(forQuery query: CIOBrowseQuery, completionHandler: @escaping BrowseQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to browse for and additional options.
completionHandler
The callback to execute on completion.
-
Get browse items results for a query.
Usage Example:
let facetFilters = [(key: "Nutrition", value: "Organic"), (key: "Nutrition", value: "Natural"), (key: "Brand", value: "Kraft Foods")] let browseItemsQuery = CIOBrowseItemsQuery(ids: ["123", "123"], filters: CIOQueryFilters(groupFilter: nil, facetFilters: facetFilters), page: 1, perPage: 30, section: "Products") constructorIO.browseItems(forQuery: browseItemsQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func browseItems(forQuery query: CIOBrowseItemsQuery, completionHandler: @escaping BrowseQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to browse items for and additional options.
completionHandler
The callback to execute on completion.
-
Get browse groups results for a query.
Usage Example:
let browseGroupsQuery = CIOBrowseGroupsQuery( groupId: "group_1", section: "Products", groupsMaxDepth: 5 ) constructor.browseGroups(forQuery: browseGroupsQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func browseGroups(forQuery query: CIOBrowseGroupsQuery, completionHandler: @escaping BrowseQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to browse groups for and additional options.
completionHandler
The callback to execute on completion.
-
Get browse facets results for a query.
Usage Example:
let browseFacetsQuery = CIOBrowseFacetsQuery(page: 1, perPage: 10, showHiddenFacets: true) constructorIO.browseFacets(forQuery: browseFacetsQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func browseFacets(forQuery query: CIOBrowseFacetsQuery, completionHandler: @escaping BrowseFacetsQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to browse facets for and additional options.
completionHandler
The callback to execute on completion.
-
Get browse facet options results for a query.
Usage Example:
let browseFacetOptionsQuery = CIOBrowseFacetOptionsQuery(facetNme: "price", showHiddenFacets: true) constructorIO.browseFacetOptions(forQuery: browseFacetOptionsQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func browseFacetOptions(forQuery query: CIOBrowseFacetOptionsQuery, completionHandler: @escaping BrowseFacetOptionsQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to browse facet options for and additional options.
completionHandler
The callback to execute on completion.
-
Get recommendation results for a query.
Usage Example:
let recommendationsQuery = CIORecommendationsQuery(podID: "pod_name", itemID: "item_id", numResults: 5, section: "Products") constructorIO.recommendations(forQuery: recommendationsQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func recommendations(forQuery query: CIORecommendationsQuery, completionHandler: @escaping RecommendationsQueryCompletionHandler)
Parameters
query
The query object, consisting of the query to get recommendations for and additional options.
completionHandler
The callback to execute on completion.
-
Get Quiz question for a query.
Usage Example:
let quizQuestionQuery = CIOQuizQuery(quizID: "123", answers: [["1"], ["1", "2"]], quizVersionID: "some-version-id", quizSessionID: "some-session-id") constructorIO.getQuizNextQuestion(forQuery: quizQuestionQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func getQuizNextQuestion(forQuery query: CIOQuizQuery, completionHandler: @escaping QuizQuestionQueryCompletionHandler)
Parameters
query
The CIOQuizQuery object required to get the next quiz question.
completionHandler
The callback to execute on completion.
-
Get Quiz results for a query.
Usage Example:
let quizResultsQuery = CIOQuizQuery(quizID: "123", answers: [["1"], ["1", "2"]], quizVersionID: "some-version-id", quizSessionID: "some-session-id") constructorIO.getQuizResults(forQuery: quizResultsQuery) { response in let data = response.data! let error = response.error! }
Declaration
Swift
public func getQuizResults(forQuery query: CIOQuizQuery, completionHandler: @escaping QuizResultsQueryCompletionHandler)
Parameters
query
The CIOQuizQuery object required to get the quiz results.
completionHandler
The callback to execute on completion.
-
Track when a user focuses on a search input element
Usage Example:
constructorIO.trackInputFocus(searchTerm: "apple")
Declaration
Swift
public func trackInputFocus(searchTerm: String, completionHandler: TrackingCompletionHandler? = nil)
Parameters
searchTerm
The pre-existing text in the search input element (if present)
completionHandler
The callback to execute on completion.
-
Track when a user selects (clicks, or navigates to via keyboard) a result that appears within autocomplete
Usage Example:
constructorIO.trackAutocompleteSelect(searchTerm: "toothpicks", originalQuery: "tooth", sectionName: "Search Suggestions", group: CIOGroup(displayName: "Dental Health", groupID: "dental-92dk2", path: "health-2911e/dental-92dk2"), resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
Declaration
Swift
public func trackAutocompleteSelect(searchTerm: String, originalQuery: String, sectionName: String, group: CIOGroup? = nil, resultID: String? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
searchTerm
The term that the user selected
originalQuery
The current text in the input field
sectionName
The name of the autocomplete section the term came from (usually “Search Suggestions”)
group
Item group (if present)
resultID
Identifier of result set
completionHandler
The callback to execute on completion.
-
Track when a user submits a search (pressing enter within input element, or clicking submit element)
Usage Example:
constructorIO.trackSearchSubmit(searchTerm: "apple", originalQuery: "app")
Declaration
Swift
public func trackSearchSubmit(searchTerm: String, originalQuery: String, group: CIOGroup? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
searchTerm
The term that the user searched for
originalQuery
The current text in the input field
group
Item group (if present)
completionHandler
The callback to execute on completion.
-
Track when a user views a search product listing page
Usage Example:
constructorIO.trackSearchResultsLoaded(searchTerm: "tooth", resultCount: 789, customerIDs: ["1234567-AB", "1234765-CD", "1234576-DE"])
Declaration
Swift
public func trackSearchResultsLoaded(searchTerm: String, resultCount: Int, customerIDs: [String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
searchTerm
The term that the user searched for
resultCount
The number of search results returned in total
customerIDs
The list of item id’s returned in the search
completionHandler
The callback to execute on completion.
-
trackSearchResultClick(itemName:
customerID: variationID: searchTerm: sectionName: resultID: completionHandler: ) Track when a user clicks a result that appears within a search product listing page
Usage Example:
constructorIO.trackSearchResultClick(itemName: "Fashionable Toothpicks", customerID: "1234567-AB", variationID: "1234567-AB-7463", searchTerm: "tooth", sectionName: "Products", resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
Declaration
Swift
public func trackSearchResultClick(itemName: String, customerID: String, variationID: String? = nil, searchTerm: String? = nil, sectionName: String? = nil, resultID: String? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
itemName
The item name.
customerID
The item ID.
variationID
The variation ID
searchTerm
The term that the user searched for (defaults to ‘TERM_UNKNOWN’)
sectionName
The name of the autocomplete section the term came from (defaults to “products”)
resultID
Identifier of result set
completionHandler
The callback to execute on completion.
-
trackBrowseResultsLoaded(filterName:
filterValue: resultCount: customerIDs: resultID: analyticsTags: completionHandler: ) Track when a user views a browse product listing page
Usage Example:
constructorIO.trackBrowseResultsLoaded(filterName: "Category", filterValue: "Snacks", resultCount: 674, customerIDs: ["1234567-AB", "1234765-CD", "1234576-DE"], resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
Declaration
Swift
public func trackBrowseResultsLoaded(filterName: String, filterValue: String, resultCount: Int, customerIDs: [String]? = nil, resultID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
filterName
The name of the primary filter that the user browsed for (i.e “color”)
filterValue
The value of the primary filter that the user browsed for (i.e “blue”)
resultCount
The number of results returned in total
resultID
Identifier of result set
completionHandler
The callback to execute on completion.
-
trackBrowseResultClick(customerID:
variationID: filterName: filterValue: resultPositionOnPage: sectionName: resultID: analyticsTags: completionHandler: ) Track when a user clicks a result that appears within a browse product listing page
Usage Example:
constructorIO.trackBrowseResultClick(filterName: "Category", filterValue: "Snacks", customerID: "7654321-BA", variationID: "7654321-BA-738", resultPositionOnPage: 4, sectionName: "Products", resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
Declaration
Swift
public func trackBrowseResultClick(customerID: String, variationID: String? = nil, filterName: String, filterValue: String, resultPositionOnPage: Int?, sectionName: String? = nil, resultID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
customerID
The item ID.
variationID
The variation ID
filterName
The name of the primary filter that the user browsed for (i.e “color”)
filterValue
The value of the primary filter that the user browsed for (i.e “blue”)
resultPositionOnPage
The position of clicked item
resultID
Identifier of result set
completionHandler
The callback to execute on completion.
-
trackRecommendationResultsView(podID:
numResultsViewed: customerIDs: resultPage: resultCount: sectionName: resultID: analyticsTags: completionHandler: ) Track when a user views a pod of recommendation results
Usage Example:
constructorIO.trackRecommendationResultsView(podID: "pdp_best_sellers", numResultsViewed: 5, customerIDs: ["1234567-AB", "1234765-CD", "1234576-DE"], resultPage: 1, resultCount: 10, resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
Declaration
Swift
public func trackRecommendationResultsView(podID: String, numResultsViewed: Int? = nil, customerIDs: [String]? = nil, resultPage: Int? = nil, resultCount: Int? = nil, sectionName: String? = nil, resultID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
podID
The pod ID
numResultsViewed
The count of results that is visible to the user
customerIDs
The items that were loaded
resultPage
The current page that recommedantion result is on
resultCount
The total number of recommendation results
sectionName
The name of the autocomplete section the term came from
resultID
Identifier of result set
completionHandler
The callback to execute on completion.
-
trackRecommendationResultClick(podID:
strategyID: customerID: variationID: numResultsPerPage: resultPage: resultCount: resultPositionOnPage: sectionName: resultID: analyticsTags: completionHandler: ) Track when a user clicks an item that appears within a list of recommendation results
Usage Example:
constructorIO.trackRecommendationResultClick(podID: "pdp_best_sellers", strategyID: "best_sellers", customerID: "P183021", variationID: "7281930", numResultsPerPage: 30, resultPage: 1, resultCount: 15, resultPositionOnPage: 1, resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
Declaration
Swift
public func trackRecommendationResultClick(podID: String, strategyID: String? = nil, customerID: String, variationID: String? = nil, numResultsPerPage: Int? = nil, resultPage: Int? = nil, resultCount: Int? = nil, resultPositionOnPage: Int? = nil, sectionName: String? = nil, resultID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
podID
The pod ID
strategyID
The strategy ID that fulfilled the pod
customerID
The item ID
variationID
The item variation ID
numResultsPerPage
The count of recommendation results on each page
resultPage
The current page that recommedantion result is on
resultCount
The total number of recommendation results
resultPositionOnPage
The position of the recommendation result that was clicked on
resultID
Identifier of result set
completionHandler
The callback to execute on completion.
-
trackConversion(itemName:
customerID: variationID: revenue: searchTerm: sectionName: conversionType: displayName: isCustomType: analyticsTags: completionHandler: ) Track when a user performs an action indicating interest in an item (add to cart, add to wishlist, etc.)
Usage Example:
constructorIO.trackConversion(itemName: "Fashionable Toothpicks", customerID: "1234567-AB", variationID: "1234567-AB-47398", revenue: 12.99, searchTerm: "tooth")
Declaration
Swift
public func trackConversion(itemName: String, customerID: String, variationID: String? = nil, revenue: Double?, searchTerm: String? = nil, sectionName: String? = nil, conversionType: String? = nil, displayName: String? = nil, isCustomType: Bool? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
itemName
The item name.
customerID
The item ID.
variationID
The variation ID
revenue
The revenue of the item.
searchTerm
The term that the user searched for if searching (defaults to ‘TERM_UNKNOWN’)
conversionType
The type of conversion (defaults to “add_to_cart”)
displayName
Display name for the custom conversion type
isCustomType
Specify if type is a custom conversion type
completionHandler
The callback to execute on completion.
-
Track when a user completes an order (usually fired on order confirmation page)
Usage Example:
constructorIO.trackPurchase(customerIDs: ["123-AB", "456-CD"], revenue: 34.49, orderID: "343-315")
Declaration
Swift
public func trackPurchase(customerIDs: [String], sectionName: String? = nil, revenue: Double? = nil, orderID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
customerIDs
The item IDs purchased
revenue
The revenue of the purchase
orderID
The order identifier
completionHandler
The callback to execute on completion.
-
Track when a user completes an order (usually fired on order confirmation page)
Usage Example:
constructorIO.trackPurchase(customerIDs: ["123-AB", "456-CD"], revenue: 34.49, orderID: "343-315")
Declaration
Swift
public func trackPurchase(items: [CIOItem], sectionName: String? = nil, revenue: Double? = nil, orderID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
items
The items purchased
revenue
The revenue of the purchase
orderID
The order identifier
completionHandler
The callback to execute on completion.
-
trackItemDetailLoad(customerID:
itemName: variationID: sectionName: url: analyticsTags: completionHandler: ) Track when a user views a product detail page
Usage Example:
constructorIO.trackItemDetailLoad(customerID: "7654321-BA", itemName: "Pencil", variationID: "7654321-BA-738", sectionName: "Products", "test.com/764321")
Declaration
Swift
public func trackItemDetailLoad(customerID: String, itemName: String, variationID: String? = nil, sectionName: String? = nil, url: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
customerID
The item ID
itemName
The item name
variationID
The id of the variation
sectionName
The name of the section the product is in.
url
The url of the product
-
trackQuizResultsLoaded(quizID:
quizVersionID: quizSessionID: resultID: resultPage: resultCount: sectionName: analyticsTags: completionHandler: ) Track when a user views a quizzes results page
Usage Example:
constructorIO.trackQuizResultsLoaded(quizID: "coffee-quiz", quizVersionID: "1231244", quizSessionID: "123", resultCount: 20)
Declaration
Swift
public func trackQuizResultsLoaded(quizID: String, quizVersionID: String, quizSessionID: String, resultID: String? = nil, resultPage: Int? = nil, resultCount: Int? = nil, sectionName: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
quizID
The quiz identifier
quizVersionID
The quiz version identifier
quizSessionID
The quiz session identifier associated with this conversion event
resultID
The identifier of result set returned by the Constructor quiz response
resultPage
The current page of the results
resultCount
The total number of results
completionHandler
The callback to execute on completion.
-
trackQuizResultClick(quizID:
quizVersionID: quizSessionID: customerID: variationID: itemName: resultID: resultPage: resultCount: numResultsPerPage: resultPositionOnPage: sectionName: analyticsTags: completionHandler: ) Track when a user clicks a result that appears within a quizzes results page
Usage Example:
constructorIO.trackQuizResultClick(quizID: "coffee-quiz", quizVersionID: "1231244", quizSessionID: "123", customerID: "123", itemName: "espresso")
Declaration
Swift
public func trackQuizResultClick(quizID: String, quizVersionID: String, quizSessionID: String, customerID: String, variationID: String? = nil, itemName: String? = nil, resultID: String? = nil, resultPage: Int? = nil, resultCount: Int? = nil, numResultsPerPage: Int? = nil, resultPositionOnPage: Int? = nil, sectionName: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
quizID
The quiz identifier
quizVersionID
The quiz version identifier
quizSessionID
The quiz session identifier associated with this conversion event
customerID
The item ID.
variationID
The variation ID
itemName
The product item name
resultID
The identifier of result set returned by the Constructor quiz response
resultPage
The current page of the results
resultCount
The total number of results
numResultsPerPage
The number of results on the current page
resultPositionOnPage
The position of clicked item
completionHandler
The callback to execute on completion.
-
trackQuizConversion(quizID:
quizVersionID: quizSessionID: customerID: variationID: itemName: revenue: conversionType: isCustomType: displayName: sectionName: analyticsTags: completionHandler: ) Track when a user clicks a result that appears within a quizzes results page
Usage Example:
constructorIO.trackQuizConversion(quizID: "coffee-quiz", quizVersionID: "1231244", quizSessionID: "3123", customerID: "123", variationID: "167", itemName: "espresso", revenue: 20.0)
Declaration
Swift
public func trackQuizConversion(quizID: String, quizVersionID: String, quizSessionID: String, customerID: String, variationID: String? = nil, itemName: String? = nil, revenue: Double? = nil, conversionType: String? = nil, isCustomType: Bool? = nil, displayName: String? = nil, sectionName: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)
Parameters
quizID
The quiz identifier
quizVersionID
The quiz version identifier
quizSessionID
The quiz session identifier associated with this conversion event
customerID
The item ID.
variationID
The variation ID
itemName
The product item name
revenue
The sale price if available, otherwise the regular (retail) price of item
conversionType
The type of conversion (defaults to “add_to_cart”)
isCustomType
The flag to specify if type is custom conversion type
displayName
The display name for the custom conversion type
completionHandler
The callback to execute on completion.
-
Set a custom clientID
Usage Example:
constructorIO.setClientId(clientID: "new-client-id")
Declaration
Swift
public func setClientId(clientID: String)
Parameters
clientID
The Client ID
-
Set a custom sessionID
Usage Example:
constructorIO.setSessionId(sessionID: 1234)
Declaration
Swift
public func setSessionId(sessionID: Int)
Parameters
sessionID
The Session ID