Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ When creating an instance of `OptableSDK`, you can pass an `InitConfig` object t
- **`readOnly` (boolean, default: `false`)**
When set to `true`, puts the SDK in a read-only mode, preventing any data modifications while still allowing API queries.

- **`optableCacheTargeting` (string, defaults: `optable-cache:targeting`)**
Local storage cache key used to store latest targeting response.
- **`optableCacheTargeting` (string, defaults: `OPTABLE_RESOLVED`)**
Local storage cache key used to store latest targeting response. The default is the key the Prebid RTD module (`buildRTD`), `pubProvidedId` and `identifyAndTokenize` use, so they share one cache; if you change it, pass the same key to those too.

- **`ois` (boolean, default: `false`)**
When set to `true`, participates in the [Optable Identity System](#optable-identity-system-ois): the SDK stores the derived OIS ID the DCN returns on the `X-Optable-OID` response header and replays it on subsequent requests, so the DCN recognizes the browser instead of deriving a new identity each visit. Requires a DCN node with OIS ID derivation enabled and device access consent, so it is a no-op otherwise. The `OPTABLE_OID` cookie identity is separate and needs no configuration.
Expand Down
2 changes: 1 addition & 1 deletion lib/addons/uid2-refresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ await refreshStaleUid2sFromCache(sdk.dcn);

Reads every stored copy of the targeting cache and refreshes each distinct UID2 past its `refresh_from` through `refreshStaleUid2s`. Copies can hold different identities, so refreshes are keyed by refresh token: two copies holding the same token make one request, and two holding different ones are refreshed and written back separately. Use this on a page that served targeting from cache: only `mergeCache` produces a `staleUid2s` list, and it runs when a response is merged, so a page that never calls the edge has nothing to pass to `refreshStaleUid2s`. That is also the page where the cached token has had time to age.

Both copies are checked, the private `OPTABLE_TARGETING_<key>` one and the public `optableCacheTargeting` one, because they can differ: `identifyAndTokenize` writes its merged cache only to its own `cacheKey` (`OPTABLE_RESOLVED` by default), which is also where prebid RTD and `pubProvidedId` read from. For a tokenize-resolved UID2 to be refreshable, that key and `optableCacheTargeting` have to name the same thing; the config default (`optable-cache:targeting`) does not. `applyUid2Refresh` then writes each outcome back to the copies holding that refresh token.
Both copies are checked, the private `OPTABLE_TARGETING_<key>` one and the public `optableCacheTargeting` one, because they can differ: `identifyAndTokenize` writes its merged cache only to its own `cacheKey` (`OPTABLE_RESOLVED` by default), which is also where prebid RTD and `pubProvidedId` read from. For a tokenize-resolved UID2 to be refreshable, that key and `optableCacheTargeting` have to name the same thing; both default to `OPTABLE_RESOLVED`. `applyUid2Refresh` then writes each outcome back to the copies holding that refresh token.

A missing cache, an unparseable copy, a cache without refresh material, and a token not yet due are all no-ops that make no request.
4 changes: 2 additions & 2 deletions lib/addons/uid2-refresh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ describe("refreshStaleUid2sFromCache", () => {
expect(calls).toBe(0);
});

it("does not read the tokenize cache under the default optableCacheTargeting", async () => {
it("reads the tokenize cache under the default optableCacheTargeting", async () => {
localStorage.setItem(
"OPTABLE_RESOLVED",
JSON.stringify({
Expand All @@ -501,7 +501,7 @@ describe("refreshStaleUid2sFromCache", () => {

await refreshStaleUid2sFromCache({ ...config, optableCacheTargeting: DCN_DEFAULTS.optableCacheTargeting });

expect(calls).toBe(0);
expect(calls).toBe(1);
});

it("applies each refresh only to the copy holding that token", async () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/addons/uid2-refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async function refreshStaleUid2s(config: ResolvedConfig, stale: StaleUid2[]): Pr
*/
async function refreshStaleUid2sFromCache(config: ResolvedConfig): Promise<void> {
// identifyAndTokenize writes only to its own cacheKey, so its copy is read
// here only when optableCacheTargeting names that same key.
// here only when optableCacheTargeting names that same key (true by default).
const stale = new Map<string, Uid2RefData>();
try {
for (const cached of new LocalStorage(config).getTargetingCopies() as ResolvedCache[]) {
Expand Down
2 changes: 1 addition & 1 deletion lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("getConfig", () => {
experiments: [],
sessionID: "",
skipEnrichment: undefined,
optableCacheTargeting: "optable-cache:targeting",
optableCacheTargeting: "OPTABLE_RESOLVED",
});
});

Expand Down
5 changes: 3 additions & 2 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type InitConfig = {
skipEnrichment?: boolean;
// Targeting call on load
initTargeting?: boolean;
// (Defaults to 'optable_cache_targeting') Cache Key used to store 'targeting' response
// (Defaults to 'OPTABLE_RESOLVED', the key prebid RTD and pubProvidedId read) Cache Key used to store 'targeting' response
optableCacheTargeting?: string;
// AB test configuration to define testing configurations
abTests?: ABTestConfig[];
Expand Down Expand Up @@ -120,6 +120,7 @@ const DCN_DEFAULTS = {
initPassport: true,
readOnly: false,
experiments: [],
optableCacheTargeting: "OPTABLE_RESOLVED",
consent: {
reg: null,
deviceAccess: true,
Expand All @@ -133,7 +134,7 @@ function getConfig(init: InitConfig): ResolvedConfig {
const config: ResolvedConfig = {
host: init.host,
site: init.site,
optableCacheTargeting: init.optableCacheTargeting ?? "optable-cache:targeting",
optableCacheTargeting: init.optableCacheTargeting ?? DCN_DEFAULTS.optableCacheTargeting,
cookies: init.cookies ?? DCN_DEFAULTS.cookies,
initPassport: init.initPassport ?? DCN_DEFAULTS.initPassport,
consent: DCN_DEFAULTS.consent,
Expand Down
4 changes: 2 additions & 2 deletions lib/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe("behavior testing of", () => {
experiments: [],
sessionID: "session",
skipEnrichment: false,
optableCacheTargeting: "optable-cache:targeting",
optableCacheTargeting: "OPTABLE_RESOLVED",
});
await sdk["init"];
expect(localStorage.setItem).toBeCalledTimes(0);
Expand Down Expand Up @@ -292,7 +292,7 @@ describe("behavior testing of", () => {
experiments: [],
sessionID: "session",
skipEnrichment: false,
optableCacheTargeting: "optable-cache:targeting",
optableCacheTargeting: "OPTABLE_RESOLVED",
});
await sdk["init"];
expect(window.localStorage.setItem).toHaveBeenLastCalledWith(
Expand Down