An iOS Client for Constructor.io. Constructor.io provides search as a service that optimizes results using artificial intelligence (including natural language processing, re-ranking to optimize for conversions, and user personalization).
Full API documentation is available on Github Pages
First make sure you have CocoaPods installed. Then create an empty text file in your project’s root directory called ‘Podfile’. Add the following lines to the file:
target ‘YOUR_TARGET_NAME’ do
pod ‘ConstructorAutocomplete'
end
Open the terminal (make sure you’re located in the project root) and type
pod install
First, make sure you have Carthage installed. Then create an empty text file called ‘Cartfile’ in your project root directory. Now, add the following lines:
github "Constructor-io/constructorio-client-swift"
Open the terminal (make sure you’re located in the project root) and type
carthage update
Drag the ConstructorIO.framework
from Carthage/Build/iOS into your project and link it with your application target. Also, make sure to copy the framework by adding a new Copy Files phase.
You can find this in your Constructor.io dashboard. Contact sales if you'd like to sign up, or support if you believe your company already has an account.
Make sure to import the ConstructorAutocomplete
module at the top of your source file and then write the following
// Create the client config
let config = ConstructorIOConfig(
apiKey: "YOUR API KEY",
baseURL: "ac.cnstrc.com", // default
resultCount: AutocompleteResultCount(numResultsForSection: ["Search Suggestions" : 3, "Products" : 0])
)
// Create the client instance
let constructorIO = ConstructorIO(config: config)
// Set the user ID (for a logged in user) used for cross device personalization
constructorIO.userID = "abcdefghijk-123"
let query = CIOAutocompleteQuery(query: "apple", numResultsForSection: ["Products": 6, "Search Suggestions": 8])
constructorIO.autocomplete(forQuery: query) { (response) in
let data = response.data!
let error = response.error!
// ...
}
let filters = CIOQueryFilters(groupFilter: "Bread", facetFilters: [
(key: "Nutrition", value: "Organic"),
(key: "Nutrition", value: "Natural"),
(key: "Nutrition", value: "Whole-grain")
])
let query = CIOSearchQuery(query: "Dave's Bread", page: 5, filters: filters)
// Specify the sort order in which groups are returned
let groupsSortOption = CIOGroupsSortOption(sortBy: CIOGroupsSortBy.value, sortOrder: CIOGroupsSortOrder.ascending)
constructorIO.search(forQuery: query, filters: filters, groupsSortOption: groupsSortOption) { (response) in
let data = response.data!
let error = response.error!
// ...
}
let query = CIOBrowseQuery(filterName: "potato", filterValue: "russet")
// Specify the sort order in which groups are returned
let groupsSortOption = CIOGroupsSortOption(sortBy: CIOGroupsSortBy.value, sortOrder: CIOGroupsSortOrder.ascending)
constructorIO.browse(forQuery: query, groupsSortOption: groupsSortOption) { (response) in
let data = response.data!
let error = response.error!
// ...
}
let query = CIORecommendationsQuery(podId: "pdp_best_sellers", filters: filters)
constructorIO.recommendations(forQuery: query) { (response) in
let data = response.data!
let error = response.error!
// ...
}
let itemId = "P18232"
let query = CIORecommendationsQuery(podId: "pdp_complementary_items", itemId: itemId)
constructorIO.recommendations(forQuery: query) { (response) in
let data = response.data!
let error = response.error!
// ...
}
let filters = CIOQueryFilters(groupFilter: "cat_1234", facetFilters: [
(key: "Nutrition", value: "Organic"),
(key: "Nutrition", value: "Natural"),
(key: "Brand", value: "Kroger")
])
let query = CIORecommendationsQuery(podId: "pdp_filtered_items", filters: filters)
constructorIO.recommendations(forQuery: query) { (response) in
let data = response.data!
let error = response.error!
// ...
}
let query = CIOQuizQuery(quizId: "quiz-1", answers: [["1"], ["2"]])
constructorIO.getQuizNextQuestion(forQuery: query) { (response) in
let data = response.data!
let error = response.error!
// ...
}
let query = CIOQuizQuery(quizId: "quiz-1", answers: [["1"], ["2"]])
constructorIO.getQuizResults(forQuery: query) { (response) in
let data = response.data!
let error = response.error!
// ...
}
The iOS Client sends behavioral events to Constructor.io in order to continuously learn and improve results for future Autosuggest and Search requests. The Client only sends events in response to being called by the consuming app or in response to user interaction . For example, if the consuming app never calls the SDK code, no events will be sent. Besides the explicitly passed in event parameters, all user events contain a GUID based user ID that the client sets to identify the user as well as a session ID.
Three types of these events exist:
add to cart
or purchase
// Track when the user focuses into the search bar
constructorIO.trackInputFocus(searchTerm: "")
// Track when the user selects an autocomplete suggestion
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")
// Track when the user submits a search (either by selecting a suggestion or not selecting a suggestion)
constructorIO.trackSearchSubmit(searchTerm: "toothpicks", originalQuery: "tooth")
// Track when search results are loaded into view (customer ID's are the ID's of shown items)
constructorIO.trackSearchResultsLoaded(searchTerm: "tooth", resultCount: 789, customerIDs: ["1234567-AB", "1234765-CD", "1234576-DE"])
// Track when a search result is clicked
constructorIO.trackSearchResultClick(itemName: "Fashionable Toothpicks", customerID: "1234567-AB", variationID: "1234567-AB-7463", searchTerm: "tooth", sectionName: "Products", resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
// Track when browse results are loaded into view
constructorIO.trackBrowseResultsLoaded(filterName: "Category", filterValue: "Snacks", resultCount: 674)
// Track when a browse result is clicked
constructorIO.trackBrowseResultClick(filterName: "Category", filterValue: "Snacks", customerID: "7654321-BA", variationID: "7654321-BA-738", resultPositionOnPage: 4, sectionName: "Products", resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
// Track when recommendation results are viewed
constructorIO.trackRecommendationResultsView(podID: "pdp_best_sellers", numResultsViewed: 5, resultPage: 1, resultCount: 10, resultID: "179b8a0e-3799-4a31-be87-127b06871de2")
// Track when a recomendation result is clicked
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")
// Track when an item converts (a.k.a. is added to cart) regardless of the user journey that led to adding to cart
constructorIO.trackConversion(itemName: "Fashionable Toothpicks", customerID: "1234567-AB", variationID: "1234567-AB-47398", revenue: 12.99, searchTerm: "tooth", conversionType: "add_to_cart")
// Track when items are purchased
constructorIO.trackPurchase(customerIDs: ["123-AB", "456-CD"], revenue: 34.49, orderID: "343-315")
// Tracking items w/ variations in purchases (supported in v2.5.5 and above)
let purchaseItems = [
CIOItem(customerID: "custID1", variationID: "varID1", quantity: 2),
CIOItem(customerID: "custID2", variationID: "varID2", quantity: 3)
]
constructorIO.trackPurchase(items: purchaseItems, revenue: 93.89, orderID: "423-2432")
// Track when a product detail page is loaded (a.k.a after a user clicks on an item)
constructorIO.trackItemDetailLoad(customerID: "10001", itemName: "item1", variationID: "var1", sectionName: "Products")
link |
Stars: 7 |
Last commit: 1 week ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics