Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ ConstructorIo.trackInputFocus("")
// 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)
Comment thread
constructor-claude-bedrock[bot] marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

ConstructorIo.trackAutocompleteSelect("Fashionable Toothpicks", "tooth", "Products", itemID = "1234567-AB")

// Track when the user submits a search (searchTerm, originalQuery)
ConstructorIo.trackSearchSubmit("toothpicks", "tooth")
Comment on lines 530 to 531
```
Expand Down
9 changes: 5 additions & 4 deletions library/src/main/java/io/constructor/core/ConstructorIo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1448,18 +1448,19 @@ object ConstructorIo {
* @param sectionName the section the selection came from, i.e. "Search Suggestions"
* @param resultGroup the group to search within if a user selected to search in a group, i.e. "Pumpkin in Canned Goods"
* @param resultID the result ID of the autocomplete response that the selection came from
* @param itemID the item ID of the selection, i.e. "ITEM-123"
*/
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) {
Comment thread
constructor-claude-bedrock[bot] marked this conversation as resolved.
var completable = trackAutocompleteSelectInternal(searchTerm, originalQuery, sectionName, resultGroup, resultID, itemID)
Comment thread
constructor-claude-bedrock[bot] marked this conversation as resolved.
Comment on lines +1453 to +1454

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

disposable.add(completable.subscribeOn(Schedulers.io()).subscribe({
context.broadcastIntent(Constants.EVENT_QUERY_SENT, Constants.EXTRA_TERM to searchTerm)
}, {
t -> e("Autocomplete Select error: ${t.message}")
}))
}
internal fun trackAutocompleteSelectInternal(searchTerm: String, originalQuery: String, sectionName: String, resultGroup: ResultGroup? = null, resultID: String? = null): Completable {
internal fun trackAutocompleteSelectInternal(searchTerm: String, originalQuery: String, sectionName: String, resultGroup: ResultGroup? = null, resultID: String? = null, itemID: String? = null): Completable {
preferenceHelper.getSessionId(sessionIncrementHandler)
val encodedParams: ArrayList<Pair<String, String>> = getEncodedParams(groupId = resultGroup?.groupId, groupDisplayName = resultGroup?.displayName, resultId = resultID)
val encodedParams: ArrayList<Pair<String, String>> = getEncodedParams(groupId = resultGroup?.groupId, groupDisplayName = resultGroup?.displayName, resultId = resultID, itemId = itemID)

return dataManager.trackAutocompleteSelect(searchTerm, arrayOf(
Constants.QueryConstants.SECTION to sectionName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,17 @@ class ConstructorIoTrackingTest {
assert(request.path!!.startsWith(path))
}

@Test
fun trackAutocompleteSelectWithItemID() {
val mockResponse = MockResponse().setResponseCode(204)
mockServer.enqueue(mockResponse)
val observer = ConstructorIo.trackAutocompleteSelectInternal("titanic", "tit", "Products", null, null, "TIT-REP-1997").test()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

observer.assertComplete()
val request = mockServer.takeRequest()
val path = "/autocomplete/titanic/select?section=Products&original_query=tit&tr=click&item_id=TIT-REP-1997&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-2.41.0&_dt="
assert(request.path!!.startsWith(path))
}

@Test
fun trackAutocompleteSelectWithServerError() {
val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error")
Expand Down
Loading