Skip to content

Commit

Permalink
fix(insights): control auto sending events w/ `isAutoSendingHitsViewE…
Browse files Browse the repository at this point in the history
…vents` (#314)

* fix(insights): add a parameter to enable/disable auto sending events

* fix linter

* Update Sources/InstantSearchCore/Searcher/Hits/HitsSearcher.swift

Co-authored-by: Haroen Viaene <[email protected]>

* change params order

---------

Co-authored-by: Haroen Viaene <[email protected]>
  • Loading branch information
aallam and Haroenv authored May 16, 2024
1 parent b084cc7 commit 8573411
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 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(),
requestOptions: RequestOptions? = nil) {
requestOptions: RequestOptions? = nil,
isAutoSendingHitsViewEvents: Bool = false) {
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, requestOptions: requestOptions, isAutoSendingHitsViewEvents: isAutoSendingHitsViewEvents)
Telemetry.shared.trace(type: .hitsSearcher,
parameters: [
.appID,
Expand All @@ -147,35 +149,42 @@ 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(),
requestOptions: RequestOptions? = nil) {
requestOptions: RequestOptions? = nil,
isAutoSendingHitsViewEvents: Bool = false) {
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 {
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,
requestOptions: RequestOptions? = nil) {
requestOptions: RequestOptions? = nil,
isAutoSendingHitsViewEvents: Bool = false) {
self.init(client: client,
indexName: indexQueryState.indexName,
query: indexQueryState.query,
requestOptions: requestOptions)
requestOptions: requestOptions,
isAutoSendingHitsViewEvents: isAutoSendingHitsViewEvents
)
}

deinit {
Expand Down

0 comments on commit 8573411

Please sign in to comment.