How to use the analytics-utils.getCookie function in analytics-utils

To help you get started, we’ve selected a few analytics-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DavidWells / analytics / packages / analytics-plugin-original-source / src / index.js View on Github external
export function getOriginalSource(opts = {}) {
  const config = Object.assign({}, CONFIG, opts)
  const { referrer, originalSourceKey } = config
  // 1. try first source browser storage
  const originalSrc = storage.getItem(originalSourceKey, { storage: config.storage })
  if (originalSrc) {
    return parsePipeString(originalSrc)
  }
  // 2. then try __utmz cookie
  const utmzCookie = getCookie('__utmz')
  if (utmzCookie) {
    const parsedCookie = parsePipeString(utmzCookie)
    if (parsedCookie) {
      setOriginalSource(parsedCookie, config)
      return parsedCookie
    }
  }
  // 3. Then try referrer url and utm params
  const ref = (inBrowser) ? (referrer || document.referrer) : ''
  const refData = parseReferrer(ref)
  setOriginalSource(refData, config)
  return refData
}