Skip to content

Commit 2207209

Browse files
authored
Update readme docs to replace deprecated token generate functions with new ones which handle opt-out (#32)
1 parent ed88979 commit 2207209

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,33 @@ If you're using the SDK's HTTP implementation, follow these steps.
4444

4545
`private final PublisherUid2Client publisherUid2Client = new PublisherUid2Client(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);`
4646

47-
2. When the user has authenticated, and has authorized the creation of a UID2, call a function that takes the user's email address or phone number as input and generates an `IdentityTokens` object. The following example uses an email address:
48-
49-
`IdentityTokens identity = publisherUid2Client.generateToken(TokenGenerateInput.fromEmail(emailAddress));`
47+
2. Call a function that takes the user's email address or phone number as input and generates a `TokenGenerateResponse` object. The following example uses an email address:
5048

49+
`TokenGenerateResponse tokenGenerateResponse = publisherUid2Client.generateTokenResponse(TokenGenerateInput.fromEmail(emailAddress).doNotGenerateTokensForOptedOut());`
50+
51+
>IMPORTANT: Be sure to call this function only when you have obtained legal basis to convert the user’s [directly identifying information (DII)](https://unifiedid.com/docs/ref-info/glossary-uid#gl-dii) to UID2 tokens for targeted advertising.
52+
53+
>`doNotGenerateTokensForOptedOut()` applies `policy=1` in the [/token/generate](https://unifiedid.com/docs/endpoints/post-token-generate#token-generation-policy) call. Without this, `policy` is omitted to maintain backwards compatibility.
5154
#### Standard Integration
5255

53-
If you're using standard integration (client and server) (see [Client-Side JavaScript SDK Integration Guide](https://unifiedid.com/docs/guides/publisher-client-side)), follow this step:
56+
If you're using standard integration (client and server) (see [UID2 SDK for JavaScript Integration Guide](https://unifiedid.com/docs/guides/publisher-client-side)), follow this step:
5457

5558
* Send this identity as a JSON string back to the client (to use in the [identity field](https://unifiedid.com/docs/sdks/client-side-identity#initopts-object-void)) using the following:
5659

57-
`identity.getJsonString()`
60+
`tokenGenerateResponse.getIdentityJsonString()` //Note: this method returns `null` if the user has opted out, so be sure to handle that case.
5861

5962
#### Server-Only Integration
6063

6164
If you're using server-only integration (see [Publisher Integration Guide, Server-Only](https://unifiedid.com/docs/guides/custom-publisher-integration)):
6265

63-
1. Store this identity as a JSON string in the user's session, using the `identity.getJsonString()` function.
64-
2. To use the user's UID2 token, use the `identity.getAdvertisingToken()` function.
65-
3. When the user accesses another page, or on a timer, determine whether a refresh is needed:
66+
1. Store this identity as a JSON string in the user's session, using the `tokenGenerateResponse.getIdentityJsonString()` function. This method returns `null` if the user has opted out, so be sure to handle that case.
67+
2. To retrieve the user's UID2 token, use:
68+
69+
```
70+
IdentityTokens identity = tokenGenerateResponse.getIdentity();
71+
if (identity != null) { String advertisingToken = identity.getAdvertisingToken(); }
72+
```
73+
4. When the user accesses another page, or on a timer, determine whether a refresh is needed:
6674
1. Retrieve the identity JSON string from the user's session, and then call the following function that takes the identity information as input and generates an `IdentityTokens` object:
6775

6876
`IdentityTokens identity = IdentityTokens.fromJsonString(identityJsonString);`
@@ -72,44 +80,53 @@ If you're using server-only integration (see [Publisher Integration Guide, Serve
7280
3. Determine if a refresh is needed:
7381

7482
`if (identity.isDueForRefresh()) {..}`
75-
4. If needed, refresh the token and associated values:
83+
5. If needed, refresh the token and associated values:
7684

7785
`TokenRefreshResponse tokenRefreshResponse = publisherUid2Client.refreshToken(identity);`
7886

79-
5. Store `tokenRefreshResponse.getIdentityJsonString()` in the user's session. If the user has opted out, this method returns null, indicating that the user's identity should be removed from the session. To confirm optout, you can use the `tokenRefreshResponse.isOptout()` function.
87+
6. Store `tokenRefreshResponse.getIdentityJsonString()` in the user's session. If the user has opted out, this method returns `null`, indicating that the user's identity should be removed from the session. To confirm optout, you can use the `tokenRefreshResponse.isOptout()` function.
8088

8189
### Advanced Usage
8290

8391
1. Create an instance of PublisherUid2Helper as an instance variable:
8492

8593
`private final PublisherUid2Helper publisherUid2Helper = new PublisherUid2Helper(UID2_SECRET_KEY);`
86-
2. When the user has authenticated, and has authorized the creation of a UID2, call a function that takes the user's email address or phone number as input and creates a secure request data envelope. See [Encrypting requests](https://unifiedid.com/docs/getting-started/gs-encryption-decryption#encrypting-requests). The following example uses an email address:
94+
2. Call a function that takes the user's email address or phone number as input and creates a secure request data envelope. See [Encrypting requests](https://unifiedid.com/docs/getting-started/gs-encryption-decryption#encrypting-requests). The following example uses an email address:
8795

88-
`EnvelopeV2 envelope = publisherUid2Helper.createEnvelopeForTokenGenerateRequest(TokenGenerateInput.fromEmail(emailAddress));`
96+
`EnvelopeV2 envelope = publisherUid2Helper.createEnvelopeForTokenGenerateRequest(TokenGenerateInput.fromEmail(emailAddress).doNotGenerateTokensForOptedOut());`
8997
3. Using an HTTP client library of your choice, post this envelope to the [POST token/generate](https://unifiedid.com/docs/endpoints/post-token-generate) endpoint, including headers and body:
9098
1. Headers: Depending on your HTTP library, this might look something like the following:
9199

92100
`.putHeader("Authorization", "Bearer " + UID2_API_KEY)`
93101
`.putHeader("X-UID2-Client-Version", PublisherUid2Helper.getVersionHeader())`
94102
2. Body: `envelope.getEnvelope()`
95-
4. If the HTTP response status code is _not_ 200, see [Response Status Codes](https://unifiedid.com/docs/endpoints/post-token-generate#response-status-codes) to determine next steps. Otherwise, convert the UID2 identity response content into an `IdentityTokens` object:
103+
>IMPORTANT: Be sure to call this endpoint only when you have obtained legal basis to convert the user’s [directly identifying information (DII)](https://unifiedid.com/docs/ref-info/glossary-uid#gl-dii) to UID2 tokens for targeted advertising.
104+
105+
>`doNotGenerateTokensForOptedOut()` applies `policy=1` in the [/token/generate](https://unifiedid.com/docs/endpoints/post-token-generate#token-generation-policy) call. Without this, `policy` is omitted to maintain backwards compatibility.
96106
97-
`IdentityTokens identity = publisherUid2Helper.createIdentityfromTokenGenerateResponse({response body}, envelope);`
107+
4. If the HTTP response status code is _not_ 200, see [Response Status Codes](https://unifiedid.com/docs/endpoints/post-token-generate#response-status-codes) to determine next steps. Otherwise, convert the UID2 identity response content into a `TokenGenerateResponse` object:
108+
109+
`TokenGenerateResponse tokenGenerateResponse = publisherUid2Helper.createTokenGenerateResponse({response body}, envelope);`
98110

99111
#### Standard Integration
100112

101-
If you're using standard integration (client and server) (see [Client-Side JavaScript SDK Integration Guide](https://unifiedid.com/docs/guides/publisher-client-side)):
113+
If you're using standard integration (client and server) (see [UID2 SDK for JavaScript Integration Guide](https://unifiedid.com/docs/guides/publisher-client-side)):
102114

103115
* Send this identity as a JSON string back to the client (to use in the [identity field](https://unifiedid.com/docs/sdks/client-side-identity#initopts-object-void)) using the following:
104116

105-
`identity.getJsonString()`
117+
`tokenGenerateResponse.getIdentityJsonString() //Note: this method returns null if the user has opted out, so be sure to handle that case.`
106118

107119
#### Server-Only Integration
108120

109121
If you're using server-only integration (see [Publisher Integration Guide, Server-Only](https://unifiedid.com/docs/guides/custom-publisher-integration)):
110122

111-
1. Store this identity as a JSON string in the user's session, using: `identity.getJsonString()`.
112-
2. To use the user's UID2 token, use `identity.getAdvertisingToken()`.
123+
1. Store this identity as a JSON string in the user's session, using: `tokenGenerateResponse.getIdentityJsonString()`. This method returns null if the user has opted out, so be sure to handle that case.
124+
2. To retrieve the user's UID2 token, use:
125+
126+
```
127+
IdentityTokens identity = tokenGenerateResponse.getIdentity();
128+
if (identity != null) { String advertisingToken = identity.getAdvertisingToken(); }
129+
```
113130

114131
3. When the user accesses another page, or on a timer, determine whether a refresh is needed:
115132
1. Retrieve the identity JSON string from the user's session, and then call the following function that generates an `IdentityTokens` object:

0 commit comments

Comments
 (0)