Skip to content

Commit 8c63dba

Browse files
committed
add publisher usage to the README.md
1 parent 6c50fde commit 8c63dba

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,57 @@ Additional examples are in the [examples] directory:
2727
* [sample_client.py](examples/sample_client.py)
2828
* Includes an example to encrypt a raw UID2 into an advertising token for UID2 sharing.
2929

30+
## Usage for Publishers
31+
32+
1. Create an instance of Uid2PublisherClient
33+
34+
`client = Uid2PublisherClient(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY)`
35+
36+
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:
37+
38+
`token_generate_response = client.generate_token(TokenGenerateInput.from_email(emailAddress).do_not_generate_tokens_for_opted_out())`
39+
40+
>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.
41+
42+
>`do_not_generate_tokens_for_opted_out()` 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.
43+
44+
### Standard Integration
45+
46+
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:
47+
48+
* 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:
49+
50+
`token_generate_response.get_identity_json_string()` //Note: this method returns `None` if the user has opted out, so be sure to handle that case.
51+
52+
### Server-Only Integration
53+
54+
If you're using server-only integration (see [Publisher Integration Guide, Server-Only](https://unifiedid.com/docs/guides/custom-publisher-integration)):
55+
56+
1. Store this identity as a JSON string in the user's session, using the `token_generate_response.get_identity_json_string()` function. This method returns `None` if the user has opted out, so be sure to handle that case.
57+
2. To retrieve the user's UID2 token, use:
58+
59+
```
60+
identity = token_generate_response.get_identity()
61+
if identity:
62+
advertising_token = identity.get_advertising_token()
63+
```
64+
4. When the user accesses another page, or on a timer, determine whether a refresh is needed:
65+
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:
66+
67+
`identity = IdentityTokens.from_json_string(identityJsonString)`
68+
2. Determine if the identity can be refreshed (that is, the refresh token hasn't expired):
69+
70+
` if not identity or not identity.is_refreshable(): # we must no longer use this identity (for example, remove this identity from the user's session) `
71+
3. Determine if a refresh is needed:
72+
73+
`if identity.is_due_for_refresh()):`
74+
5. If needed, refresh the token and associated values:
75+
76+
`token_refresh_response = client.refresh_token(identity)`
77+
78+
6. Store `token_refresh_response.get_identity_json_string()` in the user's session. If the user has opted out, this method returns `None`, indicating that the user's identity should be removed from the session. To confirm optout, you can use the `token_refresh_response.is_optout()` function.
79+
80+
3081
## Development
3182

3283
First, build the Docker image with Python 3.6 and all dev dependencies. This is required for all subsequent commands. Run the following:

examples/sample_token_generate_refresh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ def _usage():
2020

2121
publisher_client = Uid2PublisherClient(base_url, auth_key, secret_key)
2222
print("Generating Token")
23-
token_generate_response = publisher_client.generate_token(TokenGenerateInput.from_email("test@email.com"))
23+
token_generate_response = publisher_client.generate_token(TokenGenerateInput.from_email("test@email.com").do_not_generate_tokens_for_opted_out())
2424

2525
status = token_generate_response.status
2626
tokens = token_generate_response.get_identity()
27+
2728
advertising_token = tokens.get_advertising_token()
2829
refresh_token = tokens.get_refresh_token()
2930
refresh_response_key = tokens.get_refresh_response_key()

uid2_client/encryption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def encrypt_data(data, identity_scope, **kwargs):
264264
265265
The keyword arguments key, keys, site_id and advertising_token can only be used in
266266
the following combinations:
267-
- key: use the specied key
267+
- key: use the specified key
268268
- keys and site_id: find the key for the specified site_id
269269
- keys and advertising_token: extract site_id from the token and find a key for it
270270
"""

0 commit comments

Comments
 (0)