Skip to content

Commit 60df732

Browse files
added identity-map-v3 to python sdk docs
1 parent f205be8 commit 60df732

File tree

1 file changed

+163
-7
lines changed

1 file changed

+163
-7
lines changed

docs/sdks/sdk-ref-python.md

Lines changed: 163 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Decryption response codes, and their meanings, are shown in the following table.
145145
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:
146146

147147
```py
148-
token_generate_response = client.generate_token(TokenGenerateInput.from_email(emailAddress).do_not_generate_tokens_for_opted_out())
148+
token_generate_response = client.generate_token(TokenGenerateInput.from_email("[email protected]").do_not_generate_tokens_for_opted_out())
149149
```
150150

151151
<!-- :::important
@@ -183,7 +183,7 @@ If you're using server-side integration (see [Publisher Integration Guide, Serve
183183
identity = token_generate_response.get_identity()
184184
if identity:
185185
advertising_token = identity.get_advertising_token()
186-
```
186+
```
187187
3. Periodically check if the user's UID2 token should be refreshed. This can be done at fixed intervals using a timer, or can be done whenever the user accesses another page:
188188
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:
189189

@@ -194,20 +194,21 @@ If you're using server-side integration (see [Publisher Integration Guide, Serve
194194
2. Determine if the identity can be refreshed (that is, the refresh token hasn't expired):
195195

196196
```py
197-
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)
197+
if not identity or not identity.is_refreshable():
198+
# we must no longer use this identity (for example, remove this identity from the user's session)
198199
```
199200

200201
3. Determine if a refresh is needed:
201202

202203
```py
203-
if identity.is_due_for_refresh()):
204+
if identity.is_due_for_refresh():
204205
```
205206

206207
4. If needed, refresh the token and associated values:
207208

208-
```py
209-
token_refresh_response = client.refresh_token(identity)`
210-
```
209+
```py
210+
token_refresh_response = client.refresh_token(identity)
211+
```
211212

212213
5. Store `token_refresh_response.get_identity_json_string()` in the user's session.
213214

@@ -221,6 +222,161 @@ There are two operations that apply to Advertisers/Data Providers:
221222

222223
### Map DII to Raw UID2s
223224

225+
1. Create an IdentityMapV3Client as an instance variable:
226+
```py
227+
identity_map_v3_client = IdentityMapV3Client(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY)
228+
```
229+
230+
2. Create an IdentityMapV3Input object. You can use emails, phone numbers, or their hashed forms:
231+
```py
232+
input = IdentityMapV3Input.from_emails(["[email protected]", "[email protected]"])
233+
```
234+
Or combine multiple identity types:
235+
```py
236+
input = IdentityMapV3Input()
237+
.with_email("[email protected]")
238+
.with_phone("+12345678901")
239+
.with_hashed_email("pre_hashed_email")
240+
.with_hashed_phone("pre_hashed_phone")
241+
```
242+
243+
3. Call a function that takes the input and generates an IdentityMapV3Response object:
244+
```py
245+
identity_map_response = identity_map_v3_client.generate_identity_map(input)
246+
```
247+
248+
4. Retrieve the mapped and unmapped results:
249+
```py
250+
mapped_identities = identity_map_response.mapped_identities
251+
unmapped_identities = identity_map_response.unmapped_identities
252+
```
253+
254+
5. Process the results. For successfully mapped identities:
255+
```py
256+
mapped_identity = mapped_identities.get("[email protected]")
257+
if mapped_identity is not None:
258+
current_uid = mapped_identity.current_raw_uid # Current raw UID2
259+
previous_uid = mapped_identity.previous_raw_uid # Previous raw UID2 (Optional, only available for 90 days after rotation)
260+
refresh_from = mapped_identity.refresh_from # When to refresh this identity
261+
else:
262+
unmapped_identity = unmapped_identities.get("[email protected]")
263+
reason = unmapped_identity.reason # OPTOUT, INVALID_IDENTIFIER, or UNKNOWN
264+
```
265+
266+
>**Note:** The SDK automatically handles email normalization and hashing, ensuring that raw email addresses and phone numbers do not leave your server.
267+
### Usage Example
268+
269+
```py
270+
client = IdentityMapV3Client(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY)
271+
272+
# Example 1: Single identity type
273+
email_input = IdentityMapV3Input.from_emails(["[email protected]", "[email protected]"])
274+
email_response = client.generate_identity_map(email_input)
275+
276+
# Process email results
277+
for email, identity in email_response.mapped_identities.items():
278+
print("Email: " + email)
279+
print("Current UID: " + identity.current_raw_uid)
280+
print("Previous UID: " + identity.previous_raw_uid)
281+
print("Refresh from: " + str(identity.refresh_from))
282+
283+
for email, identity in email_response.unmapped_identities.items():
284+
print("Unmapped email: " + email + " - Reason: " + identity.reason)
285+
286+
# Example 2: Mixed identity types in single request
287+
mixed_input = IdentityMapV3Input()
288+
.with_email("[email protected]")
289+
.with_phone("+12345678901")
290+
.with_hashed_email("pre_hashed_email_value")
291+
.with_hashed_phone("pre_hashed_phone_value")
292+
293+
mixed_response = client.generate_identity_map(mixed_input)
294+
```
295+
296+
## Migration From Older Identity Map Version
297+
298+
### Migration Overview
299+
300+
Improvements provided by the new Identity Map version:
301+
- **Support for Multiple Identity Types**: Process emails and phones in a single request
302+
- **Simpler refresh management**: Re-map on reaching refresh timestamps instead of monitoring salt buckets
303+
- **Previous raw UID2 availability**: You can see previous UID2 for 90 days after rotation
304+
- **Improved performance**: The new API uses significantly less bandwidth for the same amount of DIIs
305+
306+
### Required Changes
307+
308+
1. **Update dependency version**:
309+
```bash
310+
pip install --upgrade uid2-client
311+
```
312+
313+
2. **Change client class**:
314+
```py
315+
# Before
316+
client = IdentityMapClient(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY)
317+
318+
# After
319+
client = IdentityMapV3Client(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY)
320+
```
321+
322+
3. **Update import statements**:
323+
```py
324+
from uid2_client import IdentityMapV3Client, IdentityMapV3Input, IdentityMapV3Response, UnmappedIdentityReason
325+
```
326+
327+
### Recommended Changes
328+
329+
1. **Update input construction**:
330+
```py
331+
# Before
332+
input = IdentityMapInput.from_emails(["[email protected]"])
333+
334+
# After - single identity type
335+
input = IdentityMapV3Input.from_emails(["[email protected]"])
336+
337+
# Alternatively - mix identity types (new capability)
338+
input = IdentityMapV3Input()
339+
.with_email("[email protected]")
340+
.with_phone("+12345678901")
341+
```
342+
343+
2. **Update response handling**:
344+
```py
345+
# Before
346+
response = client.generate_identity_map(input)
347+
mapped = response.mapped_identities.get("[email protected]")
348+
uid = mapped.get_raw_uid()
349+
350+
# After
351+
response = client.generate_identity_map(input)
352+
mapped = response.mapped_identities.get("[email protected]")
353+
current_uid = mapped.current_raw_uid
354+
previous_uid = mapped.previous_raw_uid
355+
refresh_from = mapped.refresh_from
356+
```
357+
358+
3. **Update error handling**:
359+
```py
360+
# Before
361+
unmapped = response.unmapped_identities.get("[email protected]")
362+
reason = unmapped.get_reason()
363+
364+
# After - structured error reasons
365+
unmapped = response.unmapped_identities.get("[email protected]")
366+
reason = unmapped.reason # Enum - OPTOUT, INVALID_IDENTIFIER, UNKNOWN
367+
368+
# Alternatively you can get reason as a string, values match the old ones
369+
raw_reason = unmapped.raw_reason
370+
```
371+
372+
## Previous Version (V2 Identity Map)
373+
374+
:::note
375+
The V2 Identity Map SDK is an older version maintained for backwards compatibility. Migrate to the current SDK for improved performance, multi-identity type support, and better UID rotation management.
376+
New integrations should not use this version.
377+
See [Migration From Older Identity Map Version](#migration-from-older-identity-map-version) for instructions.
378+
:::
379+
224380
To map email addresses, phone numbers, or their respective hashes to their raw UID2s and salt bucket IDs, follow these steps.
225381

226382
1. Create an instance of `IdentityMapClient` as an instance variable.

0 commit comments

Comments
 (0)