Skip to main content

UID2 SDK for C++ Reference Guide

You can use the UID2 SDK for C++ on the server side to facilitate decrypting of UID2 tokens to access the raw UID2.

Overview

The functions outlined here define the information that you'll need to configure or can retrieve from the library. The parameters and property names defined below are pseudocode. Actual parameters and property names vary by language but will be similar to the information outlined here.

Functionality

This SDK simplifies integration with UID2 for any DSPs or UID2 sharers who are using C++ for their server-side coding. The following table shows the functions it supports.

Encrypt Raw UID2 to UID2 TokenDecrypt UID2 TokenGenerate UID2 Token from DIIRefresh UID2 Token
SupportedSupportedNot supportedNot supported

API Permissions

To use this SDK, you'll need to complete the UID2 account setup by following the steps described in the Account Setup page.

You'll be granted permission to use specific functions offered by the SDK, and given credentials for that access. Bear in mind that there might be functions in the SDK that you don't have permission to use. For example, publishers get a specific API permission to generate and refresh tokens, but the SDK might support other activities that require a different API permission.

For details, see API Permissions.

Version

The SDK requires C++ version 11.

GitHub Repository/Binary

This SDK is in the following open-source GitHub repository:

Release tags are available in the following GitHub location, but you must build your own binaries:

Initialization

The initialization function configures the parameters necessary for the SDK to authenticate with the UID2 service. It also allows you to configure retry intervals in the event of errors.

ParameterDescriptionRecommended Value
endpointThe endpoint for the UID2 service.N/A
authKeyThe authentication token that belongs to the client. For access to UID2, see Contact Info.N/A

Interface

The interface allows you to decrypt UID2 advertising tokens and return the corresponding raw UID2.

NOTE: When you use an SDK, you do not need to store or manage decryption keys.

If you're a DSP, for bidding, call the interface to decrypt a UID2 advertising token and return the UID2. For details on the bidding logic for handling user opt-outs, see DSP Integration Guide.

The following is the decrypt method in C++:

#include <uid2/uid2client.h>
using namespace uid2;

const auto client = UID2ClientFactory::Create(baseUrl, apiKey, secretKey);
client->Refresh(); //Note that Refresh() should be called once after create(), and then once per hour
const auto result = client->Decrypt(adToken);

Response Content

Available information returned through the SDK is outlined in the following table.

FunctionDescription
GetStatus()The decryption result status. For a list of possible values and definitions, see Response Statuses.
GetUid()The raw UID2 for the corresponding UID2 advertising token.
GetEstablished()The timestamp indicating when a user first established the UID2 with the publisher.

Response Statuses

ValueDescription
SuccessThe UID2 advertising token was decrypted successfully and a raw UID2 was returned.
NotAuthorizedForKeyThe requester does not have authorization to decrypt this UID2 advertising token.
NotInitializedThe client library is waiting to be initialized.
InvalidPayloadThe incoming UID2 advertising token is not a valid payload.
ExpiredTokenThe incoming UID2 advertising token has expired.
KeysNotSyncedThe client has failed to synchronize keys from the UID2 service.
VersionNotSupportedThe client library does not support the version of the encrypted token.

Usage for UID2 Sharers

A UID2 sharer is any participant that wants to share UID2s with another participant. Raw UID2s must be encrypted into UID2 tokens before sending them to another participant. For an example of usage, see com.uid2.client.test.IntegrationExamples (runSharingExample method).

IMPORTANT: The UID2 token generated during this process is for sharing only—you cannot use it in the bidstream. There is a different workflow for generating tokens for the bidstream: see Tokenized Sharing in the Bidstream.

The following instructions provide an example of how you can implement sharing using the UID2 SDK for C++, either as a sender or a receiver.

  1. Create an IUID2Client shared pointer:

    const auto client = UID2ClientFactory::Create(baseUrl, apiKey, secretKey);
  2. Refresh once at startup, and then periodically (recommended refresh interval is hourly):

    client->Refresh();
  3. Senders:

    1. Call the following:

      EncryptionResult encrypted = client->Encrypt(rawUid);
    2. If encryption succeeded, send the UID2 token to the receiver:

      if (encrypted.IsSuccess()) 
      {
      // send encrypted.GetEncryptedData() to receiver
      }
      else
      {
      // check encrypted.GetStatus() for the failure reason
      }
  4. Receivers:

    1. Call the following:

      DecryptionResult decrypted = client->Decrypt(uidToken);
    2. If decryption succeeded, use the raw UID2:

      if (decrypted.IsSuccess())
      {
      // use decrypted.GetUid()
      }
      else
      {
      // check decrypted.GetStatus() for the failure reason
      }

FAQs

For a list of frequently asked questions for DSPs, see FAQs for DSPs.