diff --git a/examples/cstg/html/index.html b/examples/cstg/html/index.html
index 658555f..d248b47 100644
--- a/examples/cstg/html/index.html
+++ b/examples/cstg/html/index.html
@@ -27,7 +27,7 @@
$('#targeted_advertising_ready').text(sdk.getAdvertisingToken() ? 'yes' : 'no');
$('#advertising_token').text(String(sdk.getAdvertisingToken()));
$('#login_required').text(
- sdk.noIdentityAvailable() || sdk.noIdentityAvailable() === undefined ? 'yes' : 'no'
+ sdk.isLoginRequired() || sdk.isLoginRequired() === undefined ? 'yes' : 'no'
);
$(`#has_opted_out`).text(sdk.hasOptedOut() ? 'yes' : 'no');
$('#update_counter').text(callbackCounter);
@@ -37,7 +37,7 @@
}
function updateSharedGuiElements() {
- if (getUidSdk().noIdentityAvailable()) {
+ if (getUidSdk().isLoginRequired()) {
$('#login_form').show();
$('#logout_form').hide();
} else {
diff --git a/examples/google-secure-signals-integration/with_sdk_v3/README.md b/examples/google-secure-signals-integration/with_sdk_v3/README.md
index 68350be..b0b97e0 100644
--- a/examples/google-secure-signals-integration/with_sdk_v3/README.md
+++ b/examples/google-secure-signals-integration/with_sdk_v3/README.md
@@ -73,4 +73,4 @@ The following table outlines and annotates the steps you can take to test and ex
| 3 | Click the **Back to the main page** link. | On the updated application main page, note the newly populated **UID2 Advertising Token** value and a video player. While the [page view](views/index.html) is loading, [GPT](https://developers.google.com/publisher-tag/reference#googletag) auto-loads the Secure Signal UID2 script which pushes the advertising token to GPT local storage, and the [IMA](https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side) makes an ad request which transmits the encoded signal in the request. The [page view](views/index.html) calls the [init()](https://unifiedid.com/docs/sdks/client-side-identity#initopts-object-void) function again, but this time without passing an explicit identity. Instead, the identity is loaded from the first-party cookie. |
| 4 | Click **Play**. | This triggers AdsManager to insert the ad returned from the ad request, for display. The ad tag used in this example contains a 10-second pre-roll ad. |
| 5 | Keep the application main page open, or refresh it after a while, and note the UID2 identity state, updated counter, and login information values. | In the background, the UID2 SDK continuously validates whether the advertising token is up to date, and refreshes it automatically when needed. If the refresh succeeds, the user opts out, or the refresh token expires, the callback function is invoked, and the UI elements are updated with the current state of the UID2 identity. For details, see [Workflow Overview](https://unifiedid.com/docs/sdks/client-side-identity#workflow-overview) and [Background Token Auto-Refresh](https://unifiedid.com/docs/sdks/client-side-identity#background-token-auto-refresh). |
-| 6 | To exit the application, click **Log Out**. | This calls the UID2 SDK [`disconnect()`](https://unifiedid.com/docs/sdks/client-side-identity#disconnect-void) function, which clears the UID2 session and the first-party cookie and calls the Secure Signal [`clearAllCache()`](https://developers.google.com/publisher-tag/reference#googletag.secureSignals.SecureSignalProvidersArray_clearAllCache) function to clear all cached signals. This call also makes the UID2 SDK [`noIdentityAvailable()`](https://unifiedid.com/docs/sdks/client-side-identity#noIdentityAvailable-boolean) function return `true`, which presents the user with the login form again.
NOTE: The page displays the **Log Out** button as long as the user identity is valid and refreshable. |
+| 6 | To exit the application, click **Log Out**. | This calls the UID2 SDK [`disconnect()`](https://unifiedid.com/docs/sdks/client-side-identity#disconnect-void) function, which clears the UID2 session and the first-party cookie and calls the Secure Signal [`clearAllCache()`](https://developers.google.com/publisher-tag/reference#googletag.secureSignals.SecureSignalProvidersArray_clearAllCache) function to clear all cached signals. This call also makes the UID2 SDK [`isLoginRequired()`](https://unifiedid.com/docs/sdks/client-side-identity#isLoginRequired-boolean) function return `true`, which presents the user with the login form again.
NOTE: The page displays the **Log Out** button as long as the user identity is valid and refreshable. |
diff --git a/examples/google-secure-signals-integration/with_sdk_v3/views/index.html b/examples/google-secure-signals-integration/with_sdk_v3/views/index.html
index 0d2152e..8b969a4 100644
--- a/examples/google-secure-signals-integration/with_sdk_v3/views/index.html
+++ b/examples/google-secure-signals-integration/with_sdk_v3/views/index.html
@@ -17,11 +17,11 @@
__uid2.getAdvertisingToken() ? "yes" : "no"
);
$("#advertising_token").html(String(__uid2.getAdvertisingToken()));
- $("#login_required").html(__uid2.noIdentityAvailable() ? "yes" : "no");
+ $("#login_required").html(__uid2.isLoginRequired() ? "yes" : "no");
$("#update_counter").html(callbackCounter);
$("#identity_state").html(String(JSON.stringify(payload, null, 2)));
- if (__uid2.noIdentityAvailable()) {
+ if (__uid2.isLoginRequired()) {
$("#login_form").show();
$("#logout_form").hide();
$('#googleAdContainer').hide();
diff --git a/examples/google-secure-signals-integration/with_sdk_v3/views/login.html b/examples/google-secure-signals-integration/with_sdk_v3/views/login.html
index bdd5d52..b9c8ba3 100644
--- a/examples/google-secure-signals-integration/with_sdk_v3/views/login.html
+++ b/examples/google-secure-signals-integration/with_sdk_v3/views/login.html
@@ -18,7 +18,7 @@
});
}
if (eventType === 'InitCompleted') {
- if (__uid2.noIdentityAvailable()) __uid2.setIdentity(<%- JSON.stringify(identity) %>)
+ if (__uid2.isLoginRequired()) __uid2.setIdentity(<%- JSON.stringify(identity) %>)
}
});
diff --git a/setupJest.js b/setupJest.js
index ff89490..347db21 100644
--- a/setupJest.js
+++ b/setupJest.js
@@ -17,47 +17,47 @@ expect.extend({
expect(uid2.getAdvertisingToken()).toBeNonEmptyString();
}
- expect(uid2.noIdentityAvailable()).toEqual(false);
+ expect(uid2.isLoginRequired()).toEqual(false);
return {
pass: true,
message: () =>
- 'Expected getAdvertisingToken() returns a token and noIdentityAvailable() returns false',
+ 'Expected getAdvertisingToken() returns a token and isLoginRequired() returns false',
};
},
toBeInTemporarilyUnavailableState(uid2) {
expect(uid2.getAdvertisingToken()).toBeUndefined();
- expect(uid2.noIdentityAvailable()).toEqual(false);
+ expect(uid2.isLoginRequired()).toEqual(false);
return {
pass: true,
message: () =>
- 'Expected getAdvertisingToken() returns undefined and noIdentityAvailable() returns false',
+ 'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns false',
};
},
toBeInUnavailableState(uid2) {
expect(uid2.getAdvertisingToken()).toBeUndefined();
- expect(uid2.noIdentityAvailable()).toEqual(true);
+ expect(uid2.isLoginRequired()).toEqual(true);
expect(uid2.hasOptedOut()).toEqual(false);
return {
pass: true,
message: () =>
- 'Expected getAdvertisingToken() returns undefined and noIdentityAvailable() returns true',
+ 'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns true',
};
},
toBeInOptoutState(uid2) {
expect(uid2.getAdvertisingToken()).toBeUndefined();
- expect(uid2.noIdentityAvailable()).toEqual(false);
+ expect(uid2.isLoginRequired()).toEqual(false);
expect(uid2.hasOptedOut()).toEqual(true);
return {
pass: true,
message: () =>
- 'Expected getAdvertisingToken() returns undefined and noIdentityAvailable() returns false',
+ 'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns false',
};
},
});
diff --git a/src/sdkBase.ts b/src/sdkBase.ts
index 64b0c9e..5b880c3 100644
--- a/src/sdkBase.ts
+++ b/src/sdkBase.ts
@@ -181,16 +181,20 @@ export abstract class SdkBase {
return this._initComplete;
}
- /**
- * @deprecated in version 3.9.0. Use noIdentityAvailable() instead
- */
public isLoginRequired() {
- return this.noIdentityAvailable();
+ return !this.isIdentityAvailable();
}
- public noIdentityAvailable() {
+ /**
+ * @deprecated in version 3.10.0. Will remove in June 2025. Use isIdentityAvailable() instead.
+ **/
+ public hasIdentity() {
if (!this._initComplete) return undefined;
- return !(this.isLoggedIn() || this._apiClient?.hasActiveRequests());
+ return !(this.isIdentityValid() || this._apiClient?.hasActiveRequests());
+ }
+
+ public isIdentityAvailable() {
+ return this.isIdentityValid() || this._apiClient?.hasActiveRequests();
}
public hasOptedOut() {
@@ -295,8 +299,9 @@ export abstract class SdkBase {
if (this.hasOptedOut()) this._callbackManager.runCallbacks(EventType.OptoutReceived, {});
}
- private isLoggedIn() {
- return this._identity && !hasExpired(this._identity.refresh_expires);
+ private isIdentityValid() {
+ const identity = this._identity ?? this.getIdentityNoInit();
+ return identity && !hasExpired(identity.refresh_expires);
}
private temporarilyUnavailable(identity: Identity | OptoutIdentity | null | undefined) {
@@ -439,7 +444,7 @@ export abstract class SdkBase {
clearTimeout(this._refreshTimerId);
}
this._refreshTimerId = setTimeout(() => {
- if (this.noIdentityAvailable()) return;
+ if (this.isLoginRequired()) return;
const validatedIdentity = this.validateAndSetIdentity(
this._storageManager?.loadIdentity() ?? null
);