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

new no identity available event #184

Merged
merged 28 commits into from
Feb 25, 2025

Conversation

ashleysmithTTD
Copy link
Contributor

No description provided.

@@ -52,7 +53,6 @@ export class CallbackManager {
public runCallbacks(event: EventType, payload: CallbackPayload) {
if (event === EventType.InitCompleted) this._sentInit = true;
if (event === EventType.SdkLoaded) CallbackManager._sentSdkLoaded[this._productName] = true;
if (!this._sentInit && event !== EventType.SdkLoaded) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With everything that can be done without init, I dont think it makes sense anymore to not run callbacks if init is not complete


const enrichedPayload = {
...payload,
identity: this._getIdentity() ?? null,
};
if (event === EventType.NoIdentityAvailable && enrichedPayload.identity) {
enrichedPayload.identity = null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this because it was sending the expired or opted out identity back, but I thought this may be confusing if we are sending a "no identity available" event, but then attaching an identity.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this. It seems possible that someone could be expecting an expired identity and then acting on it in some way. this could be a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took this check out. Will add info to the docs to denote the two types of identities that can be returned with this event (null or expired)

src/sdkBase.ts Outdated
return identity;
}
}

Copy link
Contributor Author

@ashleysmithTTD ashleysmithTTD Feb 14, 2025

Choose a reason for hiding this comment

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

Callback uses getIdentity for its payload but once I added the possibility of the no identity available event, it ended up in an endless loop of callback events. So callback needed its own getIdentity function that does not run an event - getIdentityForCallback() is identical to the old getIdentity() function. Set it to private since its just internal

src/sdkBase.ts Outdated
return this.isIdentityValid() || this._apiClient?.hasActiveRequests();
const identity = this._identity ?? this.getIdentityNoInit();
const identityAvailable =
(this.isIdentityValid(identity) && !this.temporarilyUnavailable(identity)) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this extra check because identity can be valid, but unavailable

!previousOpts.identity ||
opts.identity.identity_expires > previousOpts.identity.identity_expires;
}

Copy link
Contributor Author

@ashleysmithTTD ashleysmithTTD Feb 14, 2025

Choose a reason for hiding this comment

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

found in testing that we didnt have the possibility that opts.identity just doesn't exist, which would automatically make useNewIdentity true

src/sdkBase.ts Outdated
}

public getIdentity(): Identity | null {
const identity = this._identity ?? this.getIdentityNoInit();
const isValid =
identity && !this.temporarilyUnavailable(identity) && !isOptoutIdentity(identity);
Copy link
Contributor

Choose a reason for hiding this comment

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

an Optout Identity if valid so I don't think we want that in this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was here before - and when I remove OptoutIdentity, it does change the return value of getIdentity. If I update the return value, it then errors on getAdvertisingToken(). I think we need to make we (and the docs) are clear if an opted out identity is valid

Copy link
Contributor

Choose a reason for hiding this comment

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

seems the code always checks for optout separately so it assumes a valid identity will have a particular shape. So this is fine.

Copy link
Contributor

@ssundahlTTD ssundahlTTD left a comment

Choose a reason for hiding this comment

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

a couple of comments,

@ashleysmithTTD ashleysmithTTD merged commit ae0688f into main Feb 25, 2025
3 checks passed
@ashleysmithTTD ashleysmithTTD deleted the ans-UID2-2295-no-identity-available-event branch February 25, 2025 20:40
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

Successfully merging this pull request may close these issues.

2 participants