All files / src index.js

45.76% Statements 27/59
48.65% Branches 18/37
35.29% Functions 6/17
46.43% Lines 26/56

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 101 102 103 104 105 106 107 108      1x           7x   1x                   4x   4x   4x       4x 1x 1x 1x 1x   1x 1x               1x     1x 1x 1x 1x 1x 1x 1x                                                                     1x       1x   1x           3x       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()[fn].apply(null, 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(m, n, e, t, l, o, g, y) {
        Iif (e in m) {
          if (m.console && m.console.log) {
            m.console.log(
              'FullStory namespace conflict. Please set window["_fs_namespace"].'
            );
          }
          return;
        }
        g = m[e] = function(a, b, s) {
          g.q ? g.q.push([a, b, s]) : g._api(a, b, s);
        };
        g.q = [];
        o = n.createElement(t);
        o.async = 1;
        o.crossOrigin = 'anonymous';
        o.src = 'https://' + window['_fs_host'] + '/s/fs.js';
        y = n.getElementsByTagName(t)[0];
        y.parentNode.insertBefore(o, y);
        g.identify = function(i, v, s) {
          g(l, { uid: i }, s);
          if (v) g(l, v, s);
        };
        g.setUserVars = function(v, s) {
          g(l, v, s);
        };
        g.event = function(i, v, s) {
          g('event', { n: i, p: v }, s);
        };
        g.shutdown = function() {
          g('rec', !1);
        };
        g.restart = function() {
          g('rec', !0);
        };
        g.log = function(a, b) {
          g('log', [a, b]);
        };
        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
};