All files adobeRepository.js

91.43% Statements 32/35
82.35% Branches 14/17
100% Functions 10/10
90.63% Lines 29/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61    2x 2x 2x 2x 2x   2x             2x 1122x   2x 1121x   2x 1x 1x 1x 1x     2x 39x   15x   1135x   1121x 1121x 1121x   1120x   15x       2x 2x 2x           2x 41x            
import {getConfig} from './getConfig.js'
 
const ADOBE_ORG_ID = '05FF6243578784B37F000101@AdobeOrg'
const DEFAULT_DEMDEX_VERSION = '3.3.0'
const TRACKING_SERVER = 'schibstedspain.d3.sc.omtrdc.net'
const TIMES_TO_RETRY = 80
const TIME_BETWEEN_RETRIES = 15
 
const SERVERS = {
  trackingServer: TRACKING_SERVER,
  trackingServerSecure: TRACKING_SERVER
}
 
let mcvid
 
const getDemdex = () =>
  window.Visitor && window.Visitor.getInstance(ADOBE_ORG_ID, SERVERS)
 
const getMarketingCloudVisitorID = demdex =>
  demdex && demdex.getMarketingCloudVisitorID()
 
const getAdobeVisitorData = () => {
  const demdex = getDemdex() || {}
  const {version = DEFAULT_DEMDEX_VERSION} = demdex
  const {trackingServer} = SERVERS
  return Promise.resolve({trackingServer, version})
}
 
const deprecatedGetAdobeMCVisitorID = () => {
  if (mcvid) return Promise.resolve(mcvid)
 
  return new Promise(resolve => {
    function retry(retries) {
      if (retries === 0) return resolve('')
 
      const demdex = getDemdex()
      mcvid = getMarketingCloudVisitorID(demdex)
      return mcvid
        ? resolve(mcvid)
        : window.setTimeout(() => retry(--retries), TIME_BETWEEN_RETRIES)
    }
    retry(TIMES_TO_RETRY)
  })
}
 
const importVisitorApiAndGetAdobeMCVisitorID = () =>
  import('./adobeVisitorApi.js').then(() => {
    Eif (mcvid) return Promise.resolve(mcvid)
    const demdex = getDemdex()
    mcvid = getMarketingCloudVisitorID(demdex)
    return mcvid
  })
 
const getAdobeMCVisitorID = () => {
  return getConfig('importAdobeVisitorId') === true
    ? importVisitorApiAndGetAdobeMCVisitorID()
    : deprecatedGetAdobeMCVisitorID()
}
 
export {getAdobeVisitorData, getAdobeMCVisitorID}