Learn about the reset API call in Kotlin and Swift SDKs.
4 minute read
This guide explains how to use the reset API in Kotlin and Swift SDKs.
Overview
The RudderStack Kotlin and Swift SDKs provide a reset API that lets you clear the persisted data, for example, user ID and traits.
The SDK also does the following once you call the reset API:
Generates a new anonymousId (default behavior)
If session tracking is enabled, clears the current sessionId and generates a new one.
If a mobile device mode integration plugin is present, then calling the reset API also triggers the integration’s reset API — provided it is supported.
Selective reset: Choose specific data points to reset while preserving others
Default behavior
By default, calling the reset API clears all persisted user data including user ID and traits, refreshes session information, and generates a new anonymous ID.
analytics.reset()
The corresponding Java snippet is shown below:
analytics.reset();
analytics.reset()
The corresponding Objective-C snippet is shown below:
[analyticsreset];
Selective reset
You can also use the reset API to choose which specific data components to reset while preserving others. This way, you have granular control over each component — you can regenerate the anonymous ID, clear the user ID, clear traits, or refresh session information, or preserve any of these values as per your requirement.
To perform a selective reset, the SDKs provide a options parameter that accepts a ResetOptions object with the following structure:
The following table describes the parameters accepted by the entries object of ResetOptions:
Parameter
Description
Default value
anonymousId
Resets the anonymous user ID.
true
userId
Resets the persisted user ID.
true
traits
Resets the persisted user traits.
true
session
Resets the current session information.
true
All entries in the ResetOptions.entries object are optional. If you do not specify any entry, the SDK sets its default value as described in the above table.
Examples
This section provides examples of how to perform a selective reset by using the reset API with different entries parameters.
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.