Skip to content

fix: identifyRequest intake when persistent data exists #1014

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

Open
wants to merge 2 commits into
base: development
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
35 changes: 34 additions & 1 deletion src/sessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { Messages } = Constants;

export interface ISessionManager {
initialize: () => void;
isIdentifyNeeded: () => boolean;
getSessionId: () => string;
startNewSession: () => void;
endSession: (override?: boolean) => void;
Expand Down Expand Up @@ -47,7 +48,11 @@ export default function SessionManager(
} else {
// https://go.mparticle.com/work/SQDSDKS-6045
const persistence: IPersistenceMinified = mpInstance._Persistence.getPersistence();
if (persistence && !persistence.cu) {

// If isIdentifyNeeded() returns `true`, we will force the
// identify() call, regardless of whether any user data is
// already persisted.
if (this.isIdentifyNeeded() || (persistence && !persistence.cu)) {
// https://go.mparticle.com/work/SQDSDKS-6323
mpInstance.Identity.identify(
mpInstance._Store.SDKConfig.identifyRequest,
Expand All @@ -62,6 +67,34 @@ export default function SessionManager(
}
};

/**
* Returns `true` if `userIdentities` is an empty object but the config's
* `identifyRequest` has at least a `customerid`.
*/
this.isIdentifyNeeded = function(): boolean {
const user = mpInstance.Identity.getCurrentUser()
let needsToIdentify = false

if (user) {
const storedUserIdentities = user
.getUserIdentities()?.userIdentities
const hasStoredCustomerId =
storedUserIdentities != null &&
typeof storedUserIdentities.customerid !== "undefined"

const identifyRequest = mpInstance._Store.SDKConfig.identifyRequest
const identifyRequestHasCustomerId =
identifyRequest != null &&
typeof identifyRequest.userIdentities.customerid !== "undefined"

if (!hasStoredCustomerId && identifyRequestHasCustomerId) {
needsToIdentify = true
}
}

return needsToIdentify
}

this.getSession = function(): string {
mpInstance.Logger.warning(
generateDeprecationMessage(
Expand Down