diff --git a/modules/userId/index.js b/modules/userId/index.js index 3253be42a76..64709d4aad6 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -130,6 +130,7 @@ */ import find from 'core-js-pure/features/array/find.js'; +import findIndex from 'core-js-pure/features/array/find-index.js'; import { config } from '../../src/config.js'; import events from '../../src/events.js'; import * as utils from '../../src/utils.js'; @@ -820,6 +821,16 @@ export function init(config) { auctionDelay = utils.isNumber(userSync.auctionDelay) ? userSync.auctionDelay : NO_AUCTION_DELAY; updateSubmodules(); } + // userSync.ppid should be one of the 'source' values in getUserIdsAsEids() eg pubcid.org or id5-sync.com + if (userSync && userSync.userIds && userSync.ppid && findIndex(getUserIdsAsEids(), x => x.source === userSync.ppid) >= 0 && typeof getUserIdsAsEids().find(x => x.source === userSync.ppid).uids[0].id === 'string') { + window.googletag = window.googletag || { cmd: [] }; + const ppid = getUserIdsAsEids().find(x => x.source === userSync.ppid).uids[0].id.replace(/[\W_]/g, ''); + if (ppid.length >= 32 && ppid.length <= 150) { + window.googletag.cmd.push(function() { + window.googletag.pubads().setPublisherProvidedId(ppid) + }); + } + } }); // exposing getUserIds function in global-name-space so that userIds stored in Prebid can be used by external codes.