Skip to content

Commit

Permalink
fix(insights): add a parameter to enable/disable auto sending events
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam committed May 14, 2024
1 parent b084cc7 commit a287cec
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Sources/InstantSearchCore/Searcher/Hits/HitsSearcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,17 @@ public final class HitsSearcher: IndexSearcher<AlgoliaSearchService> {
- apiKey: API Key
- indexName: Name of the index in which search will be performed
- query: Instance of Query. By default a new empty instant of Query will be created.
- isAutoSendingHitsViewEvents: flag defining whether the automatic hits view Insights events sending is enabled
- requestOptions: Custom request options. Default is `nil`.
*/
public convenience init(appID: ApplicationID,
apiKey: APIKey,
indexName: IndexName,
query: Query = .init(),
isAutoSendingHitsViewEvents: Bool = false,
requestOptions: RequestOptions? = nil) {
let client = SearchClient(appID: appID, apiKey: apiKey)
self.init(client: client, indexName: indexName, query: query, requestOptions: requestOptions)
self.init(client: client, indexName: indexName, query: query, isAutoSendingHitsViewEvents: isAutoSendingHitsViewEvents, requestOptions: requestOptions)
Telemetry.shared.trace(type: .hitsSearcher,
parameters: [
.appID,
Expand All @@ -147,34 +149,40 @@ public final class HitsSearcher: IndexSearcher<AlgoliaSearchService> {
- Parameters:
- index: Index value in which search will be performed
- query: Instance of Query. By default a new empty instant of Query will be created.
- isAutoSendingHitsViewEvents: flag defining whether the automatic hits view Insights events sending is enabled
- requestOptions: Custom request options. Default is nil.
*/
public init(client: SearchClient,
indexName: IndexName,
query: Query = .init(),
isAutoSendingHitsViewEvents: Bool = false,
requestOptions: RequestOptions? = nil) {
let service = AlgoliaSearchService(client: client)
let request = AlgoliaSearchService.Request(indexName: indexName, query: query, requestOptions: requestOptions)
super.init(service: service, initialRequest: request)
Telemetry.shared.trace(type: .hitsSearcher,
parameters: .client)
onResults.subscribe(with: self) { searcher, response in
searcher.eventTracker.trackView(for: response.hits,
eventName: "Hits Viewed")
if (isAutoSendingHitsViewEvents) {

Check failure on line 166 in Sources/InstantSearchCore/Searcher/Hits/HitsSearcher.swift

View workflow job for this annotation

GitHub Actions / lint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
searcher.eventTracker.trackView(for: response.hits, eventName: "Hits Viewed")
}
}
}

/**
- Parameters:
- indexQueryState: Instance of `IndexQueryState` encapsulating index value in which search will be performed and a `Query` instance.
- isAutoSendingHitsViewEvents: flag defining whether the automatic hits view Insights events sending is enabled
- requestOptions: Custom request options. Default is nil.
*/
public convenience init(client: SearchClient,
indexQueryState: IndexQueryState,
isAutoSendingHitsViewEvents: Bool = false,
requestOptions: RequestOptions? = nil) {
self.init(client: client,
indexName: indexQueryState.indexName,
query: indexQueryState.query,
isAutoSendingHitsViewEvents: isAutoSendingHitsViewEvents,
requestOptions: requestOptions)
}

Expand Down

0 comments on commit a287cec

Please sign in to comment.