UID2 API Documentation > v1 > Integration Guides > Publisher Integration Guide
This guide covers integration steps for publishers with web assets who would like to generate identity tokens utilizing UID2 for the bid stream. This guide focuses on publishers who would like to integrate directly with UID2 to create and manage tokens rather than integrate with UID2-enabled single-sign-on or identity providers.
The following integration steps outline the lifecycle for a user establishing a UID2 token with a publisher and how the UID2 token integrates with the RTB bid stream.
This section focuses on publisher-specific steps 1-d, 1-e, and 1-f illustrated in the above diagram.
Note
The UID2 token must only be generated on the server side after authentication. Security concerns forbid token generation on the browser side.
Step | Endpoint/SDK | Instruction |
---|---|---|
d | GET /token/generate | There are two ways for publishers to establish identity with UID2. 1. Integrate with a UID2-enabled single-sign-on provider. 2. Generate UID2 tokens when a user authenticates using the GET /token/generate endpoint. The request includes a user's normalized email address. |
e | GET /token/generate | The token generation service returns UID2 tokens. |
f | UID2 client-side identity SDK | Send returned UID2 tokens from step e to the SDK using identity mechanism below. The mechanism ensures UID2 tokens are available for the user until they logout. |
<script>
__uid2.init({
identity : <Response from the generate token api>
});
</script>
This section focuses on publisher-specific step 2-a illustrated in the above diagram.
Step | Endpoint/SDK | Instruction |
---|---|---|
a | UID2 client-side identity SDK | The established identity is available client-side for bidding. The mechnanism below returns access to a user's advertising_token to pass to SSPs. |
<script>
__uid2.getAdvertisingToken();
</script>
Step | Endpoint/SDK | Instruction |
---|---|---|
a | UID2 client-side identity SDK | The SDK automatically refreshes UID2 tokens. No manual action is required. |
b | UID2 client-side identity SDK | If a user hasn't opted out, the refresh token returns new identity tokens. |
If you decide to integrate using options other than the SDK, we recommend refreshing identity tokens every 5 minutes.
Step | Endpoint/SDK | Instruction |
---|---|---|
a | The user logs out from a publisher asset. | |
b | UID2 client-side identity SDK | Remove UID2 tokens from the user's local storage when they log out. Use the disconnect mechanism from the SDK to clear out UID2 tokens. |
<script>
__uid2.disconnect();
</script>
The token refresh process handles user opt-outs. If a user opts out, using their refresh token automatically clears their session. UID2 client-side SDK. No manual action is required.
There are two built-in tools you can use to test your integration.
You can use the GET /token/validate endpoint to check whether the PII you are sending through GET /token/generate is valid.
- Send a GET /token/generate request using
[email protected]
asemail
, or create a base64-encoded SHA256 hash of[email protected]
and send it through as an email hash. Store theadvertising_token
returned to use in step 2. - Send a GET /token/validate request using the
email
oremail_hash
you sent in step 1 and thetoken
as theadvertising_token
returned in step 1. If the response returnstrue
, theemail
oremail_hash
you sent as a request in step 1 match the token you received in the response of step 1. If it returnsfalse
, there may be an issue with the way you are sending email addresses or email hashes.
You can use the email address [email protected]
to test your token refresh workflow. Using this email for the request always generates an identity response with a refresh_token
that results in a logout response.
- Send a GET /token/generate request using
[email protected]
asemail
, or create a base64-encoded SHA256 hash of[email protected]
and send it through as an email hash. Store therefresh_token
returned to use in step 2. - Send a GET /token/validate request using the
email
oremail_hash
you sent in step 1 and therefresh_token
as therefresh_token
returned in step 1. Thebody
response should be empty because the[email protected]
email always results in a logged out refresh token.