All files referrer.js

72.73% Statements 8/11
83.33% Branches 5/6
50% Functions 2/4
72.73% Lines 8/11

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 373x 3x         3x                                   3x 35x           3x 6x   6x    
let spaReferrer = ''
let referrer = ''
 
/**
 * Useful wrapper around document and window objects
 */
export const utils = {
  /**
   * @returns {string} The referrer of the document
   */
  getDocumentReferrer: () => document.referrer,
  /**
   * @returns {string} The actual location with protocol, domain and pathname
   */
  getActualLocation: () => {
    const {origin, pathname} = window.location
    return `${origin}${pathname}`
  }
}
 
/**
 * Get the correct page referrer for SPA navigations
 * @returns {string} referrer
 */
export const getPageReferrer = ({isPageTrack = false} = {}) => {
  return isPageTrack ? referrer || utils.getDocumentReferrer() : spaReferrer
}
 
/**
 * Update page referrer for SPA navigations
 */
export const updatePageReferrer = () => {
  spaReferrer = getPageReferrer({isPageTrack: true})
  // mutate actualReferrer with what will be the new referrer
  referrer = utils.getActualLocation()
}