@fullstory/browser 1.5.1 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.0
4
+
5
+ - Add a `readyCallback` parameter to the `init` function (#140)
6
+ - Add an `isInitialized` API (#130)
7
+ - Automated dependency updates
8
+
3
9
  ## 1.5.1
4
10
 
5
11
  - 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 = ({ 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
@@ -157,7 +157,7 @@ var restart = guard('restart');
157
157
  var anonymize = guard('anonymize');
158
158
  var setVars = guard('setVars');
159
159
 
160
- var _init = function _init(options) {
160
+ var _init = function _init(options, readyCallback) {
161
161
  if (fs()) {
162
162
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
163
163
  return;
@@ -173,6 +173,13 @@ var _init = function _init(options) {
173
173
 
174
174
  snippet(options);
175
175
 
176
+ if (readyCallback) {
177
+ fs()('observe', {
178
+ type: 'start',
179
+ callback: readyCallback
180
+ });
181
+ }
182
+
176
183
  if (options.devMode === true) {
177
184
  var message = 'FullStory was initialized in devMode and will stop recording';
178
185
  event('FullStory Dev Mode', {
@@ -197,5 +204,8 @@ var initOnce = function initOnce(fn, message) {
197
204
  };
198
205
 
199
206
  var init = initOnce(_init, 'FullStory init has already been called once, additional invocations are ignored');
207
+ var isInitialized = function isInitialized() {
208
+ return !!window._fs_initialized;
209
+ };
200
210
 
201
- export { anonymize, consent, event, getCurrentSessionURL, identify, init, log, restart, setUserVars, setVars, shutdown };
211
+ export { anonymize, consent, event, getCurrentSessionURL, identify, init, isInitialized, log, restart, setUserVars, setVars, shutdown };
package/dist/index.js CHANGED
@@ -161,7 +161,7 @@ var restart = guard('restart');
161
161
  var anonymize = guard('anonymize');
162
162
  var setVars = guard('setVars');
163
163
 
164
- var _init = function _init(options) {
164
+ var _init = function _init(options, readyCallback) {
165
165
  if (fs()) {
166
166
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
167
167
  return;
@@ -177,6 +177,13 @@ var _init = function _init(options) {
177
177
 
178
178
  snippet(options);
179
179
 
180
+ if (readyCallback) {
181
+ fs()('observe', {
182
+ type: 'start',
183
+ callback: readyCallback
184
+ });
185
+ }
186
+
180
187
  if (options.devMode === true) {
181
188
  var message = 'FullStory was initialized in devMode and will stop recording';
182
189
  event('FullStory Dev Mode', {
@@ -201,6 +208,9 @@ var initOnce = function initOnce(fn, message) {
201
208
  };
202
209
 
203
210
  var init = initOnce(_init, 'FullStory init has already been called once, additional invocations are ignored');
211
+ var isInitialized = function isInitialized() {
212
+ return !!window._fs_initialized;
213
+ };
204
214
 
205
215
  exports.anonymize = anonymize;
206
216
  exports.consent = consent;
@@ -208,6 +218,7 @@ exports.event = event;
208
218
  exports.getCurrentSessionURL = getCurrentSessionURL;
209
219
  exports.identify = identify;
210
220
  exports.init = init;
221
+ exports.isInitialized = isInitialized;
211
222
  exports.log = log;
212
223
  exports.restart = restart;
213
224
  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.0",
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 = ({ 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
@@ -39,7 +39,7 @@ 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 = (options, readyCallback) => {
43
43
  if (fs()) {
44
44
  // eslint-disable-next-line no-console
45
45
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
@@ -58,6 +58,10 @@ const _init = (options) => {
58
58
 
59
59
  snippet(options);
60
60
 
61
+ if (readyCallback) {
62
+ fs()('observe', { type: 'start', callback: readyCallback });
63
+ }
64
+
61
65
  if (options.devMode === true) {
62
66
  const message = 'FullStory was initialized in devMode and will stop recording';
63
67
  event('FullStory Dev Mode', {
@@ -80,3 +84,6 @@ const initOnce = (fn, message) => (...args) => {
80
84
  };
81
85
 
82
86
  export const init = initOnce(_init, 'FullStory init has already been called once, additional invocations are ignored');
87
+
88
+ // normalize undefined into boolean
89
+ export const isInitialized = () => !!window._fs_initialized;