[CDX-471] Support passing itemID in trackAutocompleteSelect#168
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the SDK’s autocomplete select tracking API to optionally send an itemID (item_id query param), allowing consumers to attribute a selection to a specific item when available.
Changes:
- Added optional
itemIDparameter totrackAutocompleteSelect(and internal implementation) and plumbed it into the request query params. - Added a unit test asserting
item_idis included in the autocomplete select tracking request. - Updated README with an example showing how to pass
itemID.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| README.md | Adds documentation example for passing itemID to autocomplete select tracking. |
| library/src/main/java/io/constructor/core/ConstructorIo.kt | Adds optional itemID to the public/internal autocomplete select tracking API and includes it in encoded params. |
| library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt | Adds coverage for item_id being emitted in the tracking URL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fun trackAutocompleteSelect(searchTerm: String, originalQuery: String, sectionName: String, resultGroup: ResultGroup? = null, resultID: String? = null, itemID: String? = null) { | ||
| var completable = trackAutocompleteSelectInternal(searchTerm, originalQuery, sectionName, resultGroup, resultID, itemID) |
| // Track when the user submits a search (searchTerm, originalQuery) | ||
| ConstructorIo.trackSearchSubmit("toothpicks", "tooth") |
There was a problem hiding this comment.
Code Review
This PR adds an itemID parameter to trackAutocompleteSelect, wiring it through to the existing getEncodedParams machinery — a clean, minimal change that follows established patterns. The implementation is correct and consistent with the rest of the codebase.
Inline comments: 3 discussions added
Overall Assessment:
| fun trackAutocompleteSelect(searchTerm: String, originalQuery: String, sectionName: String, resultGroup: ResultGroup? = null, resultID: String? = null) { | ||
| var completable = trackAutocompleteSelectInternal(searchTerm, originalQuery, sectionName, resultGroup, resultID) | ||
| fun trackAutocompleteSelect(searchTerm: String, originalQuery: String, sectionName: String, resultGroup: ResultGroup? = null, resultID: String? = null, itemID: String? = null) { | ||
| var completable = trackAutocompleteSelectInternal(searchTerm, originalQuery, sectionName, resultGroup, resultID, itemID) |
There was a problem hiding this comment.
Suggestion: The completable variable is assigned once and never reassigned, so it should be val rather than var. The same pattern exists on the previous line of the original code (var completable = ...), but since this PR touches this function it's worth fixing here.
val completable = trackAutocompleteSelectInternal(searchTerm, originalQuery, sectionName, resultGroup, resultID, itemID)| fun trackAutocompleteSelectWithItemID() { | ||
| val mockResponse = MockResponse().setResponseCode(204) | ||
| mockServer.enqueue(mockResponse) | ||
| val observer = ConstructorIo.trackAutocompleteSelectInternal("titanic", "tit", "Products", null, null, "TIT-REP-1997").test() |
There was a problem hiding this comment.
Suggestion: Passing null, null as positional arguments for resultGroup and resultID is hard to read and fragile — if the parameter order changes, this silently breaks. The existing codebase already uses named arguments (e.g. in getEncodedParams calls), and the trackAutocompleteSelectInternal signature supports them too. Prefer:
val observer = ConstructorIo.trackAutocompleteSelectInternal(
"titanic", "tit", "Products",
resultGroup = null, resultID = null, itemID = "TIT-REP-1997"
).test()Or, since the parameters have defaults, simply omit the nulls:
val observer = ConstructorIo.trackAutocompleteSelectInternal(
"titanic", "tit", "Products", itemID = "TIT-REP-1997"
).test()| // Track when the user selects an autocomplete suggestion (searchTerm, originalQuery, sectionName) | ||
| ConstructorIo.trackAutocompleteSelect("toothpicks", "tooth", "Search Suggestions") | ||
|
|
||
| // Track when the user selects an autocomplete suggestion with an item ID (searchTerm, originalQuery, sectionName, resultGroup, resultID, itemID) |
There was a problem hiding this comment.
Suggestion: The comment documents all six parameters including resultGroup and resultID, but neither appears in the example call below. This makes the comment misleading. Since the call only uses itemID as a named argument, the comment could simply reflect the params that matter:
// Track when the user selects an autocomplete suggestion with an item ID (searchTerm, originalQuery, sectionName, itemID)
ConstructorIo.trackAutocompleteSelect("Fashionable Toothpicks", "tooth", "Products", itemID = "1234567-AB")
Support passing an
itemIDparameter to the existingtrackAutocompleteSelectfunction.1 test added ✅