Skip to content

Latest commit

 

History

History

AlgoliaInsightsClient

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Algolia Insights client

Algolia Insights client is a library that enables developers to track and analyze user behavior and search patterns within their Swift applications using Algolia's Insights API. It provides a set of APIs that developers can use to track various user interactions within their applications, such as clicks, views, and conversions. This data can then be used to gain insights into how users are interacting with the application, what they're searching for, and what results they're clicking on.

Getting started

Insights client allows developers to capture search-related events. The events maybe related to search queries (such as click an conversion events used for Click Analytics or A/B testing). It does so by correlating events with queryIDs generated by the search API when a query parameter clickAnalytics is set to true. As well library allows to capture search-independent events which can be used for the purpose of search experience personalization. There are three types of these events which are currently supported: click, conversion and view.

let insightsClient = InsightsClient(appID: "YourApplicationID", apiKey: "YourAPIKey")

let events: [Event] = [
  try .click(name: "foo",
             indexName: index.name,
             userToken: "bar",
             timestamp: timestamp,
             objectIDs: ["one", "two"]),
  try .click(name: "foo",
             indexName: index.name,
             userToken: "bar",
             timestamp: timestamp,
             objectIDs: ["one", "two"])
]
try await insightsClient.send(events)


let searchParameters = SearchParameters(ClickAnalytics(true))
let searchResponse = try await index.search(parameters: searchParameters)
let queryID = searchResponse.queryID

let eventsAfterSearch = [
  try Event.view(name: "foo",
                 indexName: index.name,
                 userToken: "bar",
                 objectIDs: ["one", "two"]),
  try Event.click(name: "foo",
                  indexName: index.name,
                  userToken: "bar",
                  queryID: queryID!,
                  objectIDsWithPositions: [("one", 1), ("two", 2)]),
  try Event.conversion(name: "foo",
                       indexName: index.name,
                       userToken: "bar",
                       queryID: queryID!,
                       objectIDs: ["one", "two"]),
]

try await insightsClient.send(eventsAfterSearch)