Skip to content
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

Add identify overload with anonymousId param #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,34 @@ open class Analytics protected constructor(
track(name, properties, JsonAnySerializer.serializersModule.serializer(), enrichment)
}

/**
* Identify lets you tie one of your users and their actions to a recognizable {@code userId}.
* It also lets you record {@code traits} about the user, like their email, name, account type,
* etc.
*
* <p>Traits and userId will be automatically cached and available on future sessions for the
* same user. To update a trait on the server, call identify with the same user id.
* You can also use {@link #identify(Traits)} for this purpose.
*
* In the case when user logs out, make sure to call {@link #reset()} to clear user's identity
* info.
*
* @param userId Unique identifier which you recognize a user by in your own database
* @param anonymousId Anonymous id to associate with the user
* @param traits [Traits] about the user.
* @param enrichment a closure that enables enrichment on the generated event
* @see <a href="https://segment.com/docs/spec/identify/">Identify Documentation</a>
*/
@JvmOverloads
fun identify(userId: String, anonymousId: String, traits: JsonObject = emptyJsonObject, enrichment: EnrichmentClosure? = null) {
analyticsScope.launch(analyticsDispatcher) {
store.dispatch(UserInfo.SetUserIdAndTraitsAction(userId, traits), UserInfo::class)
store.dispatch(UserInfo.SetAnonymousIdAction(anonymousId), UserInfo::class)
}
val event = IdentifyEvent(userId = userId, traits = traits)
process(event, enrichment)
}

/**
* Identify lets you tie one of your users and their actions to a recognizable {@code userId}.
* It also lets you record {@code traits} about the user, like their email, name, account type,
Expand Down