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
configA 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
queryThe query object, consisting of the query to autocomplete on and additional options.
completionHandlerThe 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
queryThe query object, consisting of the query to search for and additional options.
completionHandlerThe 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
queryThe query object, consisting of the query to browse for and additional options.
completionHandlerThe 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
queryThe query object, consisting of the query to browse items for and additional options.
completionHandlerThe 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
queryThe query object, consisting of the query to browse groups for and additional options.
completionHandlerThe 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
queryThe query object, consisting of the query to browse facets for and additional options.
completionHandlerThe 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
queryThe query object, consisting of the query to browse facet options for and additional options.
completionHandlerThe 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
queryThe query object, consisting of the query to get recommendations for and additional options.
completionHandlerThe 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
queryThe CIOQuizQuery object required to get the next quiz question.
completionHandlerThe 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
queryThe CIOQuizQuery object required to get the quiz results.
completionHandlerThe 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
searchTermThe pre-existing text in the search input element (if present)
completionHandlerThe 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
searchTermThe term that the user selected
originalQueryThe current text in the input field
sectionNameThe name of the autocomplete section the term came from (usually “Search Suggestions”)
resultIDIdentifier of result set
completionHandlerThe 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
searchTermThe term that the user searched for
originalQueryThe current text in the input field
completionHandlerThe callback to execute on completion.
-
trackSearchResultsLoaded(searchTerm:resultCount: customerIDs: items: resultID: analyticsTags: completionHandler: ) Track when a user views a search product listing page
Usage Example:
// Uses Items parameters (preferred) constructorIO.trackSearchResultsLoaded(searchTerm: "tooth", resultCount: 789, items: [CIOItem(id: "1234567-AB", name: "Toothpicks")]) // Uses CustomerIDs parameters (deprecated) 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, items: [CIOItem]? = nil, resultID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)Parameters
searchTermThe term that the user searched for
resultCountThe number of search results returned in total
customerIDsDeprecated. Use
items(v4.2.0) instead. The list of item id’s returned in the searchresultIDIdentifier of result set
itemsThe list of items returned in the search (Preferred over customerIDs)
completionHandlerThe callback to execute on completion.
-
trackSearchResultClick(itemName:customerID: variationID: searchTerm: sectionName: resultID: slCampaignID: slCampaignOwner: 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-47398", searchTerm: "tooth", sectionName: "Products", resultID: "179b8a0e-3799-4a31-be87-127b06871de2", slCampaignID: "camp123", slCampaignOwner: "own123")Declaration
Swift
public func trackSearchResultClick(itemName: String, customerID: String, variationID: String? = nil, searchTerm: String? = nil, sectionName: String? = nil, resultID: String? = nil, slCampaignID: String? = nil, slCampaignOwner: String? = nil, completionHandler: TrackingCompletionHandler? = nil)Parameters
itemNameThe item name.
customerIDThe item ID.
variationIDThe variation ID
searchTermThe term that the user searched for (defaults to ‘TERM_UNKNOWN’)
sectionNameThe name of the autocomplete section the term came from (defaults to “products”)
resultIDIdentifier of result set
slCampaignIDThe campaign ID
slCampaignOwnerThe campaign owner
completionHandlerThe callback to execute on completion.
-
trackBrowseResultsLoaded(filterName:filterValue: resultCount: customerIDs: items: resultID: analyticsTags: completionHandler: ) Track when a user views a browse product listing page
Usage Example:
// Uses items parameter (preferred) constructorIO.trackBrowseResultsLoaded(filterName: "Category", filterValue: "Snacks", resultCount: 674, items: [CIOItem(id: "1234567-AB", name: "Toothpicks")]) // Uses customerIDs parameter (deprecated) constructorIO.trackBrowseResultsLoaded(filterName: "Category", filterValue: "Snacks", resultCount: 674, customerIDs: ["1234567-AB", "1234765-CD", "1234576-DE"])Declaration
Swift
public func trackBrowseResultsLoaded(filterName: String, filterValue: String, resultCount: Int, customerIDs: [String]? = nil, items: [CIOItem]? = nil, resultID: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)Parameters
filterNameThe name of the primary filter that the user browsed for (i.e “color”)
filterValueThe value of the primary filter that the user browsed for (i.e “blue”)
resultCountThe number of results returned in total
customerIDsDeprecated. Use
items(v4.2.0) instead. The list of item id’s returned in the browseresultIDIdentifier of result set
itemsThe list of items returned in the browse (Preferred over customerIDs)
completionHandlerThe callback to execute on completion.
-
trackBrowseResultClick(customerID:variationID: filterName: filterValue: resultPositionOnPage: sectionName: resultID: slCampaignID: slCampaignOwner: 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, slCampaignID: String? = nil, slCampaignOwner: String? = nil, analyticsTags: [String : String]? = nil, completionHandler: TrackingCompletionHandler? = nil)Parameters
customerIDThe item ID.
variationIDThe variation ID
filterNameThe name of the primary filter that the user browsed for (i.e “color”)
filterValueThe value of the primary filter that the user browsed for (i.e “blue”)
resultPositionOnPageThe position of clicked item
resultIDIdentifier of result set
slCampaignIDThe campaign ID
slCampaignOwnerThe campaign owner
completionHandlerThe 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
podIDThe pod ID
numResultsViewedThe count of results that is visible to the user
customerIDsThe items that were loaded
resultPageThe current page that recommedantion result is on
resultCountThe total number of recommendation results
sectionNameThe name of the autocomplete section the term came from
resultIDIdentifier of result set
completionHandlerThe 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
podIDThe pod ID
strategyIDThe strategy ID that fulfilled the pod
customerIDThe item ID
variationIDThe item variation ID
numResultsPerPageThe count of recommendation results on each page
resultPageThe current page that recommedantion result is on
resultCountThe total number of recommendation results
resultPositionOnPageThe position of the recommendation result that was clicked on
resultIDIdentifier of result set
completionHandlerThe 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
itemNameThe item name.
customerIDThe item ID.
variationIDThe variation ID
revenueThe revenue of the item.
searchTermThe term that the user searched for if searching (defaults to ‘TERM_UNKNOWN’)
conversionTypeThe type of conversion (defaults to “add_to_cart”)
displayNameDisplay name for the custom conversion type
isCustomTypeSpecify if type is a custom conversion type
completionHandlerThe 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
customerIDsThe item IDs purchased
revenueThe revenue of the purchase
orderIDThe order identifier
completionHandlerThe 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
itemsThe items purchased
revenueThe revenue of the purchase
orderIDThe order identifier
completionHandlerThe 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
customerIDThe item ID
itemNameThe item name
variationIDThe id of the variation
sectionNameThe name of the section the product is in.
urlThe 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
quizIDThe quiz identifier
quizVersionIDThe quiz version identifier
quizSessionIDThe quiz session identifier associated with this conversion event
resultIDThe identifier of result set returned by the Constructor quiz response
resultPageThe current page of the results
resultCountThe total number of results
completionHandlerThe 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
quizIDThe quiz identifier
quizVersionIDThe quiz version identifier
quizSessionIDThe quiz session identifier associated with this conversion event
customerIDThe item ID.
variationIDThe variation ID
itemNameThe product item name
resultIDThe identifier of result set returned by the Constructor quiz response
resultPageThe current page of the results
resultCountThe total number of results
numResultsPerPageThe number of results on the current page
resultPositionOnPageThe position of clicked item
completionHandlerThe 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
quizIDThe quiz identifier
quizVersionIDThe quiz version identifier
quizSessionIDThe quiz session identifier associated with this conversion event
customerIDThe item ID.
variationIDThe variation ID
itemNameThe product item name
revenueThe sale price if available, otherwise the regular (retail) price of item
conversionTypeThe type of conversion (defaults to “add_to_cart”)
isCustomTypeThe flag to specify if type is custom conversion type
displayNameThe display name for the custom conversion type
completionHandlerThe callback to execute on completion.
-
Track when a user clicks on a generic result
Usage Example:
constructorIO.trackGenericResultClick(itemID: "7654321-BA", itemName: "Pencil", variationID: "7654321-BA-738", sectionName: "Products")Declaration
Swift
public func trackGenericResultClick(itemID: String, itemName: String, variationID: String? = nil, sectionName: String? = nil, completionHandler: TrackingCompletionHandler? = nil)Parameters
itemIDThe ID of the item that was clicked
itemNameThe name of the item that was clicked
variationIDOptional; Variation ID of the item
sectionNameOptional; The name of the section the product is in
-
Set a custom clientID
Usage Example:
constructorIO.setClientId(clientID: "new-client-id")Declaration
Swift
public func setClientId(clientID: String)Parameters
clientIDThe Client ID
-
Set a custom sessionID
Usage Example:
constructorIO.setSessionId(sessionID: 1234)Declaration
Swift
public func setSessionId(sessionID: Int)Parameters
sessionIDThe Session ID