You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are a content publisher interested in generating identity tokens utilizing UID2 for the RTB bid stream, you can build and run either of the two example applications to see how you can use the UID2 services and which integration fits your needs best.
4
+
5
+
Both examples illustrate the basic steps that you need to consider for your integration. For example, you need to decide how to implement user login and logout, how to manage UID2 identity information and use it for targeted advertising, how to refresh tokens, deal with missing identities, and handle user opt-outs.
6
+
7
+
The following table summarizes both examples.
8
+
9
+
| Example Documentation | Primary Audience | Example Description | Integration Steps |
10
+
| :--- | :--- | :--- | :--- |
11
+
|[UID2 SDK Integration Example](./publisher/standard/README.md)| Publishers with web assets | Demonstrates how to use the UID2 services with the [Client-Side Identity JavaScript SDK](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md) (also known as the UID2 SDK) to implement the standard UID2 integration workflow. |[UID2 SDK Integration Guide](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/guides/publisher-client-side.md)|
12
+
|[Server-Only UID2 Integration Example](./publisher/server_only/README.md)| App developers and CTV broadcasters | Demonstrates how to use the UID2 services to implement a custom (server-only) UID2 integration workflow without relying on an SDK for establishing client UID2 identity and retrieving advertising tokens. |[Server-Only UID2 Integration Guide](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/guides/custom-publisher-integration.md)|
13
+
14
+
The documentation for each example includes instructions on how to build and run the application and suggests steps that you may take to test and explore it. Each step is annotated with comments that explain what takes place on the backend and how the UID2 services work.
This example demonstrates how a content publisher can work with UID2 services and UID2 JavaScript SDK
4
-
to implement the standard UID2 publisher integration workflow (XREF).
3
+
This example demonstrates how a content publisher can use the UID2 services and the [Client-Side Identity JavaScript SDK](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md) (also known as the UID2 SDK) to implement the [standard UID2 integration workflow](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/guides/publisher-client-side.md).
5
4
6
-
While the server side of the example application is implemented in JavaScript using node.js, it is not
7
-
a requirement. The server side can be implemented using any technology of your choice, and you can use
8
-
the example application as a reference of the functionality that needs to be implemented.
5
+
For an example application without using the UID2 SDK, see [Server-Only UID2 Integration Example](../server_only/README.md).
9
6
10
-
## Building and Running the Example
7
+
>NOTE: While the server side of the example application is implemented in JavaScript using node.js, it is not
8
+
a requirement. You can use any technology of your choice and refer to the example application for illustration of the functionality that needs to be implemented.
11
9
12
-
The easiest way to trying the example is to rely on docker:
10
+
## Build and Run the Example Application
11
+
12
+
The easiest way to try the example is to use the following docker build command:
The following parameters must be specified in form of environment variables to start the application:
22
+
The following table lists the environment variables that you must specify to start the application.
23
23
24
-
|Setting| Description |
25
-
| :--- | :--- |
26
-
|`UID2_BASE_URL`|Base URL of the UID2 services. For example, production uid2 services are available on`https://prod.uidapi.com`|
27
-
|`UID2_API_KEY`| Your UID2 authentication key for the UID2 service above. |
24
+
|Parameter | Data Type| Description |
25
+
| :--- | :--- | :--- |
26
+
|`UID2_BASE_URL`|string | The base URL of the UID2 service. For example:</br>Testing environment: `https://integ.uidapi.com`<br/>Production environment:`https://prod.uidapi.com`|
27
+
|`UID2_API_KEY`|string |Your UID2 authentication key for the UID2 service specified in `UID2_BASE_URL`. |
28
28
29
-
Once the application starts up successfully, you should see output similar to below:
29
+
After you see output similar to the following, the example application is up and running.
30
30
31
31
```
32
32
> uid2-publisher@1.0.0 start /usr/src/app
33
33
> node server.js
34
34
35
35
Example app listening at http://localhost:3000
36
36
```
37
+
If needed, to close the application, terminate the docker container or use the `Ctrl+C` keyboard shortcut.
37
38
38
-
You should then be able to navigate to the application's main page in your browser: `http://localhost:3000`.
39
-
40
-
You can quit the application by terminating the docker container or by hitting `Ctrl+C`.
41
-
42
-
## Key Points
43
-
44
-
Example follows the steps of the UID2 publisher integration workflow (XREF).
45
-
46
-
The index page provides a login form for the user to complete the UID2 login process. A real application
47
-
would need to display information for user to express their consent to targeted advertising.
48
-
49
-
Once the user supplies their email address and hit the `Login` button, they will hit the `/login` endpoint (XREF to server.js).
50
-
The login process on the server side will call `GET /token/generate` (XREF) and process the received response.
51
-
If the response indicates success, the returned identity (`body` properity of the response JSON) will be passed
52
-
to the `login` view (XREF to file) for rendering client side JavaScript.
39
+
## Test the Example Application
53
40
54
-
The client side JavaScript calls the UID2 client SDK `init()` function passing it the identity from `/token/generate`.
55
-
If the identity is valid, it will be stored in a first party UID2 cookie for use on subsequent page loads.
41
+
The example application illustrates the steps documented in the [UID2 SDK Integration Guide](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/guides/publisher-client-side.md). For an overview of the high-level workflow for establishing UID2 identity, API reference, and explanation of the UID2 cookie format, see [Client-Side Identity JavaScript SDK](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md).
56
42
57
-
Next the user can navigate back to the main (index) page. The page view (XREF to index view) calls the `init()`
58
-
function this time without passing an explicit identity, requesting for it to be loaded from the first party cookie
59
-
instead. When the UID2 finishes initialising, it will invoke the passed callback function `onUid2IdentityUpdated()`.
60
-
The callback will update the page elements with the state of UID2 identity: it is the place where one should place
61
-
their logic for initiating targeted advertising.
43
+
The following table outlines and annotates the steps you may take to test and explore the example application.
62
44
63
-
As the user keeps the page open or as they keep refreshing it over time, the UID2 JavaScript SDK will be validating
64
-
whether the advertising token is up-to-date and refresh it automatically when needed. If the refresh succeeds, or
65
-
if the user opts out, or the refresh token expires, the callback function will be invoked and the UI elements
66
-
will be updated with the current state of UID2 identity.
45
+
| Step | Description | Comments |
46
+
| :---: | :--- | :--- |
47
+
| 1 | In your browser, navigate to the application main page at `http://localhost:3000`. | The displayed main ([index](views/index.html)) page of the example application provides a login form for the user to complete the UID2 login process.</br>IMPORTANT: A real-life application must also display a form for the user to express their consent to targeted advertising. |
48
+
| 2 | In the text field at the bottom, enter the user email address that you want to use for testing and click **Log In**. | This is a call to the `/login` endpoint ([server.js](server.js)). The login initiated on the server side then calls the [GET /token/generate](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/endpoints/get-token-generate.md#response-format) endpoint and processes the received response. |
49
+
|| A confirmation message appears with the established UID2 identity information. | The displayed identity information is the `body` property of the [JSON response payload](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/endpoints/get-token-generate.md#response-format) from the `GET /token/generate` response. It has been passed to the `login`[view](views/login.html) for rendering client-side JavaScript. Next, the identity information is passed to the [UID2 SDK `init()` function](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#initopts-object-void). If the identity is valid, the SDK stores it in a [first-party UID2 cookie](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#uid2-cookie-format) for use on subsequent page loads. |
50
+
| 3 | Click the **Back to the main page** link. | On the updated application main page, note the newly populated **UID2 Advertising Token** value. The [page view](views/index.html) calls the [init() function](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#initopts-object-void) again, but this time without passing an explicit identity. Instead, the identity is loaded from the first-party cookie. |
51
+
| 4 | (Optional) Right-click the main page to inspect the source code. | When the UID2 SDK initialization is complete, the SDK invokes the passed [callback function](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#callback-function) (`onUid2IdentityUpdated()` in this example).</br>IMPORTANT: The callback updates the page elements with the state of UID2 identity: this is the place where you should define your logic for initiating targeted advertising. |
52
+
| 5 | Keep the application main page open or refresh it after awhile 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 States and Transitions](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#workflow-states-and-transitions) and [Background Token Auto-Refresh](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#background-token-auto-refresh). |
53
+
| 6 | To exit the application, click **Log Out**. | This calls the [UID2 SDK `disconnect()` function](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#disconnect-void), which clears the UID2 session and the first-party cookie. This call also makes the [UID2 SDK `isLoginRequired()` function](https://github.com/UnifiedID2/uid2docs/blob/main/api/v1/sdks/client-side-identity-v1.md#isloginrequired-boolean) 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. |
67
54
68
-
While the user identity is valid (refreshable), the page will display a logout button. User clicking the button
69
-
would lead to UID2 SDK `disconnect()` function being called which would clear the UID2 session and the first party
70
-
cookie. User will be presented with the login form again.
0 commit comments