@fullstory/browser 1.7.1 → 2.0.0-beta.3

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/README.md CHANGED
@@ -35,6 +35,8 @@ The only required option is `orgId`, all others are optional.
35
35
  * `recordCrossDomainIFrames` - Defaults to `false`. FullStory can record cross-domain iFrames if: 1. The FullStory Browser SDK is running in the cross-domain iFrame and 2. `recordCrossDomainIFrames` is set to `true` in the cross-domain iFrame and 3. The FullStory Browser SDK is running in the parent page of the cross-domain iFrame. Click [here](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) for a detailed explanation of what "cross-domain" means. Before using, you should understand the security implications, and configure your [Content Security Policy](https://www.html5rocks.com/en/tutorials/security/content-security-policy/) (CSP) HTTP headers accordingly - specifically the frame-ancestors directive. Failure to configure your CSP headers while using this setting can bypass IFrames security protections that are included in modern browsers. More information about cross-domain iFrame recording can be found on our [Knowledge Base](https://help.fullstory.com/hc/en-us/articles/360020622514-Can-FullStory-capture-content-that-is-presented-in-iframes-#2-the-outer-page-is-running-fullstory-and-you-have-iframes-runni). Note: the `recordCrossDomainIFrames` parameter is the same as the `window['_fs_run_in_iframe']` referenced in the KB article.
36
36
  * `recordOnlyThisIFrame` - When set to `true`, this tells FullStory that the IFrame is the "root" of the recording and should be its own session; defaults to `false`. Use this when your app is embedded in an IFrame on a site not running FullStory or when the site *is* running FullStory, but you want your content sent to a different FullStory org.
37
37
  * `devMode` - Set to `true` if you want to deactivate FullStory in your development environment. When set to `true`, FullStory will shutdown recording and all subsequent SDK method calls will be no-ops. At the time `init` is called with `devMode: true`, a single `event` call will be sent to FullStory to indicate that the SDK is in `devMode`; this is to help trouble-shoot the case that the SDK was accidentally set to `devMode: true` in a production environment. Additionally, any calls to SDK methods will `console.warn` that FullStory is in `devMode`. Defaults to `false`.
38
+ * `startCaptureManually` - Set to `true` if you want to start capture manually using `FS('start')`. FullStory will load but wait for a call to `FS('start')` to begin capturing. See [Manually Delay Data Capture](https://developer.fullstory.com/browser/v2/auto-capture/capture-data/#manually-delay-data-capture) for more information. Defaults to `false`.
39
+ * `assetMapId` - Use this to set the current asset map id. See [Asset Uploading for Web](https://help.fullstory.com/hc/en-us/articles/4404129191575-Asset-Uploading-for-Web) for more information.
38
40
 
39
41
  ### Ready Callback
40
42
 
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,46 @@
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
+ assetMapId?: string;
18
+ cookieDomain?: string;
19
+ debug?: boolean;
20
+ devMode?: boolean;
21
+ host?: string;
22
+ namespace?: string;
23
+ recordCrossDomainIFrames?: boolean;
24
+ recordOnlyThisIFrame?: boolean;
25
+ script?: string;
26
+ startCaptureManually?: boolean;
24
27
  }
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
28
  /**
37
29
  * A callback that will be invoked when FullStory has begun a session.
38
30
  *
39
31
  * `sessionUrl` contains the URL to the current session.
32
+ * `settings` contains the org settings for the current session.
40
33
  */
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;
34
+ type ReadyCallback = (data: {
35
+ sessionUrl: string;
36
+ settings: Readonly<object>;
37
+ }) => void;
38
+ declare global {
39
+ interface Window {
40
+ _fs_asset_map_id?: string;
41
+ _fs_capture_on_startup?: boolean;
42
+ _fs_cookie_domain?: string;
43
+ _fs_debug?: boolean;
44
+ _fs_dev_mode?: boolean;
45
+ _fs_host?: string;
46
+ _fs_initialized?: boolean;
47
+ _fs_is_outer_script?: boolean;
48
+ _fs_namespace?: string;
49
+ _fs_org?: string;
50
+ _fs_run_in_iframe?: boolean;
51
+ _fs_script?: string;
52
+ }
53
+ }
54
+ export declare const init: (inputOptions: SnippetOptions, readyCallback?: ReadyCallback) => void;
55
+ export declare const isInitialized: () => boolean;
56
+ export declare const FullStory: FSApi;
57
+ export {};
package/dist/index.esm.js CHANGED
@@ -1,163 +1,160 @@
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
+ if (options.assetMapId) {
54
+ window._fs_asset_map_id = options.assetMapId;
55
+ }
56
+ if (options.startCaptureManually) {
57
+ window._fs_capture_on_startup = false;
58
+ }
59
+ // record the contents of this iFrame when embedded in a parent site
60
+ if (options.recordOnlyThisIFrame) {
61
+ window._fs_is_outer_script = true;
62
+ }
63
+ // Set cookie domain if it was specified.
64
+ if (options.cookieDomain) {
65
+ window._fs_cookie_domain = options.cookieDomain;
66
+ }
67
+ if (options.debug === true) {
68
+ if (!options.script) {
69
+ options.script = 'edge.fullstory.com/s/fs-debug.js';
70
+ }
71
+ else {
72
+ console.warn('Ignoring `debug = true` because `script` is set');
73
+ }
74
+ }
75
+ initFS(options);
76
+ var fs = getFullStory();
77
+ if (!fs) {
78
+ console.warn('Failed to initialize FS snippet');
79
+ return;
80
+ }
81
+ if (readyCallback) {
82
+ fs('observe', { type: 'start', callback: readyCallback });
83
+ }
84
+ if (options.devMode === true) {
85
+ var message = 'FullStory was initialized in devMode and will stop recording';
86
+ fs('trackEvent', {
87
+ name: 'FullStory Dev Mode',
88
+ properties: {
89
+ message_str: message,
90
+ }
91
+ });
92
+ fs('shutdown');
93
+ window._fs_dev_mode = true;
94
+ console.warn(message);
123
95
  }
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
96
  };
145
-
146
- var initOnce = function initOnce(fn, message) {
147
- return function () {
97
+ var initOnce = function (message) { return function (inputOptions, readyCallback) {
148
98
  if (window._fs_initialized) {
149
- if (message) console.warn(message);
150
- return;
99
+ if (message)
100
+ console.warn(message);
101
+ return;
151
102
  }
152
-
153
- fn.apply(void 0, arguments);
103
+ _init(inputOptions, readyCallback);
154
104
  window._fs_initialized = true;
155
- };
105
+ }; };
106
+ var init = initOnce('FullStory init has already been called once, additional invocations are ignored');
107
+ // normalize undefined into boolean
108
+ var isInitialized = function () { return !!window._fs_initialized; };
109
+ var hasFullStoryWithFunction = function () {
110
+ var testNames = [];
111
+ for (var _i = 0; _i < arguments.length; _i++) {
112
+ testNames[_i] = arguments[_i];
113
+ }
114
+ var fs = ensureSnippetLoaded();
115
+ return testNames.every(function (current) { return fs[current]; });
156
116
  };
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;
117
+ var guard = function (name) { return function () {
118
+ var args = [];
119
+ for (var _i = 0; _i < arguments.length; _i++) {
120
+ args[_i] = arguments[_i];
121
+ }
122
+ if (window._fs_dev_mode) {
123
+ var message = "FullStory is in dev mode and is not recording: ".concat(name, " method not executed");
124
+ console.warn(message);
125
+ return message;
126
+ }
127
+ var fs = getFullStory();
128
+ if (hasFullStoryWithFunction(name) && fs) {
129
+ return fs[name].apply(fs, args);
130
+ }
131
+ console.warn("FS.".concat(name, " not ready"));
132
+ return null;
133
+ }; };
134
+ var buildFullStoryShim = function () {
135
+ var FS = function (operation, options, source) {
136
+ var fs = ensureSnippetLoaded();
137
+ if (window._fs_dev_mode) {
138
+ var message = 'FullStory is in dev mode and is not recording: method not executed';
139
+ console.warn(message);
140
+ return undefined;
141
+ }
142
+ return fs(operation, options, source);
143
+ };
144
+ FS.anonymize = guard('anonymize');
145
+ FS.consent = guard('consent');
146
+ FS.disableConsole = guard('disableConsole');
147
+ FS.enableConsole = guard('enableConsole');
148
+ FS.event = guard('event');
149
+ FS.getCurrentSessionURL = guard('getCurrentSessionURL');
150
+ FS.identify = guard('identify');
151
+ FS.log = guard('log');
152
+ FS.restart = guard('restart');
153
+ FS.setUserVars = guard('setUserVars');
154
+ FS.setVars = guard('setVars');
155
+ FS.shutdown = guard('shutdown');
156
+ return FS;
161
157
  };
158
+ var FullStory = buildFullStoryShim();
162
159
 
163
- export { anonymize, consent, event, getCurrentSessionURL, identify, init, isInitialized, log, restart, setUserVars, setVars, shutdown };
160
+ export { FullStory, init, isInitialized };