From 86e6ef552ea5c207aa8b5573e86283dbe841b517 Mon Sep 17 00:00:00 2001
From: Brett Bloxom <38990705+BrettBlox@users.noreply.github.com>
Date: Mon, 10 Apr 2023 08:19:47 -0600
Subject: [PATCH] Concert Bid Adapter: Enable support for additional userId's
 (#9780)

* collect EIDs for bid request

* add ad slot positioning to payload

* RPO-2012: Update local storage name-spacing for c_uid (#8)

* Updates c_uid namespacing to be more specific for concert

* fixes unit tests

* remove console.log

* RPO-2012: Add check for shared id (#9)

* Adds check for sharedId

* Updates cookie name

* remove trailing comma

* [RPO-3152] Enable Support for GPP Consent (#12)

* Adds gpp consent integration to concert bid adapter

* Update tests to check for gpp consent string param

* removes user sync endpoint and tests

* updates comment

* cleans up consentAllowsPpid function

* comment fix

* rename variables for clarity

* fixes conditional logic for consent allows function (#13)

* [RPO-3262] Update getUid function to check for pubcid and sharedid (#14)

* Update getUid function to check for pubcid and sharedid

* updates adapter version

---------

Co-authored-by: antoin <antoin.campbell@voxmedia.com>
Co-authored-by: Antoin <antoinfive@gmail.com>
---
 modules/concertBidAdapter.js                | 21 ++++++++++++++-------
 test/spec/modules/concertBidAdapter_spec.js | 11 +++--------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/modules/concertBidAdapter.js b/modules/concertBidAdapter.js
index 176729dd607..a25d9086446 100644
--- a/modules/concertBidAdapter.js
+++ b/modules/concertBidAdapter.js
@@ -42,9 +42,9 @@ export const spec = {
         pageUrl: bidderRequest.refererInfo.page,
         screen: [window.screen.width, window.screen.height].join('x'),
         debug: debugTurnedOn(),
-        uid: getUid(bidderRequest),
+        uid: getUid(bidderRequest, validBidRequests),
         optedOut: hasOptedOutOfPersonalization(),
-        adapterVersion: '1.1.1',
+        adapterVersion: '1.2.0',
         uspConsent: bidderRequest.uspConsent,
         gdprConsent: bidderRequest.gdprConsent,
         gppConsent: bidderRequest.gppConsent,
@@ -158,16 +158,23 @@ export const storage = getStorageManager({bidderCode: BIDDER_CODE});
 /**
  * Check or generate a UID for the current user.
  */
-function getUid(bidderRequest) {
+function getUid(bidderRequest, validBidRequests) {
   if (hasOptedOutOfPersonalization() || !consentAllowsPpid(bidderRequest)) {
     return false;
   }
 
-  const sharedId = deepAccess(bidderRequest, 'userId._sharedid.id');
+  /**
+   * check for shareId or pubCommonId before generating a new one
+   * sharedId: @see https://docs.prebid.org/dev-docs/modules/userId.html
+   * pubCid (no longer supported): @see https://docs.prebid.org/dev-docs/modules/pubCommonId.html#adapter-integration
+   */
+  const sharedId =
+    deepAccess(validBidRequests[0], 'userId.sharedid.id') ||
+    deepAccess(validBidRequests[0], 'userId.pubcid')
+  const pubCid = deepAccess(validBidRequests[0], 'crumbs.pubcid');
 
-  if (sharedId) {
-    return sharedId;
-  }
+  if (sharedId) return sharedId;
+  if (pubCid) return pubCid;
 
   const LEGACY_CONCERT_UID_KEY = 'c_uid';
   const CONCERT_UID_KEY = 'vmconcert_uid';
diff --git a/test/spec/modules/concertBidAdapter_spec.js b/test/spec/modules/concertBidAdapter_spec.js
index d5e7140a9f7..f5c807b4703 100644
--- a/test/spec/modules/concertBidAdapter_spec.js
+++ b/test/spec/modules/concertBidAdapter_spec.js
@@ -149,15 +149,10 @@ describe('ConcertAdapter', function () {
 
     it('should use sharedid if it exists', function() {
       storage.removeDataFromLocalStorage('c_nap');
-      const request = spec.buildRequests(bidRequests, {
-        ...bidRequest,
-        userId: {
-          _sharedid: {
-            id: '123abc'
-          }
-        }
-      });
+      const bidRequestsWithSharedId = [{ ...bidRequests[0], userId: { sharedid: { id: '123abc' } } }]
+      const request = spec.buildRequests(bidRequestsWithSharedId, bidRequest);
       const payload = JSON.parse(request.data);
+
       expect(payload.meta.uid).to.equal('123abc');
     })