/modules/userId/eids.js

https://github.com/prebid/Prebid.js · JavaScript · 204 lines · 158 code · 20 blank · 26 comment · 19 complexity · d26304a9ac186139df80f0a3a77ca709 MD5 · raw file

  1. import * as utils from '../../src/utils.js';
  2. // Each user-id sub-module is expected to mention respective config here
  3. const USER_IDS_CONFIG = {
  4. // key-name : {config}
  5. // intentIqId
  6. 'intentIqId': {
  7. source: 'intentiq.com',
  8. atype: 1
  9. },
  10. // pubCommonId
  11. 'pubcid': {
  12. source: 'pubcid.org',
  13. atype: 1
  14. },
  15. // unifiedId
  16. 'tdid': {
  17. source: 'adserver.org',
  18. atype: 1,
  19. getUidExt: function() {
  20. return {
  21. rtiPartner: 'TDID'
  22. };
  23. }
  24. },
  25. // id5Id
  26. 'id5id': {
  27. getValue: function(data) {
  28. return data.uid
  29. },
  30. source: 'id5-sync.com',
  31. atype: 1,
  32. getEidExt: function(data) {
  33. if (data.ext) {
  34. return data.ext;
  35. }
  36. }
  37. },
  38. // parrableId
  39. 'parrableId': {
  40. source: 'parrable.com',
  41. atype: 1,
  42. getValue: function(parrableId) {
  43. if (parrableId.eid) {
  44. return parrableId.eid;
  45. }
  46. if (parrableId.ccpaOptout) {
  47. // If the EID was suppressed due to a non consenting ccpa optout then
  48. // we still wish to provide this as a reason to the adapters
  49. return '';
  50. }
  51. return null;
  52. },
  53. getUidExt: function(parrableId) {
  54. const extendedData = utils.pick(parrableId, [
  55. 'ibaOptout',
  56. 'ccpaOptout'
  57. ]);
  58. if (Object.keys(extendedData).length) {
  59. return extendedData;
  60. }
  61. }
  62. },
  63. // identityLink
  64. 'idl_env': {
  65. source: 'liveramp.com',
  66. atype: 1
  67. },
  68. // liveIntentId
  69. 'lipb': {
  70. getValue: function(data) {
  71. return data.lipbid;
  72. },
  73. source: 'liveintent.com',
  74. atype: 1,
  75. getEidExt: function(data) {
  76. if (Array.isArray(data.segments) && data.segments.length) {
  77. return {
  78. segments: data.segments
  79. };
  80. }
  81. }
  82. },
  83. // britepoolId
  84. 'britepoolid': {
  85. source: 'britepool.com',
  86. atype: 1
  87. },
  88. // lotamePanoramaId
  89. lotamePanoramaId: {
  90. source: 'crwdcntrl.net',
  91. atype: 1,
  92. },
  93. // criteo
  94. 'criteoId': {
  95. source: 'criteo.com',
  96. atype: 1
  97. },
  98. // merkleId
  99. 'merkleId': {
  100. source: 'merkleinc.com',
  101. atype: 1
  102. },
  103. // NetId
  104. 'netId': {
  105. source: 'netid.de',
  106. atype: 1
  107. },
  108. // sharedid
  109. 'sharedid': {
  110. source: 'sharedid.org',
  111. atype: 1,
  112. getValue: function(data) {
  113. return data.id;
  114. },
  115. getUidExt: function(data) {
  116. return (data && data.third) ? {
  117. third: data.third
  118. } : undefined;
  119. }
  120. },
  121. // zeotapIdPlus
  122. 'IDP': {
  123. source: 'zeotap.com',
  124. atype: 1
  125. },
  126. // haloId
  127. 'haloId': {
  128. source: 'audigent.com',
  129. atype: 1
  130. },
  131. // quantcastId
  132. 'quantcastId': {
  133. source: 'quantcast.com',
  134. atype: 1
  135. }
  136. };
  137. // this function will create an eid object for the given UserId sub-module
  138. function createEidObject(userIdData, subModuleKey) {
  139. const conf = USER_IDS_CONFIG[subModuleKey];
  140. if (conf && userIdData) {
  141. let eid = {};
  142. eid.source = conf['source'];
  143. const value = utils.isFn(conf['getValue']) ? conf['getValue'](userIdData) : userIdData;
  144. if (utils.isStr(value)) {
  145. const uid = { id: value, atype: conf['atype'] };
  146. // getUidExt
  147. if (utils.isFn(conf['getUidExt'])) {
  148. const uidExt = conf['getUidExt'](userIdData);
  149. if (uidExt) {
  150. uid.ext = uidExt;
  151. }
  152. }
  153. eid.uids = [uid];
  154. // getEidExt
  155. if (utils.isFn(conf['getEidExt'])) {
  156. const eidExt = conf['getEidExt'](userIdData);
  157. if (eidExt) {
  158. eid.ext = eidExt;
  159. }
  160. }
  161. return eid;
  162. }
  163. }
  164. return null;
  165. }
  166. // this function will generate eids array for all available IDs in bidRequest.userId
  167. // this function will be called by userId module
  168. // if any adapter does not want any particular userId to be passed then adapter can use Array.filter(e => e.source != 'tdid')
  169. export function createEidsArray(bidRequestUserId) {
  170. let eids = [];
  171. for (const subModuleKey in bidRequestUserId) {
  172. if (bidRequestUserId.hasOwnProperty(subModuleKey)) {
  173. if (subModuleKey === 'pubProvidedId') {
  174. eids = eids.concat(bidRequestUserId['pubProvidedId']);
  175. } else {
  176. const eid = createEidObject(bidRequestUserId[subModuleKey], subModuleKey);
  177. if (eid) {
  178. eids.push(eid);
  179. }
  180. }
  181. }
  182. }
  183. return eids;
  184. }