Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

JavaScript SDK Integrations

This folder contains sample integrations using the UID2/EUID JavaScript SDK directly, without Prebid.js or Google Secure Signals.

How It Works

The JavaScript SDK provides a straightforward way to manage UID2/EUID tokens:

  1. Token Generation — Either client-side (CSTG) or via server-provided token
  2. Token Storage — Stored in localStorage or first-party cookie
  3. Token Refresh — SDK automatically refreshes tokens before expiration
  4. Callbacks — SDK notifies your code when token state changes

Key SDK Methods

// Initialize with server-generated token (client-server)
__uid2.init({ identity: tokenFromServer });

// OR generate token client-side (CSTG)
__uid2.setIdentityFromEmail(email, {
  subscriptionId: 'your-sub-id',
  serverPublicKey: 'your-public-key'
});

// Get current advertising token
__uid2.getAdvertisingToken();

// Check if login is needed
__uid2.isLoginRequired();

// Clear identity (logout)
__uid2.disconnect();

Integration Types

Type Token Generation Use Case
Client-Side SDK uses CSTG Simple setup, all client-side
Client-Server Server generates, SDK refreshes More control, server-side validation

Available Examples

Folder Description Port
client-side/ Client-side token generation using CSTG 3031
client-server/ Server generates initial token, client SDK manages refresh 3032
react-client-side/ React implementation of client-side token generation 3034

Documentation

Environment Variables

All integrations in this folder require common variables plus integration-specific ones. See the individual README for each integration for the complete list of required variables.

Common Variables

Variable Description
IDENTITY_NAME Display name for the UI (UID2 or EUID)
DOCS_BASE_URL Used for UI links to public documentation (https://unifiedid.com/docs or https://euid.eu/docs)

Client-Side Specific

Variable Description
UID_CLIENT_BASE_URL API base URL for client-side calls
UID_CSTG_SUBSCRIPTION_ID Your subscription ID for CSTG
UID_CSTG_SERVER_PUBLIC_KEY Your server public key for CSTG
UID_JS_SDK_URL URL to the JavaScript SDK
UID_JS_SDK_NAME Global variable name (__uid2 or __euid)

React Note: For the React example (react-client-side/), all client-side variables must be prefixed with REACT_APP_ (e.g., REACT_APP_UID_CLIENT_BASE_URL). See the React README for the complete list.

Client-Server Specific

Variable Description
UID_SERVER_BASE_URL API base URL for server-side calls
UID_API_KEY Your API key for server-side token generation
UID_CLIENT_SECRET Your client secret for server-side token generation

Debugging Tips

Check Environment Variables

docker compose config

View Container Logs

# Replace SERVICE_NAME with the specific service
docker compose logs javascript-sdk-client-side
docker compose logs javascript-sdk-client-server
docker compose logs javascript-sdk-react-client-side

Rebuild After Changes

docker compose up -d --build SERVICE_NAME

Verify Token State

Open Developer Tools (F12) and check:

  • Console: Look for SDK initialization messages and errors
  • Application > Local Storage: Check for __uid2_advertising_token or __euid_advertising_token
  • Network: Monitor API calls to the operator endpoint

Common Issues

Issue Possible Cause Solution
"Invalid subscription ID" Wrong credentials for the environment Verify credentials match your operator URL
Token not persisting localStorage blocked Check browser privacy settings
SDK not loading Wrong SDK URL Verify UID_JS_SDK_URL is accessible
"Unexpected origin" Domain not allowed Use local operator or verify domain is registered

Troubleshooting (Client-Server)

"Request failed with status code 401"

  • Verify your UID_API_KEY and UID_CLIENT_SECRET are correct
  • Ensure your API key has the GENERATOR role
  • Check that credentials match your environment (local vs. integration)
  • For EUID, ensure your operator's identity_scope is set to "euid" and you're using EUID-C- keys

"Request failed with status code 500"

For local operator:

  • Verify the operator is running at localhost:8080
  • Check enable_v2_encryption: true is set in the operator's config
  • Review operator logs for errors
  • Ensure identity_scope matches your credentials (e.g., "uid2" or "euid")

For Docker:

  • Ensure UID_SERVER_BASE_URL uses host.docker.internal:8080 not localhost:8080