Skip to content

Commit 4869277

Browse files
created new is identity available function
1 parent c86dfb9 commit 4869277

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

examples/cstg/html/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
$('#targeted_advertising_ready').text(sdk.getAdvertisingToken() ? 'yes' : 'no');
2828
$('#advertising_token').text(String(sdk.getAdvertisingToken()));
2929
$('#login_required').text(
30-
sdk.noIdentityAvailable() || sdk.noIdentityAvailable() === undefined ? 'yes' : 'no'
30+
sdk.isLoginRequired() || sdk.isLoginRequired() === undefined ? 'yes' : 'no'
3131
);
3232
$(`#has_opted_out`).text(sdk.hasOptedOut() ? 'yes' : 'no');
3333
$('#update_counter').text(callbackCounter);
@@ -37,7 +37,7 @@
3737
}
3838

3939
function updateSharedGuiElements() {
40-
if (getUidSdk().noIdentityAvailable()) {
40+
if (getUidSdk().isLoginRequired()) {
4141
$('#login_form').show();
4242
$('#logout_form').hide();
4343
} else {

examples/google-secure-signals-integration/with_sdk_v3/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ The following table outlines and annotates the steps you can take to test and ex
7373
| 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. |
7474
| 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. |
7575
| 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). |
76-
| 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.<br/> NOTE: The page displays the **Log Out** button as long as the user identity is valid and refreshable. |
76+
| 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.<br/> NOTE: The page displays the **Log Out** button as long as the user identity is valid and refreshable. |

examples/google-secure-signals-integration/with_sdk_v3/views/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
__uid2.getAdvertisingToken() ? "yes" : "no"
1818
);
1919
$("#advertising_token").html(String(__uid2.getAdvertisingToken()));
20-
$("#login_required").html(__uid2.noIdentityAvailable() ? "yes" : "no");
20+
$("#login_required").html(__uid2.isLoginRequired() ? "yes" : "no");
2121
$("#update_counter").html(callbackCounter);
2222
$("#identity_state").html(String(JSON.stringify(payload, null, 2)));
2323

24-
if (__uid2.noIdentityAvailable()) {
24+
if (__uid2.isLoginRequired()) {
2525
$("#login_form").show();
2626
$("#logout_form").hide();
2727
$('#googleAdContainer').hide();

examples/google-secure-signals-integration/with_sdk_v3/views/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
});
1919
}
2020
if (eventType === 'InitCompleted') {
21-
if (__uid2.noIdentityAvailable()) __uid2.setIdentity(<%- JSON.stringify(identity) %>)
21+
if (__uid2.isLoginRequired()) __uid2.setIdentity(<%- JSON.stringify(identity) %>)
2222
}
2323
});
2424
</script>

setupJest.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,47 @@ expect.extend({
1717
expect(uid2.getAdvertisingToken()).toBeNonEmptyString();
1818
}
1919

20-
expect(uid2.noIdentityAvailable()).toEqual(false);
20+
expect(uid2.isLoginRequired()).toEqual(false);
2121

2222
return {
2323
pass: true,
2424
message: () =>
25-
'Expected getAdvertisingToken() returns a token and noIdentityAvailable() returns false',
25+
'Expected getAdvertisingToken() returns a token and isLoginRequired() returns false',
2626
};
2727
},
2828

2929
toBeInTemporarilyUnavailableState(uid2) {
3030
expect(uid2.getAdvertisingToken()).toBeUndefined();
31-
expect(uid2.noIdentityAvailable()).toEqual(false);
31+
expect(uid2.isLoginRequired()).toEqual(false);
3232

3333
return {
3434
pass: true,
3535
message: () =>
36-
'Expected getAdvertisingToken() returns undefined and noIdentityAvailable() returns false',
36+
'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns false',
3737
};
3838
},
3939

4040
toBeInUnavailableState(uid2) {
4141
expect(uid2.getAdvertisingToken()).toBeUndefined();
42-
expect(uid2.noIdentityAvailable()).toEqual(true);
42+
expect(uid2.isLoginRequired()).toEqual(true);
4343
expect(uid2.hasOptedOut()).toEqual(false);
4444

4545
return {
4646
pass: true,
4747
message: () =>
48-
'Expected getAdvertisingToken() returns undefined and noIdentityAvailable() returns true',
48+
'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns true',
4949
};
5050
},
5151

5252
toBeInOptoutState(uid2) {
5353
expect(uid2.getAdvertisingToken()).toBeUndefined();
54-
expect(uid2.noIdentityAvailable()).toEqual(false);
54+
expect(uid2.isLoginRequired()).toEqual(false);
5555
expect(uid2.hasOptedOut()).toEqual(true);
5656

5757
return {
5858
pass: true,
5959
message: () =>
60-
'Expected getAdvertisingToken() returns undefined and noIdentityAvailable() returns false',
60+
'Expected getAdvertisingToken() returns undefined and isLoginRequired() returns false',
6161
};
6262
},
6363
});

src/sdkBase.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,20 @@ export abstract class SdkBase {
181181
return this._initComplete;
182182
}
183183

184-
/**
185-
* @deprecated in version 3.9.0. Use noIdentityAvailable() instead
186-
*/
187184
public isLoginRequired() {
188-
return this.noIdentityAvailable();
185+
return !this.isIdentityAvailable();
189186
}
190187

191-
public noIdentityAvailable() {
188+
/**
189+
* @deprecated in version 3.10.0. Will remove in June 2025. Use isIdentityAvailable() instead.
190+
**/
191+
public hasIdentity() {
192192
if (!this._initComplete) return undefined;
193-
return !(this.isLoggedIn() || this._apiClient?.hasActiveRequests());
193+
return !(this.isIdentityValid() || this._apiClient?.hasActiveRequests());
194+
}
195+
196+
public isIdentityAvailable() {
197+
return this.isIdentityValid() || this._apiClient?.hasActiveRequests();
194198
}
195199

196200
public hasOptedOut() {
@@ -295,8 +299,9 @@ export abstract class SdkBase {
295299
if (this.hasOptedOut()) this._callbackManager.runCallbacks(EventType.OptoutReceived, {});
296300
}
297301

298-
private isLoggedIn() {
299-
return this._identity && !hasExpired(this._identity.refresh_expires);
302+
private isIdentityValid() {
303+
const identity = this._identity ?? this.getIdentityNoInit();
304+
return identity && !hasExpired(identity.refresh_expires);
300305
}
301306

302307
private temporarilyUnavailable(identity: Identity | OptoutIdentity | null | undefined) {
@@ -439,7 +444,7 @@ export abstract class SdkBase {
439444
clearTimeout(this._refreshTimerId);
440445
}
441446
this._refreshTimerId = setTimeout(() => {
442-
if (this.noIdentityAvailable()) return;
447+
if (this.isLoginRequired()) return;
443448
const validatedIdentity = this.validateAndSetIdentity(
444449
this._storageManager?.loadIdentity() ?? null
445450
);

0 commit comments

Comments
 (0)