Skip to content

Commit 6bc7d44

Browse files
replace isloginrequired with no identity available function
1 parent 69ae6f7 commit 6bc7d44

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

examples/cstg/html/index.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@
2727
$('#targeted_advertising_ready').text(sdk.getAdvertisingToken() ? 'yes' : 'no');
2828
$('#advertising_token').text(String(sdk.getAdvertisingToken()));
2929
$('#login_required').text(
30-
sdk.isLoginRequired() || sdk.isLoginRequired() === undefined ? 'yes' : 'no'
31-
);
32-
$(`#has_opted_out`).text(
33-
sdk.hasOptedOut() ? 'yes' : 'no'
30+
sdk.noIdentityAvailable() || sdk.noIdentityAvailable() === undefined ? 'yes' : 'no'
3431
);
32+
$(`#has_opted_out`).text(sdk.hasOptedOut() ? 'yes' : 'no');
3533
$('#update_counter').text(callbackCounter);
3634
$('#identity_state').text(String(JSON.stringify(state, null, 2)));
3735

3836
updateSharedGuiElements();
3937
}
4038

4139
function updateSharedGuiElements() {
42-
if (getUidSdk().isLoginRequired()) {
40+
if (getUidSdk().noIdentityAvailable()) {
4341
$('#login_form').show();
4442
$('#logout_form').hide();
4543
} else {
@@ -65,10 +63,11 @@
6563
});
6664

6765
$('#login').click(async () => {
68-
const email = $('#email').val();
66+
//const email = $('#email').val();
67+
const phone = $('#email').val();
6968

7069
try {
71-
await getUidSdk().setIdentityFromEmail(email, clientSideIdentityOptions);
70+
await getUidSdk().setIdentityFromPhoneHash(phone, clientSideIdentityOptions);
7271
} catch (e) {
7372
console.error('setIdentityFromEmail failed', e);
7473
}

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 [`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. |
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. |

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.isLoginRequired() ? "yes" : "no");
20+
$("#login_required").html(__uid2.noIdentityAvailable() ? "yes" : "no");
2121
$("#update_counter").html(callbackCounter);
2222
$("#identity_state").html(String(JSON.stringify(payload, null, 2)));
2323

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<meta charset="UTF-8" />
@@ -18,7 +18,7 @@
1818
});
1919
}
2020
if (eventType === 'InitCompleted') {
21-
if (__uid2.isLoginRequired()) __uid2.setIdentity(<%- JSON.stringify(identity) %>)
21+
if (__uid2.noIdentityAvailable()) __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.isLoginRequired()).toEqual(false);
20+
expect(uid2.noIdentityAvailable()).toEqual(false);
2121

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

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

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

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

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

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

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

src/sdkBase.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,22 @@ export abstract class SdkBase {
182182
}
183183

184184
/**
185-
* Deprecated
185+
* @deprecated in version 3.9.0. Use noIdentityAvailable() instead
186186
*/
187-
public isLoginRequired() {
188-
return this.hasIdentity();
187+
public noIdentityAvailable() {
188+
return this.noIdentityAvailable();
189189
}
190190

191-
public hasIdentity() {
191+
public noIdentityAvailable() {
192192
if (!this._initComplete) return undefined;
193193
return !(this.isLoggedIn() || this._apiClient?.hasActiveRequests());
194194
}
195195

196+
// public hasIdentity() {
197+
// if (!this._initComplete) return undefined;
198+
// return !(this.isLoggedIn() || this._apiClient?.hasActiveRequests());
199+
// }
200+
196201
public hasOptedOut() {
197202
if (!this._initComplete) return undefined;
198203
return isOptoutIdentity(this._identity);
@@ -439,7 +444,7 @@ export abstract class SdkBase {
439444
clearTimeout(this._refreshTimerId);
440445
}
441446
this._refreshTimerId = setTimeout(() => {
442-
if (this.isLoginRequired()) return;
447+
if (this.noIdentityAvailable()) return;
443448
const validatedIdentity = this.validateAndSetIdentity(
444449
this._storageManager?.loadIdentity() ?? null
445450
);

0 commit comments

Comments
 (0)