All files index.js

66.04% Statements 35/53
51.35% Branches 19/37
53.33% Functions 8/15
68% Lines 34/50

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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100      1x           8x   1x                   4x   4x   4x       4x 1x 1x 1x 1x   1x 1x               1x 1x   1x 1x 1x 1x 1x 1x       1x     1x 1x   1x     1x     1x           1x           1x       1x   1x   1x       4x       1x      
import { Component } from 'react';
import PropTypes from 'prop-types';
 
const canUseDOM = !!(
  typeof window !== 'undefined' &&
  window.document &&
  window.document.createElement
);
 
export const getWindowFullStory = () => window[window['_fs_namespace']];
 
export const FullStoryAPI = (fn, ...args) => {
  if (canUseDOM && getWindowFullStory()) {
    getWindowFullStory().apply(fn, args);
  } else {
    console.warn('FullStory not initialized yet');
  }
};
 
export default class FullStory extends Component {
  constructor(props) {
    super(props);
 
    const { org, debug, host, namespace } = props;
 
    Iif (!org || !canUseDOM) {
      return;
    }
 
    if (!getWindowFullStory()) {
      window['_fs_debug'] = debug || false;
      window['_fs_host'] = host || 'fullstory.com';
      window['_fs_org'] = org;
      window['_fs_namespace'] = namespace || 'FS';
 
      (function(w, d, ns, t, l, o, g, y) {
        Iif (ns in w) {
          if (w.console && w.console.log) {
            w.console.log(
              'FullStory namespace conflict. Please set window["_fs_namespace"]'
            );
          }
          return;
        }
        g = w[ns] = function(a, b) {
          g.q ? g.q.push([a, b]) : g._api(a, b);
        };
        g.q = [];
        o = d.createElement(t);
        o.async = 1;
        o.src = 'https://' + window['_fs_host'] + '/s/fs.js';
        d.head.appendChild(o);
        g.identify = function(i, v) {
          g(l, { uid: i });
          if (v) g(l, v);
        };
        g.setUserVars = function(v) {
          g(l, v);
        };
        g.shutdown = function() {
          g('rec', !1);
        };
        g.restart = function() {
          g('rec', !0);
        };
        g.consent = function(a) {
          g('consent', !arguments.length || a);
        };
        g.identifyAccount = function(i, v) {
          o = 'account';
          v = v || {};
          v.acctId = i;
          g(o, v);
        };
        g.clearUserCookie = function() {};
      })(window, document, window['_fs_namespace'], 'script', 'user');
    }
  }
 
  shouldComponentUpdate() {
    return false;
  }
 
  componentWillUnmount() {
    Iif (!canUseDOM || !getWindowFullStory()) return false;
 
    getWindowFullStory().shutdown();
 
    delete getWindowFullStory();
  }
 
  render() {
    return false;
  }
}
 
FullStory.propTypes = {
  org: PropTypes.string.isRequired
};