function parseReferrer(referrer = '', currentUrl) {
  const { search, hash, hostname } = parseUrl(currentUrl)
  const currentDomain = getDomain(hostname)
  const refData = parseUrl(referrer)
  const refDomain = getDomain(refData.hostname)
  const params = decode(search)
  const isInternal = currentDomain === refDomain
  const isSubDomain = isInternal && (hostname !== refData.hostname)
  const external = isExternal(referrer, currentUrl)
  const isExternalLink = external && !isSubDomain
  /*
  // const local = isLocalHost(referrer)
  console.log('isExternal', external)
  console.log('refData', refData)
  console.log('params', params)
  /** */
  let result = {
    type: (!referrer) ? DIRECT : (isExternalLink) ? INBOUND : INTERNAL,
    date: new Date().toISOString(),
    entry: {
      url: getUrl(currentUrl),
      search,
      hash
    },
    referrer: {
      url: trimTrailingSlash(referrer),
      hostname: refData.hostname,
      domain: refDomain,
      isExternal: isExternalLink,
      isInternal,
      isInternalSubDomain: isSubDomain,
    },
  }

  const { ref, utm_medium, utm_source } = params

  /* UTM parameters */
  if (utm_medium || utm_source) {
    const campaign = checkGA(params)
    // console.log('campaign', campaign)
    result = {
      ...result,
      type: CAMPAIGN,
      data: campaign,
    }
  }

  /* Affiliate Link */
  if (ref) {
    result = {
      ...result,
      type: AFFILIATE,
      data: { 
        id: ref 
      }
    }
  }

  if (!refDomain) {
    return result
  }

  /* Check search engines */
  const name = (refDomain.indexOf(googleKey) > -1) ? googleKey : refDomain
  const engineKey = searchEngines[name]
  if (engineKey) {
    const term = getSearch(referrer, engineKey)
    return {
      ...result,
      type: SEARCH,
      data: {
        term: term || NA,
        name: trimTld(name),
      }
    }
  }

  /* Check socials */
  const isSocial = socials.find((urls) => urls.some((url) => refDomain === url))
  // console.log('isSocial', isSocial)
  if (isSocial) {
    if (result.type !== AFFILIATE) {
      result.type = SOCIAL
    }
    result.data = {
      ...result.data,
      site: isSocial[0],
    }
  }
  return result
}
@param {string} [referrer] 
@param {string} [currentUrl] 
@returns {ReferralData}