All files adobeRepository.js

84.62% Statements 22/26
76.92% Branches 10/13
85.71% Functions 6/7
84% Lines 21/25

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 531x 1x 1x 1x 1x   1x             1x 1121x   1x 1121x   1x                     1x 26x   15x   1135x 14x   1121x 1121x 1121x     1120x       15x          
const ADOBE_ORG_ID = '05FF6243578784B37F000101@AdobeOrg'
const TRACKING_SERVER = 'schibstedspain.d3.sc.omtrdc.net'
const DEFAULT_DEMDEX_VERSION = '3.3.0'
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 getAdobeMCVisitorID = () => {
  if (mcvid) return Promise.resolve(mcvid)
 
  return new Promise(function(resolve) {
    function retry(retries) {
      if (retries === 0) {
        return resolve('')
      } else {
        const demdex = getDemdex()
        mcvid = getMarketingCloudVisitorID(demdex)
        return mcvid
          ? resolve(mcvid)
          : window.setTimeout(function() {
              retry(--retries)
            }, TIME_BETWEEN_RETRIES)
      }
    }
    retry(TIMES_TO_RETRY)
  })
}
 
export {getAdobeVisitorData, getAdobeMCVisitorID}