-
Notifications
You must be signed in to change notification settings - Fork 3
[CDX-487] Add trackSearchSubmit that supports analytics tags #173
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
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package io.constructor.data.builder | ||
|
|
||
| import io.constructor.data.model.common.ResultGroup | ||
|
|
||
| /** | ||
| * Create a Search Submit tracking request object utilizing a builder | ||
| */ | ||
| class SearchSubmitTrackingData( | ||
|
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 primary constructor is // This compiles and bypasses the builder:
SearchSubmitTrackingData("term", "query", null, mapOf("k" to "v"))If the intent is to enforce usage through the builder DSL, consider making the primary constructor |
||
| val searchTerm: String, | ||
| val originalQuery: String, | ||
| val resultGroup: ResultGroup? = null, | ||
| val analyticsTags: Map<String, String>? = null, | ||
| ) { | ||
| private constructor(builder: Builder) : this( | ||
| builder.searchTerm, | ||
| builder.originalQuery, | ||
| builder.resultGroup, | ||
| builder.analyticsTags, | ||
| ) | ||
|
|
||
| companion object { | ||
| inline fun build( | ||
| searchTerm: String, | ||
| originalQuery: String, | ||
| block: Builder.() -> Unit = {} | ||
| ) = Builder(searchTerm, originalQuery).apply(block).build() | ||
| } | ||
|
|
||
| class Builder( | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| val searchTerm: String, | ||
| val originalQuery: String | ||
| ) { | ||
| var resultGroup: ResultGroup? = null | ||
| var analyticsTags: Map<String, String>? = null | ||
|
|
||
| fun setResultGroup(resultGroup: ResultGroup): Builder = apply { this.resultGroup = resultGroup } | ||
| fun setAnalyticsTags(analyticsTags: Map<String, String>): Builder = apply { this.analyticsTags = analyticsTags } | ||
| fun build(): SearchSubmitTrackingData = SearchSubmitTrackingData(this) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import io.constructor.data.memory.ConfigMemoryHolder | |
| import io.constructor.data.model.common.ResultGroup | ||
| import io.constructor.data.model.purchase.PurchaseItem | ||
| import io.constructor.data.model.common.TrackingItem | ||
| import io.constructor.data.builder.SearchSubmitTrackingData | ||
| import io.constructor.test.createTestDataManager | ||
| import io.constructor.util.RxSchedulersOverrideRule | ||
| import io.mockk.every | ||
|
|
@@ -340,18 +341,43 @@ class ConstructorIoTrackingTest { | |
| val observer = ConstructorIo.trackSearchSubmitInternal("titanic", "tit", null).test() | ||
| observer.assertComplete() | ||
| val request = mockServer.takeRequest() | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&analytics_tags%5BappVersion%5D=123&analytics_tags%5BappPlatform%5D=Android&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
| assert(request.path!!.startsWith(path)) | ||
| } | ||
|
|
||
| @Test | ||
| fun trackSearchSubmitWithAnalyticsTags() { | ||
| val mockResponse = MockResponse().setResponseCode(204) | ||
| mockServer.enqueue(mockResponse) | ||
| val observer = ConstructorIo.trackSearchSubmitInternal("titanic", "tit", null, mapOf("test" to "test1", "appVersion" to "150")).test() | ||
| observer.assertComplete() | ||
| val request = mockServer.takeRequest() | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&analytics_tags%5BappVersion%5D=150&analytics_tags%5BappPlatform%5D=Android&analytics_tags%5Btest%5D=test1&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
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 test asserts a specific URL parameter order that relies on the iteration order of However, relying on query-parameter ordering for correctness is brittle — HTTP servers are not required to treat parameter order as significant, and a future change to the test setup's |
||
| assert(request.path!!.startsWith(path)) | ||
| } | ||
|
|
||
| @Test | ||
| fun trackSearchSubmitWithRequestBuilder() { | ||
|
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: There is no error path test for the new public |
||
| val mockResponse = MockResponse().setResponseCode(204) | ||
| mockServer.enqueue(mockResponse) | ||
| val request = SearchSubmitTrackingData.build("titanic", "tit") { | ||
| setResultGroup(ResultGroup("Movies", "group_id")) | ||
| setAnalyticsTags(mapOf("relatedSearchTerm" to "true")) | ||
| } | ||
| ConstructorIo.trackSearchSubmit(request) | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| val recordedRequest = mockServer.takeRequest() | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&group%5Bgroup_id%5D=group_id&group%5Bdisplay_name%5D=Movies&analytics_tags%5BappVersion%5D=123&analytics_tags%5BappPlatform%5D=Android&analytics_tags%5BrelatedSearchTerm%5D=true&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
| assert(recordedRequest.path!!.startsWith(path)) | ||
| } | ||
|
|
||
| @Test | ||
| fun trackSearchSubmit500() { | ||
| val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") | ||
| mockServer.enqueue(mockResponse) | ||
| val observer = ConstructorIo.trackSearchSubmitInternal("titanic", "tit", null).test() | ||
| observer.assertError { true } | ||
| val request = mockServer.takeRequest() | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&analytics_tags%5BappVersion%5D=123&analytics_tags%5BappPlatform%5D=Android&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
| assert(request.path!!.startsWith(path)) | ||
| } | ||
|
|
||
|
|
@@ -363,7 +389,7 @@ class ConstructorIoTrackingTest { | |
| val observer = ConstructorIo.trackSearchSubmitInternal("titanic", "tit", null).test() | ||
| observer.assertError(SocketTimeoutException::class.java) | ||
| val request = mockServer.takeRequest() | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
| val path = "/autocomplete/titanic/search?original_query=tit&tr=search&analytics_tags%5BappVersion%5D=123&analytics_tags%5BappPlatform%5D=Android&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.44.0&_dt=" | ||
| assert(request.path!!.startsWith(path)) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: This constant uses a
%sformat placeholder, making it a format string rather than a plain constant. Consider documenting this expectation with a brief KDoc comment (e.g.,/** Format string; supply the tag key as the argument, e.g. ANALYTICS_TAGS.format("myKey") */) to make the intended usage clear to future maintainers. This is especially important since the pattern differs from all other constants in this object, which are plain strings.