@fullstory/browser 1.5.1 → 1.6.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.2
4
+
5
+ - Load `fs-debug.js` capture script when `debug = true` option is used to match updated debug logging practices.
6
+
7
+ ## 1.6.1
8
+
9
+ - Fix a TypeScript type issue with the `readyCallback` API (#144)
10
+ - Add a RELEASING doc (#143)
11
+ ## 1.6.0
12
+
13
+ - Add a `readyCallback` parameter to the `init` function (#140)
14
+ - Add an `isInitialized` API (#130)
15
+ - Automated dependency updates
16
+
3
17
  ## 1.5.1
4
18
 
5
19
  - Updating README to include `host` and `script` configuration options
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FullStory Browser SDK
2
2
 
3
- [![CircleCI](https://circleci.com/gh/fullstorydev/fullstory-browser-sdk.svg?style=svg)](https://circleci.com/gh/fullstorydev/fullstory-browser-sdk)
3
+ [![CircleCI](https://circleci.com/gh/fullstorydev/fullstory-browser-sdk.svg?style=svg)](https://circleci.com/gh/fullstorydev/fullstory-browser-sdk) [![npm (scoped)](https://img.shields.io/npm/v/@fullstory/browser)](https://www.npmjs.com/package/@fullstory/browser)
4
4
 
5
5
  FullStory's browser SDK lets you manage FullStory recording on your site as well as retrieve deep links to session replays and send your own custom events. More information about the FullStory API can be found at https://developer.fullstory.com.
6
6
 
@@ -20,7 +20,7 @@ yarn add @fullstory/browser
20
20
 
21
21
  ## Initialize the SDK
22
22
 
23
- Call the `init()` function with options as soon as you can in your website startup process.
23
+ Call the `init()` function with options as soon as you can in your website startup process. Calling init after successful initialization will trigger console warnings - if you need to programmatically check if FullStory has been initialized at some point in your code, you can call `isInitialized()`.
24
24
 
25
25
  ### Configuration Options
26
26
 
@@ -35,6 +35,14 @@ The only required option is `orgId`, all others are optional.
35
35
  * `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.
36
36
  * `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`.
37
37
 
38
+ ### Ready Callback
39
+
40
+ The `init` function also accepts an optional `readyCallback` argument. If you provide a function, it will be invoked when the FullStory session has started. Your callback will be called with one parameter: an object containing information about the session. Currently the only property is `sessionUrl`, which is a string containing the URL to the session.
41
+
42
+ ```javascript
43
+ FullStory.init({ orgId }, ({ sessionUrl }) => console.log(`Started session: ${sessionUrl}`));
44
+ ```
45
+
38
46
  ### Initialization Examples
39
47
 
40
48
  #### React
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * - debug: Debug mode with extra browser console logging.
7
7
  * - host: The recording server host domain. Can be set to direct recorded events to a proxy that you host. Defaults to `fullstory.com`.
8
8
  * - script: FullStory script host domain. FullStory hosts the `fs.js` recording script on a CDN, but you can choose to host a copy yourself. Defaults to `edge.fullstory.com`.
9
- * - recordCrossDomainIFrames: FullStory can record cross-domain iFrames. Defaults to `false`. Certain limitations 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_01F1G333PYKPGZ4B42WDBV3YKV).
9
+ * - recordCrossDomainIFrames: FullStory can record cross-domain iFrames. Defaults to `false`. Certain limitations 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_01F1G333PYKPGZ4B42WDBV3YKV).
10
10
  * - 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).
11
11
  * - 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`.
12
12
  */
@@ -31,12 +31,26 @@ type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
31
31
 
32
32
  type VarScope = 'page';
33
33
 
34
+ /**
35
+ * A callback that will be invoked when FullStory has begun a session.
36
+ *
37
+ * `sessionUrl` contains the URL to the current session.
38
+ */
39
+ type ReadyCallback = (data: { sessionUrl: string }) => void;
40
+
34
41
  // API functions that are available as soon as the snippet has executed.
35
42
  export function anonymize(): void;
36
43
  export function consent(userConsents?: boolean): void;
37
44
  export function event(eventName: string, eventProperties: { [key: string]: any }): void;
38
45
  export function identify(uid: string, customVars?: UserVars): void;
39
- export function init(options: SnippetOptions): void;
46
+ /**
47
+ * Initialize FullStory.
48
+ *
49
+ * @param options Options to pass to the snippet.
50
+ * @param readyCallback If provided, a callback that will be invoked when the FullStory session has begun.
51
+ */
52
+ export function init(options: SnippetOptions, readyCallback?: ReadyCallback): void;
53
+ export function isInitialized(): boolean;
40
54
  export function log(level: LogLevel, msg: string): void;
41
55
  export function log(msg: string): void;
42
56
  export function restart(): void;
package/dist/index.esm.js CHANGED
@@ -1,9 +1,49 @@
1
+ function ownKeys(object, enumerableOnly) {
2
+ var keys = Object.keys(object);
3
+
4
+ if (Object.getOwnPropertySymbols) {
5
+ var symbols = Object.getOwnPropertySymbols(object);
6
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
7
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
8
+ })), keys.push.apply(keys, symbols);
9
+ }
10
+
11
+ return keys;
12
+ }
13
+
14
+ function _objectSpread2(target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = null != arguments[i] ? arguments[i] : {};
17
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
18
+ _defineProperty(target, key, source[key]);
19
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
20
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
21
+ });
22
+ }
23
+
24
+ return target;
25
+ }
26
+
27
+ function _defineProperty(obj, key, value) {
28
+ if (key in obj) {
29
+ Object.defineProperty(obj, key, {
30
+ value: value,
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true
34
+ });
35
+ } else {
36
+ obj[key] = value;
37
+ }
38
+
39
+ return obj;
40
+ }
41
+
1
42
  var snippet = function snippet(_ref) {
2
43
  var orgId = _ref.orgId,
3
44
  _ref$namespace = _ref.namespace,
4
45
  namespace = _ref$namespace === void 0 ? 'FS' : _ref$namespace,
5
46
  _ref$debug = _ref.debug,
6
- debug = _ref$debug === void 0 ? false : _ref$debug,
7
47
  _ref$host = _ref.host,
8
48
  host = _ref$host === void 0 ? 'fullstory.com' : _ref$host,
9
49
  _ref$script = _ref.script,
@@ -13,7 +53,6 @@ var snippet = function snippet(_ref) {
13
53
  throw new Error('FullStory orgId is a required parameter');
14
54
  }
15
55
 
16
- window['_fs_debug'] = debug;
17
56
  window['_fs_host'] = host;
18
57
  window['_fs_script'] = script;
19
58
  window['_fs_org'] = orgId;
@@ -157,7 +196,9 @@ var restart = guard('restart');
157
196
  var anonymize = guard('anonymize');
158
197
  var setVars = guard('setVars');
159
198
 
160
- var _init = function _init(options) {
199
+ var _init = function _init(inputOptions, readyCallback) {
200
+ var options = _objectSpread2({}, inputOptions);
201
+
161
202
  if (fs()) {
162
203
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
163
204
  return;
@@ -171,8 +212,23 @@ var _init = function _init(options) {
171
212
  window._fs_is_outer_script = true;
172
213
  }
173
214
 
215
+ if (options.debug === true) {
216
+ if (!options.script) {
217
+ options.script = 'edge.fullstory.com/s/fs-debug.js';
218
+ } else {
219
+ console.warn('Ignoring `debug = true` because `script` is set');
220
+ }
221
+ }
222
+
174
223
  snippet(options);
175
224
 
225
+ if (readyCallback) {
226
+ fs()('observe', {
227
+ type: 'start',
228
+ callback: readyCallback
229
+ });
230
+ }
231
+
176
232
  if (options.devMode === true) {
177
233
  var message = 'FullStory was initialized in devMode and will stop recording';
178
234
  event('FullStory Dev Mode', {
@@ -197,5 +253,8 @@ var initOnce = function initOnce(fn, message) {
197
253
  };
198
254
 
199
255
  var init = initOnce(_init, 'FullStory init has already been called once, additional invocations are ignored');
256
+ var isInitialized = function isInitialized() {
257
+ return !!window._fs_initialized;
258
+ };
200
259
 
201
- export { anonymize, consent, event, getCurrentSessionURL, identify, init, log, restart, setUserVars, setVars, shutdown };
260
+ export { anonymize, consent, event, getCurrentSessionURL, identify, init, isInitialized, log, restart, setUserVars, setVars, shutdown };
package/dist/index.js CHANGED
@@ -2,12 +2,52 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ function ownKeys(object, enumerableOnly) {
6
+ var keys = Object.keys(object);
7
+
8
+ if (Object.getOwnPropertySymbols) {
9
+ var symbols = Object.getOwnPropertySymbols(object);
10
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
11
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
12
+ })), keys.push.apply(keys, symbols);
13
+ }
14
+
15
+ return keys;
16
+ }
17
+
18
+ function _objectSpread2(target) {
19
+ for (var i = 1; i < arguments.length; i++) {
20
+ var source = null != arguments[i] ? arguments[i] : {};
21
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
22
+ _defineProperty(target, key, source[key]);
23
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
24
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
25
+ });
26
+ }
27
+
28
+ return target;
29
+ }
30
+
31
+ function _defineProperty(obj, key, value) {
32
+ if (key in obj) {
33
+ Object.defineProperty(obj, key, {
34
+ value: value,
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true
38
+ });
39
+ } else {
40
+ obj[key] = value;
41
+ }
42
+
43
+ return obj;
44
+ }
45
+
5
46
  var snippet = function snippet(_ref) {
6
47
  var orgId = _ref.orgId,
7
48
  _ref$namespace = _ref.namespace,
8
49
  namespace = _ref$namespace === void 0 ? 'FS' : _ref$namespace,
9
50
  _ref$debug = _ref.debug,
10
- debug = _ref$debug === void 0 ? false : _ref$debug,
11
51
  _ref$host = _ref.host,
12
52
  host = _ref$host === void 0 ? 'fullstory.com' : _ref$host,
13
53
  _ref$script = _ref.script,
@@ -17,7 +57,6 @@ var snippet = function snippet(_ref) {
17
57
  throw new Error('FullStory orgId is a required parameter');
18
58
  }
19
59
 
20
- window['_fs_debug'] = debug;
21
60
  window['_fs_host'] = host;
22
61
  window['_fs_script'] = script;
23
62
  window['_fs_org'] = orgId;
@@ -161,7 +200,9 @@ var restart = guard('restart');
161
200
  var anonymize = guard('anonymize');
162
201
  var setVars = guard('setVars');
163
202
 
164
- var _init = function _init(options) {
203
+ var _init = function _init(inputOptions, readyCallback) {
204
+ var options = _objectSpread2({}, inputOptions);
205
+
165
206
  if (fs()) {
166
207
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
167
208
  return;
@@ -175,8 +216,23 @@ var _init = function _init(options) {
175
216
  window._fs_is_outer_script = true;
176
217
  }
177
218
 
219
+ if (options.debug === true) {
220
+ if (!options.script) {
221
+ options.script = 'edge.fullstory.com/s/fs-debug.js';
222
+ } else {
223
+ console.warn('Ignoring `debug = true` because `script` is set');
224
+ }
225
+ }
226
+
178
227
  snippet(options);
179
228
 
229
+ if (readyCallback) {
230
+ fs()('observe', {
231
+ type: 'start',
232
+ callback: readyCallback
233
+ });
234
+ }
235
+
180
236
  if (options.devMode === true) {
181
237
  var message = 'FullStory was initialized in devMode and will stop recording';
182
238
  event('FullStory Dev Mode', {
@@ -201,6 +257,9 @@ var initOnce = function initOnce(fn, message) {
201
257
  };
202
258
 
203
259
  var init = initOnce(_init, 'FullStory init has already been called once, additional invocations are ignored');
260
+ var isInitialized = function isInitialized() {
261
+ return !!window._fs_initialized;
262
+ };
204
263
 
205
264
  exports.anonymize = anonymize;
206
265
  exports.consent = consent;
@@ -208,6 +267,7 @@ exports.event = event;
208
267
  exports.getCurrentSessionURL = getCurrentSessionURL;
209
268
  exports.identify = identify;
210
269
  exports.init = init;
270
+ exports.isInitialized = isInitialized;
211
271
  exports.log = log;
212
272
  exports.restart = restart;
213
273
  exports.setUserVars = setUserVars;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstory/browser",
3
- "version": "1.5.1",
3
+ "version": "1.6.2",
4
4
  "description": "The official FullStory browser SDK",
5
5
  "repository": "git://github.com/fullstorydev/fullstory-browser-sdk.git",
6
6
  "homepage": "https://github.com/fullstorydev/fullstory-browser-sdk",
package/src/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * - debug: Debug mode with extra browser console logging.
7
7
  * - host: The recording server host domain. Can be set to direct recorded events to a proxy that you host. Defaults to `fullstory.com`.
8
8
  * - script: FullStory script host domain. FullStory hosts the `fs.js` recording script on a CDN, but you can choose to host a copy yourself. Defaults to `edge.fullstory.com`.
9
- * - recordCrossDomainIFrames: FullStory can record cross-domain iFrames. Defaults to `false`. Certain limitations 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_01F1G333PYKPGZ4B42WDBV3YKV).
9
+ * - recordCrossDomainIFrames: FullStory can record cross-domain iFrames. Defaults to `false`. Certain limitations 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_01F1G333PYKPGZ4B42WDBV3YKV).
10
10
  * - 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).
11
11
  * - 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`.
12
12
  */
@@ -31,12 +31,26 @@ type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
31
31
 
32
32
  type VarScope = 'page';
33
33
 
34
+ /**
35
+ * A callback that will be invoked when FullStory has begun a session.
36
+ *
37
+ * `sessionUrl` contains the URL to the current session.
38
+ */
39
+ type ReadyCallback = (data: { sessionUrl: string }) => void;
40
+
34
41
  // API functions that are available as soon as the snippet has executed.
35
42
  export function anonymize(): void;
36
43
  export function consent(userConsents?: boolean): void;
37
44
  export function event(eventName: string, eventProperties: { [key: string]: any }): void;
38
45
  export function identify(uid: string, customVars?: UserVars): void;
39
- export function init(options: SnippetOptions): void;
46
+ /**
47
+ * Initialize FullStory.
48
+ *
49
+ * @param options Options to pass to the snippet.
50
+ * @param readyCallback If provided, a callback that will be invoked when the FullStory session has begun.
51
+ */
52
+ export function init(options: SnippetOptions, readyCallback?: ReadyCallback): void;
53
+ export function isInitialized(): boolean;
40
54
  export function log(level: LogLevel, msg: string): void;
41
55
  export function log(msg: string): void;
42
56
  export function restart(): void;
package/src/index.js CHANGED
@@ -17,14 +17,14 @@ const hasFullStoryWithFunction = (...testNames) => {
17
17
  const guard = (name) => (...args) => {
18
18
  if (window._fs_dev_mode) {
19
19
  const message = `FullStory is in dev mode and is not recording: ${name} method not executed`;
20
- console.warn(message); // eslint-disable-line no-console
20
+ console.warn(message);
21
21
  return message;
22
22
  }
23
23
 
24
24
  if (hasFullStoryWithFunction(name)) {
25
25
  return fs()[name](...args);
26
26
  }
27
- console.warn(`FS.${name} not ready`); // eslint-disable-line no-console
27
+ console.warn(`FS.${name} not ready`);
28
28
  return null;
29
29
  };
30
30
 
@@ -39,9 +39,10 @@ export const restart = guard('restart');
39
39
  export const anonymize = guard('anonymize');
40
40
  export const setVars = guard('setVars');
41
41
 
42
- const _init = (options) => {
42
+ const _init = (inputOptions, readyCallback) => {
43
+ // Make a copy so we can modify `options` if desired.
44
+ const options = { ...inputOptions };
43
45
  if (fs()) {
44
- // eslint-disable-next-line no-console
45
46
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
46
47
  return;
47
48
  }
@@ -56,8 +57,20 @@ const _init = (options) => {
56
57
  window._fs_is_outer_script = true;
57
58
  }
58
59
 
60
+ if (options.debug === true) {
61
+ if (!options.script) {
62
+ options.script = 'edge.fullstory.com/s/fs-debug.js';
63
+ } else {
64
+ console.warn('Ignoring `debug = true` because `script` is set');
65
+ }
66
+ }
67
+
59
68
  snippet(options);
60
69
 
70
+ if (readyCallback) {
71
+ fs()('observe', { type: 'start', callback: readyCallback });
72
+ }
73
+
61
74
  if (options.devMode === true) {
62
75
  const message = 'FullStory was initialized in devMode and will stop recording';
63
76
  event('FullStory Dev Mode', {
@@ -65,13 +78,12 @@ const _init = (options) => {
65
78
  });
66
79
  shutdown();
67
80
  window._fs_dev_mode = true;
68
- console.warn(message); // eslint-disable-line no-console
81
+ console.warn(message);
69
82
  }
70
83
  };
71
84
 
72
85
  const initOnce = (fn, message) => (...args) => {
73
86
  if (window._fs_initialized) {
74
- // eslint-disable-next-line no-console
75
87
  if (message) console.warn(message);
76
88
  return;
77
89
  }
@@ -80,3 +92,6 @@ const initOnce = (fn, message) => (...args) => {
80
92
  };
81
93
 
82
94
  export const init = initOnce(_init, 'FullStory init has already been called once, additional invocations are ignored');
95
+
96
+ // normalize undefined into boolean
97
+ export const isInitialized = () => !!window._fs_initialized;
package/src/snippet.js CHANGED
@@ -13,8 +13,7 @@ const snippet = (
13
13
  throw new Error('FullStory orgId is a required parameter');
14
14
  }
15
15
  /* begin FullStory snippet */
16
- window['_fs_debug'] = debug;
17
- window['_fs_host'] = host;
16
+ window['_fs_host'] = host;
18
17
  window['_fs_script'] = script;
19
18
  window['_fs_org'] = orgId;
20
19
  window['_fs_namespace'] = namespace;