Skip to content

Allow for userId to be passed to track calls for server-side use #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

Closed
wickstopher opened this issue Jun 22, 2023 · 3 comments
Closed
Assignees

Comments

@wickstopher
Copy link

Is your feature request related to a problem? Please describe.
Currently, correlating a track event to an individual user on the server requires making an identify call prior to any track calls. We'd like to avoid making frequent server-side identify calls as they aren't particularly useful to us, but would still like to be able to correlate a track event with a specific userId. This appears to be possible in the Java library. From your documentation:

analytics.enqueue(TrackMessage.builder("Item Purchased")
    .userId("f4ca124298")
    .properties(ImmutableMap.builder()
        .put("revenue", 39.95)
        .put("shipping", "2-day")
        .build()
    )
);

Describe the solution you'd like
Add an overload for the com.segment.analytics.kotlin.core.Analytics::track method that accepts a userId, e.g.

track(
    userId = "12345", 
    name = "Event Name", 
    properties = JsonObject(mapOf("attribute" to JsonPrimitive("value")))
)

Describe alternatives you've considered
The only feasible alternative at the moment appears to be switching to the Java library.

Additional context
Add any other context or screenshots about the feature request here.

@wenxi-zeng
Copy link
Contributor

@wickstopher please refer to #112 for solution

@wickstopher
Copy link
Author

Thanks for the solution; this seems like a reasonable stopgap for avoiding switching to the Java library, but it would be nice to see this functionality ported over from your other SDKs. Has there been any consideration of separating out a server-side SDK for Kotlin that does not contain all of the Android dependencies and concerns?

@wenxi-zeng
Copy link
Contributor

wenxi-zeng commented Jun 22, 2023

@wickstopher glad to hear it solves your problem. the plugin architecture is designed to provide customizability. since this use case can be addressed by a plugin in a relatively simple way, we are not going to add a new API for it.

when adding dependency of the SDK, make sure you use core instead of android to avoid importing unnecessary android dependencies. see kotlin server doc here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants