Repository navigation
[CDX-437] Add missing params to search/browse results load events #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
341b7cb
2e8f167
f5e3e81
7255997
59143f7
ea79a1d
e34c623
b0f8327
043c500
aa3da19
eba3e6d
375dab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1564,8 +1564,47 @@ object ConstructorIo { | |
| disposable.add(completable.subscribeOn(Schedulers.io()).subscribe({}, { t -> e("Search Results Loaded error: ${t.message}") })) | ||
| } | ||
|
|
||
| internal fun trackSearchResultsLoadedInternal(term: String, resultCount: Int, customerIds: Array<String>? = null, items: Array<TrackingItem>? = null, analyticsTags: Map<String, String>? = null): Completable { | ||
| /** | ||
| * Tracks search results loaded (a.k.a. search results viewed) events, with support for the | ||
| * result ID, pagination, sorting and selected filters of the search results. | ||
| * | ||
| * Example: | ||
| * ``` | ||
| * val request = SearchResultsLoadedData.build("tooth", 789) { | ||
| * setItems(listOf(TrackingItem("1234", "2345", "camp1234", "owner-A"))) | ||
| * setSectionName("Products") | ||
| * setAnalyticsTags(mapOf("campaign" to "summer_sale")) | ||
| * setResultId("179b8a0e-3799-4a31-be87-127b06871de2") | ||
| * setResultPage(3) | ||
| * setSortOrder("ascending") | ||
| * setSortBy("price") | ||
| * setSelectedFilters(mapOf("brand" to listOf("XYZ"), "color" to listOf("black"))) | ||
| * } | ||
| * ConstructorIo.trackSearchResultsLoaded(request) | ||
| * ``` | ||
| * @param request the search results loaded request object holding all of the tracking parameters | ||
| */ | ||
| fun trackSearchResultsLoaded(request: SearchResultsLoadedData) { | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| val completable = trackSearchResultsLoadedInternal( | ||
| term = request.term, | ||
| resultCount = request.resultCount, | ||
| items = request.items?.toTypedArray(), | ||
|
Alexey-Pavlov marked this conversation as resolved.
|
||
| sectionName = request.sectionName, | ||
| url = request.url, | ||
| analyticsTags = request.analyticsTags, | ||
| resultId = request.resultId, | ||
| resultPage = request.resultPage, | ||
| resultOffset = request.resultOffset, | ||
| sortOrder = request.sortOrder, | ||
| sortBy = request.sortBy, | ||
| selectedFilters = request.selectedFilters | ||
| ) | ||
| disposable.add(completable.subscribeOn(Schedulers.io()).subscribe({}, { t -> e("Search Results Loaded error: ${t.message}") })) | ||
| } | ||
|
|
||
| internal fun trackSearchResultsLoadedInternal(term: String, resultCount: Int, customerIds: Array<String>? = null, items: Array<TrackingItem>? = null, sectionName: String? = null, url: String = "Not Available", analyticsTags: Map<String, String>? = null, resultId: String? = null, resultPage: Int? = null, resultOffset: Int? = null, sortOrder: String? = null, sortBy: String? = null, selectedFilters: Map<String, List<String>>? = null): Completable { | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| preferenceHelper.getSessionId(sessionIncrementHandler) | ||
| val section = sectionName ?: preferenceHelper.defaultItemSection | ||
| val itemsList: List<TrackingItem>? = when { | ||
| items != null -> items.toList() | ||
| customerIds != null -> customerIds.map { id -> TrackingItem(id, null, null, null) } | ||
|
|
@@ -1575,7 +1614,13 @@ object ConstructorIo { | |
| term, | ||
| itemsList, | ||
| resultCount, | ||
| "Not Available", | ||
| resultId, | ||
| resultPage, | ||
| resultOffset, | ||
| sortOrder, | ||
| sortBy, | ||
| selectedFilters, | ||
| url, | ||
| BuildConfig.CLIENT_VERSION, | ||
| preferenceHelper.id, | ||
| preferenceHelper.getSessionId(), | ||
|
|
@@ -1584,7 +1629,7 @@ object ConstructorIo { | |
| configMemoryHolder.segments, | ||
| mergeAnalyticsTags(configMemoryHolder.defaultAnalyticsTags, analyticsTags), | ||
| true, | ||
| preferenceHelper.defaultItemSection, | ||
| section, | ||
| System.currentTimeMillis() | ||
| ) | ||
|
|
||
|
|
@@ -1845,7 +1890,46 @@ object ConstructorIo { | |
| })) | ||
| } | ||
|
|
||
| internal fun trackBrowseResultsLoadedInternal(filterName: String, filterValue: String, itemIds: Array<String>? = null, items: Array<TrackingItem>? = null, resultCount: Int, sectionName: String? = null, url: String = "Not Available", analyticsTags: Map<String, String>? = null): Completable { | ||
| /** | ||
| * Tracks browse result loaded (a.k.a. browse results viewed) events, with support for the | ||
| * result ID, pagination, sorting and selected filters of the browse results. | ||
| * | ||
| * Example: | ||
| * ``` | ||
| * val request = BrowseResultsLoadedData.build("group_id", "Snacks", 674) { | ||
| * setItems(listOf(TrackingItem("1234", "2345", "camp1234", "owner-A"))) | ||
| * setSectionName("Products") | ||
| * setAnalyticsTags(mapOf("campaign" to "summer_sale")) | ||
| * setResultId("179b8a0e-3799-4a31-be87-127b06871de2") | ||
| * setResultPage(3) | ||
| * setSortOrder("ascending") | ||
| * setSortBy("price") | ||
| * setSelectedFilters(mapOf("brand" to listOf("XYZ"), "color" to listOf("black"))) | ||
| * } | ||
| * ConstructorIo.trackBrowseResultsLoaded(request) | ||
| * ``` | ||
| * @param request the browse results loaded request object holding all of the tracking parameters | ||
| */ | ||
| fun trackBrowseResultsLoaded(request: BrowseResultsLoadedData) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The positional arguments used when calling val completable = trackBrowseResultsLoadedInternal(
request.filterName,
request.filterValue,
items = request.items?.toTypedArray(),
...For readability and consistency with val completable = trackBrowseResultsLoadedInternal(
filterName = request.filterName,
filterValue = request.filterValue,
items = request.items?.toTypedArray(),
... |
||
| val completable = trackBrowseResultsLoadedInternal( | ||
| request.filterName, | ||
| request.filterValue, | ||
| items = request.items?.toTypedArray(), | ||
| resultCount = request.resultCount, | ||
| sectionName = request.sectionName, | ||
| url = request.url, | ||
| analyticsTags = request.analyticsTags, | ||
| resultId = request.resultId, | ||
| resultPage = request.resultPage, | ||
| resultOffset = request.resultOffset, | ||
| sortOrder = request.sortOrder, | ||
| sortBy = request.sortBy, | ||
| selectedFilters = request.selectedFilters | ||
| ) | ||
| disposable.add(completable.subscribeOn(Schedulers.io()).subscribe({}, { t -> e("Browse Results Loaded error: ${t.message}") })) | ||
| } | ||
|
|
||
| internal fun trackBrowseResultsLoadedInternal(filterName: String, filterValue: String, itemIds: Array<String>? = null, items: Array<TrackingItem>? = null, resultCount: Int, sectionName: String? = null, url: String = "Not Available", analyticsTags: Map<String, String>? = null, resultId: String? = null, resultPage: Int? = null, resultOffset: Int? = null, sortOrder: String? = null, sortBy: String? = null, selectedFilters: Map<String, List<String>>? = null): Completable { | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| preferenceHelper.getSessionId(sessionIncrementHandler) | ||
| val section = sectionName ?: preferenceHelper.defaultItemSection | ||
| val itemsList: List<TrackingItem>? = when { | ||
|
|
@@ -1858,6 +1942,12 @@ object ConstructorIo { | |
| filterValue, | ||
| itemsList, | ||
| resultCount, | ||
| resultId, | ||
| resultPage, | ||
| resultOffset, | ||
| sortOrder, | ||
| sortBy, | ||
| selectedFilters, | ||
| url, | ||
| BuildConfig.CLIENT_VERSION, | ||
| preferenceHelper.id, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package io.constructor.data.builder | ||
|
|
||
| import io.constructor.data.model.common.TrackingItem | ||
|
|
||
| /** | ||
| * Create a Browse Results Loaded tracking request object utilizing a builder | ||
| */ | ||
| class BrowseResultsLoadedData( | ||
| val filterName: String, | ||
| val filterValue: String, | ||
| val resultCount: Int, | ||
| val items: List<TrackingItem>? = null, | ||
| val sectionName: String? = null, | ||
| val url: String = "Not Available", | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| val analyticsTags: Map<String, String>? = null, | ||
| val resultId: String? = null, | ||
| val resultPage: Int? = null, | ||
| val resultOffset: Int? = null, | ||
| val sortOrder: String? = null, | ||
| val sortBy: String? = null, | ||
| val selectedFilters: Map<String, List<String>>? = null, | ||
| ) { | ||
| private constructor(builder: Builder) : this( | ||
| builder.filterName, | ||
| builder.filterValue, | ||
| builder.resultCount, | ||
| builder.items, | ||
| builder.sectionName, | ||
| builder.url, | ||
| builder.analyticsTags, | ||
| builder.resultId, | ||
| builder.resultPage, | ||
| builder.resultOffset, | ||
| builder.sortOrder, | ||
| builder.sortBy, | ||
| builder.selectedFilters, | ||
| ) | ||
|
|
||
| companion object { | ||
| inline fun build(filterName: String, filterValue: String, resultCount: Int, block: Builder.() -> Unit = {}) = Builder(filterName, filterValue, resultCount).apply(block).build() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: Same mutual-exclusivity concern as fun build(): BrowseResultsLoadedData {
require(resultPage == null || resultOffset == null) {
"Only one of resultPage or resultOffset may be set, not both."
}
return BrowseResultsLoadedData(this)
} |
||
| } | ||
|
|
||
| class Builder( | ||
| val filterName: String, | ||
| val filterValue: String, | ||
| val resultCount: Int | ||
| ) { | ||
| var items: List<TrackingItem>? = null | ||
| var sectionName: String? = null | ||
| var url: String = "Not Available" | ||
| var analyticsTags: Map<String, String>? = null | ||
| var resultId: String? = null | ||
| var resultPage: Int? = null | ||
| var resultOffset: Int? = null | ||
| var sortOrder: String? = null | ||
| var sortBy: String? = null | ||
| var selectedFilters: Map<String, List<String>>? = null | ||
|
|
||
| fun setItems(items: List<TrackingItem>): Builder = apply { this.items = items } | ||
| fun setSectionName(sectionName: String): Builder = apply { this.sectionName = sectionName } | ||
| fun setUrl(url: String): Builder = apply { this.url = url } | ||
| fun setAnalyticsTags(analyticsTags: Map<String, String>): Builder = apply { this.analyticsTags = analyticsTags } | ||
| fun setResultId(resultId: String): Builder = apply { this.resultId = resultId } | ||
| fun setResultPage(resultPage: Int): Builder = apply { this.resultPage = resultPage } | ||
| fun setResultOffset(resultOffset: Int): Builder = apply { this.resultOffset = resultOffset } | ||
| fun setSortOrder(sortOrder: String): Builder = apply { this.sortOrder = sortOrder } | ||
| fun setSortBy(sortBy: String): Builder = apply { this.sortBy = sortBy } | ||
| fun setSelectedFilters(selectedFilters: Map<String, List<String>>): Builder = apply { this.selectedFilters = selectedFilters } | ||
| fun build(): BrowseResultsLoadedData = BrowseResultsLoadedData(this) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package io.constructor.data.builder | ||
|
|
||
| import io.constructor.data.model.common.TrackingItem | ||
|
|
||
| /** | ||
| * Create a Search Results Loaded tracking request object utilizing a builder | ||
| */ | ||
| class SearchResultsLoadedData( | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| val term: String, | ||
| val resultCount: Int, | ||
| val items: List<TrackingItem>? = null, | ||
|
Alexey-Pavlov marked this conversation as resolved.
|
||
| val sectionName: String? = null, | ||
| val url: String = "Not Available", | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| val analyticsTags: Map<String, String>? = null, | ||
| val resultId: String? = null, | ||
| val resultPage: Int? = null, | ||
| val resultOffset: Int? = null, | ||
| val sortOrder: String? = null, | ||
| val sortBy: String? = null, | ||
| val selectedFilters: Map<String, List<String>>? = null, | ||
| ) { | ||
| private constructor(builder: Builder) : this( | ||
| builder.term, | ||
| builder.resultCount, | ||
| builder.items, | ||
| builder.sectionName, | ||
| builder.url, | ||
| builder.analyticsTags, | ||
| builder.resultId, | ||
| builder.resultPage, | ||
| builder.resultOffset, | ||
| builder.sortOrder, | ||
| builder.sortBy, | ||
| builder.selectedFilters, | ||
| ) | ||
|
|
||
| companion object { | ||
| inline fun build(term: String, resultCount: Int, block: Builder.() -> Unit = {}) = Builder(term, resultCount).apply(block).build() | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: The README (and KDoc) comments throughout state that Consider adding a guard in fun build(): SearchResultsLoadedData {
require(resultPage == null || resultOffset == null) {
"Only one of resultPage or resultOffset may be set, not both."
}
return SearchResultsLoadedData(this)
} |
||
| } | ||
|
|
||
| class Builder( | ||
| val term: String, | ||
| val resultCount: Int | ||
| ) { | ||
| var items: List<TrackingItem>? = null | ||
| var sectionName: String? = null | ||
| var url: String = "Not Available" | ||
| var analyticsTags: Map<String, String>? = null | ||
| var resultId: String? = null | ||
| var resultPage: Int? = null | ||
| var resultOffset: Int? = null | ||
| var sortOrder: String? = null | ||
| var sortBy: String? = null | ||
| var selectedFilters: Map<String, List<String>>? = null | ||
|
|
||
| fun setItems(items: List<TrackingItem>): Builder = apply { this.items = items } | ||
| fun setSectionName(sectionName: String): Builder = apply { this.sectionName = sectionName } | ||
| fun setUrl(url: String): Builder = apply { this.url = url } | ||
| fun setAnalyticsTags(analyticsTags: Map<String, String>): Builder = apply { this.analyticsTags = analyticsTags } | ||
| fun setResultId(resultId: String): Builder = apply { this.resultId = resultId } | ||
| fun setResultPage(resultPage: Int): Builder = apply { this.resultPage = resultPage } | ||
| fun setResultOffset(resultOffset: Int): Builder = apply { this.resultOffset = resultOffset } | ||
| fun setSortOrder(sortOrder: String): Builder = apply { this.sortOrder = sortOrder } | ||
| fun setSortBy(sortBy: String): Builder = apply { this.sortBy = sortBy } | ||
| fun setSelectedFilters(selectedFilters: Map<String, List<String>>): Builder = apply { this.selectedFilters = selectedFilters } | ||
| fun build(): SearchResultsLoadedData = SearchResultsLoadedData(this) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,7 @@ class ConstructorIoIntegrationQuizTest { | |
| fun getQuizNextQuestionWithSingleTypeAnswerAgainstRealResponse() { | ||
| val answers = listOf(listOf("1")) | ||
| val request = QuizRequest.Builder("test-quiz") | ||
| .setQuizSessionId("bc48a85d-2f45-4c91-ba3a-dcf655b33831") | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The same hardcoded private val TEST_QUIZ_SESSION_ID = "bc48a85d-2f45-4c91-ba3a-dcf655b33831"This also makes it clearer whether using the same session ID across tests is intentional. |
||
| .setAnswers(answers) | ||
| .build() | ||
| val observer = constructorIo.getQuizNextQuestion(request).test() | ||
|
|
@@ -130,6 +131,7 @@ class ConstructorIoIntegrationQuizTest { | |
| listOf("1", "2") | ||
| ) | ||
| val request = QuizRequest.Builder("test-quiz") | ||
| .setQuizSessionId("bc48a85d-2f45-4c91-ba3a-dcf655b33831") | ||
| .setAnswers(answers) | ||
| .build() | ||
| val observer = constructorIo.getQuizNextQuestion(request).test() | ||
|
|
@@ -157,6 +159,7 @@ class ConstructorIoIntegrationQuizTest { | |
| listOf("seen") | ||
| ) | ||
| val request = QuizRequest.Builder("test-quiz") | ||
| .setQuizSessionId("bc48a85d-2f45-4c91-ba3a-dcf655b33831") | ||
| .setAnswers(answers) | ||
| .build() | ||
| val observer = constructorIo.getQuizNextQuestion(request).test() | ||
|
|
@@ -186,6 +189,7 @@ class ConstructorIoIntegrationQuizTest { | |
| listOf("true") | ||
| ) | ||
| val request = QuizRequest.Builder("test-quiz") | ||
| .setQuizSessionId("bc48a85d-2f45-4c91-ba3a-dcf655b33831") | ||
| .setAnswers(answers) | ||
| .build() | ||
| val observer = constructorIo.getQuizNextQuestion(request).test() | ||
|
|
@@ -208,6 +212,7 @@ class ConstructorIoIntegrationQuizTest { | |
| listOf("seen") | ||
| ) | ||
| val request = QuizRequest.Builder("test-quiz") | ||
| .setQuizSessionId("bc48a85d-2f45-4c91-ba3a-dcf655b33831") | ||
| .setAnswers(answers) | ||
| .build() | ||
| val observer = constructorIo.getQuizResults(request).test() | ||
|
|
@@ -255,7 +260,7 @@ class ConstructorIoIntegrationQuizTest { | |
| listOf("1", "2"), | ||
| listOf("seen") | ||
| ) | ||
| val quizResult = constructorIo.getQuizNextQuestionCRT("test-quiz", answers) | ||
| val quizResult = constructorIo.getQuizNextQuestionCRT("test-quiz", answers, quizSessionId = "bc48a85d-2f45-4c91-ba3a-dcf655b33831") | ||
| assertNotNull(quizResult?.quizId) | ||
| assertNotNull(quizResult?.quizVersionId) | ||
| assertNotNull(quizResult?.quizSessionId) | ||
|
|
@@ -278,7 +283,7 @@ class ConstructorIoIntegrationQuizTest { | |
| listOf("1", "2"), | ||
| listOf("seen") | ||
| ) | ||
| val quizResult = constructorIo.getQuizResultsCRT("test-quiz", answers) | ||
| val quizResult = constructorIo.getQuizResultsCRT("test-quiz", answers, quizSessionId = "bc48a85d-2f45-4c91-ba3a-dcf655b33831") | ||
| assertEquals(quizResult?.quizId, "test-quiz"); | ||
| assertNotNull(quizResult?.quizVersionId) | ||
| assertNotNull(quizResult?.quizSessionId) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.