@fullstory/browser 1.7.1 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { FSApi } from '@fullstory/snippet';
1
2
  /**
2
3
  * FullStory Client SDK snippet options.
3
4
  *
@@ -11,55 +12,42 @@
11
12
  * - recordOnlyThisIFrame: FullStory can record the iFrame as its own unique session. Defaults to `false`. Additional conditions apply and can be found [here](https://help.fullstory.com/hc/en-us/articles/360020622514-Can-FullStory-capture-content-that-is-presented-in-iframes-#h_01F1G33B40Q2TPQA8MA7SF8Y5P).
12
13
  * - devMode: In dev mode FullStory won't record sessions. Any calls to SDK methods will `console.warn` that FullStory is in `devMode`. Defaults to `false`.
13
14
  */
14
- interface SnippetOptions {
15
- orgId: string;
16
- namespace?: string;
17
- debug?: boolean;
18
- host?: string;
19
- script?: string;
20
- cookieDomain?: string;
21
- recordCrossDomainIFrames?: boolean;
22
- recordOnlyThisIFrame?: boolean;
23
- devMode?: boolean;
15
+ export interface SnippetOptions {
16
+ orgId: string;
17
+ namespace?: string;
18
+ debug?: boolean;
19
+ host?: string;
20
+ script?: string;
21
+ cookieDomain?: string;
22
+ recordCrossDomainIFrames?: boolean;
23
+ recordOnlyThisIFrame?: boolean;
24
+ devMode?: boolean;
24
25
  }
25
-
26
- interface UserVars {
27
- displayName?: string;
28
- email?: string;
29
- [key: string]: any;
30
- }
31
-
32
- type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
33
-
34
- type VarScope = 'page';
35
-
36
26
  /**
37
27
  * A callback that will be invoked when FullStory has begun a session.
38
28
  *
39
29
  * `sessionUrl` contains the URL to the current session.
30
+ * `settings` contains the org settings for the current session.
40
31
  */
41
- type ReadyCallback = (data: { sessionUrl: string }) => void;
42
-
43
- // API functions that are available as soon as the snippet has executed.
44
- export function anonymize(): void;
45
- export function consent(userConsents?: boolean): void;
46
- export function event(eventName: string, eventProperties: { [key: string]: any }): void;
47
- export function identify(uid: string, customVars?: UserVars): void;
48
- /**
49
- * Initialize FullStory.
50
- *
51
- * @param options Options to pass to the snippet.
52
- * @param readyCallback If provided, a callback that will be invoked when the FullStory session has begun.
53
- */
54
- export function init(options: SnippetOptions, readyCallback?: ReadyCallback): void;
55
- export function isInitialized(): boolean;
56
- export function log(level: LogLevel, msg: string): void;
57
- export function log(msg: string): void;
58
- export function restart(): void;
59
- export function setUserVars(customVars: UserVars): void;
60
- export function shutdown(): void;
61
- export function setVars(varScope: VarScope, properties?: { [key: string]: any }): void;
62
-
63
- // API functions that are available after /rec/page returns.
64
- // FullStory bootstrapping details: https://help.fullstory.com/hc/en-us/articles/360032975773
65
- export function getCurrentSessionURL(now?: boolean): string | null;
32
+ type ReadyCallback = (data: {
33
+ sessionUrl: string;
34
+ settings: Readonly<object>;
35
+ }) => void;
36
+ declare global {
37
+ interface Window {
38
+ _fs_cookie_domain?: string;
39
+ _fs_debug?: boolean;
40
+ _fs_dev_mode?: boolean;
41
+ _fs_host?: string;
42
+ _fs_initialized?: boolean;
43
+ _fs_is_outer_script?: boolean;
44
+ _fs_namespace?: string;
45
+ _fs_org?: string;
46
+ _fs_run_in_iframe?: boolean;
47
+ _fs_script?: string;
48
+ }
49
+ }
50
+ export declare const init: (inputOptions: SnippetOptions, readyCallback?: ReadyCallback) => void;
51
+ export declare const isInitialized: () => boolean;
52
+ export declare const FullStory: FSApi;
53
+ export {};
package/dist/index.esm.js CHANGED
@@ -1,163 +1,154 @@
1
1
  import { initFS } from '@fullstory/snippet';
2
2
 
3
- function ownKeys(object, enumerableOnly) {
4
- var keys = Object.keys(object);
5
-
6
- if (Object.getOwnPropertySymbols) {
7
- var symbols = Object.getOwnPropertySymbols(object);
8
- enumerableOnly && (symbols = symbols.filter(function (sym) {
9
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
10
- })), keys.push.apply(keys, symbols);
11
- }
12
-
13
- return keys;
14
- }
15
-
16
- function _objectSpread2(target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = null != arguments[i] ? arguments[i] : {};
19
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
20
- _defineProperty(target, key, source[key]);
21
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
22
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
23
- });
24
- }
25
-
26
- return target;
27
- }
28
-
29
- function _defineProperty(obj, key, value) {
30
- if (key in obj) {
31
- Object.defineProperty(obj, key, {
32
- value: value,
33
- enumerable: true,
34
- configurable: true,
35
- writable: true
36
- });
37
- } else {
38
- obj[key] = value;
39
- }
40
-
41
- return obj;
42
- }
43
-
44
- var fs = function fs() {
45
- return window[window._fs_namespace];
3
+ /******************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+
18
+ var __assign = function() {
19
+ __assign = Object.assign || function __assign(t) {
20
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
21
+ s = arguments[i];
22
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
46
27
  };
47
28
 
48
- var ensureSnippetLoaded = function ensureSnippetLoaded() {
49
- var snippetLoaded = !!fs();
50
-
51
- if (!snippetLoaded) {
52
- throw Error('FullStory is not loaded, please ensure the init function is invoked before calling FullStory API functions');
53
- }
29
+ var getFullStory = function () {
30
+ if (window._fs_namespace) {
31
+ return window[window._fs_namespace];
32
+ }
33
+ return undefined;
54
34
  };
55
-
56
- var hasFullStoryWithFunction = function hasFullStoryWithFunction() {
57
- ensureSnippetLoaded();
58
-
59
- for (var _len = arguments.length, testNames = new Array(_len), _key = 0; _key < _len; _key++) {
60
- testNames[_key] = arguments[_key];
61
- }
62
-
63
- return testNames.every(function (current) {
64
- return fs()[current];
65
- });
35
+ var ensureSnippetLoaded = function () {
36
+ var fs = getFullStory();
37
+ if (!fs) {
38
+ throw Error('FullStory is not loaded, please ensure the init function is invoked before calling FullStory API functions');
39
+ }
40
+ return fs;
66
41
  };
67
-
68
- var guard = function guard(name) {
69
- return function () {
70
- if (window._fs_dev_mode) {
71
- var message = "FullStory is in dev mode and is not recording: ".concat(name, " method not executed");
72
- console.warn(message);
73
- return message;
42
+ var _init = function (inputOptions, readyCallback) {
43
+ // Make a copy so we can modify `options` if desired.
44
+ var options = __assign({}, inputOptions);
45
+ if (getFullStory()) {
46
+ console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
47
+ return;
74
48
  }
75
-
76
- if (hasFullStoryWithFunction(name)) {
77
- var _fs;
78
-
79
- return (_fs = fs())[name].apply(_fs, arguments);
49
+ // see README for details on the recordCrossDomainIFrames option
50
+ if (options.recordCrossDomainIFrames) {
51
+ window._fs_run_in_iframe = true;
80
52
  }
81
-
82
- console.warn("FS.".concat(name, " not ready"));
83
- return null;
84
- };
85
- };
86
-
87
- var event = guard('event');
88
- var log = guard('log');
89
- var getCurrentSessionURL = guard('getCurrentSessionURL');
90
- var identify = guard('identify');
91
- var setUserVars = guard('setUserVars');
92
- var consent = guard('consent');
93
- var shutdown = guard('shutdown');
94
- var restart = guard('restart');
95
- var anonymize = guard('anonymize');
96
- var setVars = guard('setVars');
97
-
98
- var _init = function _init(inputOptions, readyCallback) {
99
- var options = _objectSpread2({}, inputOptions);
100
-
101
- if (fs()) {
102
- console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
103
- return;
104
- }
105
-
106
- if (options.recordCrossDomainIFrames) {
107
- window._fs_run_in_iframe = true;
108
- }
109
-
110
- if (options.recordOnlyThisIFrame) {
111
- window._fs_is_outer_script = true;
112
- }
113
-
114
- if (options.cookieDomain) {
115
- window._fs_cookie_domain = options.cookieDomain;
116
- }
117
-
118
- if (options.debug === true) {
119
- if (!options.script) {
120
- options.script = 'edge.fullstory.com/s/fs-debug.js';
121
- } else {
122
- console.warn('Ignoring `debug = true` because `script` is set');
53
+ // record the contents of this iFrame when embedded in a parent site
54
+ if (options.recordOnlyThisIFrame) {
55
+ window._fs_is_outer_script = true;
56
+ }
57
+ // Set cookie domain if it was specified.
58
+ if (options.cookieDomain) {
59
+ window._fs_cookie_domain = options.cookieDomain;
60
+ }
61
+ if (options.debug === true) {
62
+ if (!options.script) {
63
+ options.script = 'edge.fullstory.com/s/fs-debug.js';
64
+ }
65
+ else {
66
+ console.warn('Ignoring `debug = true` because `script` is set');
67
+ }
68
+ }
69
+ initFS(options);
70
+ var fs = getFullStory();
71
+ if (!fs) {
72
+ console.warn('Failed to initialize FS snippet');
73
+ return;
74
+ }
75
+ if (readyCallback) {
76
+ fs('observe', { type: 'start', callback: readyCallback });
77
+ }
78
+ if (options.devMode === true) {
79
+ var message = 'FullStory was initialized in devMode and will stop recording';
80
+ fs('trackEvent', {
81
+ name: 'FullStory Dev Mode',
82
+ properties: {
83
+ message_str: message,
84
+ }
85
+ });
86
+ fs('shutdown');
87
+ window._fs_dev_mode = true;
88
+ console.warn(message);
123
89
  }
124
- }
125
-
126
- initFS(options);
127
-
128
- if (readyCallback) {
129
- fs()('observe', {
130
- type: 'start',
131
- callback: readyCallback
132
- });
133
- }
134
-
135
- if (options.devMode === true) {
136
- var message = 'FullStory was initialized in devMode and will stop recording';
137
- event('FullStory Dev Mode', {
138
- message_str: message
139
- });
140
- shutdown();
141
- window._fs_dev_mode = true;
142
- console.warn(message);
143
- }
144
90
  };
145
-
146
- var initOnce = function initOnce(fn, message) {
147
- return function () {
91
+ var initOnce = function (message) { return function (inputOptions, readyCallback) {
148
92
  if (window._fs_initialized) {
149
- if (message) console.warn(message);
150
- return;
93
+ if (message)
94
+ console.warn(message);
95
+ return;
151
96
  }
152
-
153
- fn.apply(void 0, arguments);
97
+ _init(inputOptions, readyCallback);
154
98
  window._fs_initialized = true;
155
- };
99
+ }; };
100
+ var init = initOnce('FullStory init has already been called once, additional invocations are ignored');
101
+ // normalize undefined into boolean
102
+ var isInitialized = function () { return !!window._fs_initialized; };
103
+ var hasFullStoryWithFunction = function () {
104
+ var testNames = [];
105
+ for (var _i = 0; _i < arguments.length; _i++) {
106
+ testNames[_i] = arguments[_i];
107
+ }
108
+ var fs = ensureSnippetLoaded();
109
+ return testNames.every(function (current) { return fs[current]; });
156
110
  };
157
-
158
- var init = initOnce(_init, 'FullStory init has already been called once, additional invocations are ignored');
159
- var isInitialized = function isInitialized() {
160
- return !!window._fs_initialized;
111
+ var guard = function (name) { return function () {
112
+ var args = [];
113
+ for (var _i = 0; _i < arguments.length; _i++) {
114
+ args[_i] = arguments[_i];
115
+ }
116
+ if (window._fs_dev_mode) {
117
+ var message = "FullStory is in dev mode and is not recording: ".concat(name, " method not executed");
118
+ console.warn(message);
119
+ return message;
120
+ }
121
+ var fs = getFullStory();
122
+ if (hasFullStoryWithFunction(name) && fs) {
123
+ return fs[name].apply(fs, args);
124
+ }
125
+ console.warn("FS.".concat(name, " not ready"));
126
+ return null;
127
+ }; };
128
+ var buildFullStoryShim = function () {
129
+ var FS = function (operation, options, source) {
130
+ var fs = ensureSnippetLoaded();
131
+ if (window._fs_dev_mode) {
132
+ var message = 'FullStory is in dev mode and is not recording: method not executed';
133
+ console.warn(message);
134
+ return undefined;
135
+ }
136
+ return fs(operation, options, source);
137
+ };
138
+ FS.anonymize = guard('anonymize');
139
+ FS.consent = guard('consent');
140
+ FS.disableConsole = guard('disableConsole');
141
+ FS.enableConsole = guard('enableConsole');
142
+ FS.event = guard('event');
143
+ FS.getCurrentSessionURL = guard('getCurrentSessionURL');
144
+ FS.identify = guard('identify');
145
+ FS.log = guard('log');
146
+ FS.restart = guard('restart');
147
+ FS.setUserVars = guard('setUserVars');
148
+ FS.setVars = guard('setVars');
149
+ FS.shutdown = guard('shutdown');
150
+ return FS;
161
151
  };
152
+ var FullStory = buildFullStoryShim();
162
153
 
163
- export { anonymize, consent, event, getCurrentSessionURL, identify, init, isInitialized, log, restart, setUserVars, setVars, shutdown };
154
+ export { FullStory, init, isInitialized };