@fullstory/browser 1.4.10 → 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,19 @@
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
+
9
+ ## 1.5.1
10
+
11
+ - Updating README to include `host` and `script` configuration options
12
+
13
+ ## 1.5.0
14
+
15
+ - Adding the `setVars` API function
16
+
3
17
  ## 1.4.10
4
18
 
5
19
  - Adding docs to the types file (index.d.ts)
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
 
@@ -28,11 +28,21 @@ The only required option is `orgId`, all others are optional.
28
28
 
29
29
  * `orgId` - Sets your FullStory Org Id. Find out how to get your Org Id [here](https://help.fullstory.com/hc/en-us/articles/360047075853).
30
30
  * `debug` - When set to `true`, enables FullStory debug messages; defaults to `false`.
31
+ * `host` - The recording server host domain. Can be set to direct recorded events to a proxy that you host. Defaults to `fullstory.com`.
32
+ * `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`.
31
33
  * `namespace` - Sets the global identifier for FullStory when conflicts with `FS` arise; see [help](https://help.fullstory.com/hc/en-us/articles/360020624694-What-if-the-identifier-FS-is-used-by-another-script-on-my-site-).
32
34
  * `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.
33
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.
34
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`.
35
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
+
36
46
  ### Initialization Examples
37
47
 
38
48
  #### React
@@ -123,3 +133,16 @@ FullStory.event('Subscribed', {
123
133
  const startOfPlayback = FullStory.getCurrentSessionURL();
124
134
  const playbackAtThisMomentInTime = FullStory.getCurrentSessionURL(true);
125
135
  ```
136
+
137
+ ### Sending custom page data
138
+ ```JavaScript
139
+ FullStory.setVars('page', {
140
+ pageName : 'Checkout', // what is the name of the page?
141
+ cart_size_int : 10, // how many items were in the cart?
142
+ used_coupon_bool : true, // was a coupon used?
143
+ });
144
+ ```
145
+ For more information on setting page vars, view the FullStory help article on [Sending custom page data to FullStory](https://help.fullstory.com/hc/en-us/articles/1500004101581-FS-setVars-API-Sending-custom-page-data-to-FullStory).
146
+
147
+ #### Note
148
+ `FullStory.setVars(<scope>, <payload>)` currently only supports a string value of "page" for the scope. Using arbitrary strings for the scope parameter will result in an Error that will be logged to the browser console or discarded, depending on whether devMode or debug is enabled.
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
  */
@@ -29,17 +29,34 @@ interface UserVars {
29
29
 
30
30
  type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
31
31
 
32
+ type VarScope = 'page';
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
+
32
41
  // API functions that are available as soon as the snippet has executed.
33
42
  export function anonymize(): void;
34
43
  export function consent(userConsents?: boolean): void;
35
44
  export function event(eventName: string, eventProperties: { [key: string]: any }): void;
36
45
  export function identify(uid: string, customVars?: UserVars): void;
37
- 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;
38
54
  export function log(level: LogLevel, msg: string): void;
39
55
  export function log(msg: string): void;
40
56
  export function restart(): void;
41
57
  export function setUserVars(customVars: UserVars): void;
42
58
  export function shutdown(): void;
59
+ export function setVars(varScope: VarScope, properties?: { [key: string]: any }): void;
43
60
 
44
61
  // API functions that are available after /rec/page returns.
45
62
  // FullStory bootstrapping details: https://help.fullstory.com/hc/en-us/articles/360032975773
package/dist/index.esm.js CHANGED
@@ -155,8 +155,9 @@ var consent = guard('consent');
155
155
  var shutdown = guard('shutdown');
156
156
  var restart = guard('restart');
157
157
  var anonymize = guard('anonymize');
158
+ var setVars = guard('setVars');
158
159
 
159
- var _init = function _init(options) {
160
+ var _init = function _init(options, readyCallback) {
160
161
  if (fs()) {
161
162
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
162
163
  return;
@@ -172,6 +173,13 @@ var _init = function _init(options) {
172
173
 
173
174
  snippet(options);
174
175
 
176
+ if (readyCallback) {
177
+ fs()('observe', {
178
+ type: 'start',
179
+ callback: readyCallback
180
+ });
181
+ }
182
+
175
183
  if (options.devMode === true) {
176
184
  var message = 'FullStory was initialized in devMode and will stop recording';
177
185
  event('FullStory Dev Mode', {
@@ -196,5 +204,8 @@ var initOnce = function initOnce(fn, message) {
196
204
  };
197
205
 
198
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
+ };
199
210
 
200
- export { anonymize, consent, event, getCurrentSessionURL, identify, init, log, restart, setUserVars, shutdown };
211
+ export { anonymize, consent, event, getCurrentSessionURL, identify, init, isInitialized, log, restart, setUserVars, setVars, shutdown };
package/dist/index.js CHANGED
@@ -159,8 +159,9 @@ var consent = guard('consent');
159
159
  var shutdown = guard('shutdown');
160
160
  var restart = guard('restart');
161
161
  var anonymize = guard('anonymize');
162
+ var setVars = guard('setVars');
162
163
 
163
- var _init = function _init(options) {
164
+ var _init = function _init(options, readyCallback) {
164
165
  if (fs()) {
165
166
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
166
167
  return;
@@ -176,6 +177,13 @@ var _init = function _init(options) {
176
177
 
177
178
  snippet(options);
178
179
 
180
+ if (readyCallback) {
181
+ fs()('observe', {
182
+ type: 'start',
183
+ callback: readyCallback
184
+ });
185
+ }
186
+
179
187
  if (options.devMode === true) {
180
188
  var message = 'FullStory was initialized in devMode and will stop recording';
181
189
  event('FullStory Dev Mode', {
@@ -200,6 +208,9 @@ var initOnce = function initOnce(fn, message) {
200
208
  };
201
209
 
202
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
+ };
203
214
 
204
215
  exports.anonymize = anonymize;
205
216
  exports.consent = consent;
@@ -207,7 +218,9 @@ exports.event = event;
207
218
  exports.getCurrentSessionURL = getCurrentSessionURL;
208
219
  exports.identify = identify;
209
220
  exports.init = init;
221
+ exports.isInitialized = isInitialized;
210
222
  exports.log = log;
211
223
  exports.restart = restart;
212
224
  exports.setUserVars = setUserVars;
225
+ exports.setVars = setVars;
213
226
  exports.shutdown = shutdown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstory/browser",
3
- "version": "1.4.10",
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",
@@ -43,7 +43,7 @@
43
43
  "karma-mocha": "^2.0.1",
44
44
  "karma-spec-reporter": "0.0.32",
45
45
  "karma-webpack": "^5.0.0",
46
- "mocha": "^9.0.0",
46
+ "mocha": "^9.2.0",
47
47
  "rimraf": "^2.7.1",
48
48
  "rollup": "^1.32.1",
49
49
  "rollup-plugin-copy": "^3.3.0",
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
  */
@@ -29,17 +29,34 @@ interface UserVars {
29
29
 
30
30
  type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
31
31
 
32
+ type VarScope = 'page';
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
+
32
41
  // API functions that are available as soon as the snippet has executed.
33
42
  export function anonymize(): void;
34
43
  export function consent(userConsents?: boolean): void;
35
44
  export function event(eventName: string, eventProperties: { [key: string]: any }): void;
36
45
  export function identify(uid: string, customVars?: UserVars): void;
37
- 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;
38
54
  export function log(level: LogLevel, msg: string): void;
39
55
  export function log(msg: string): void;
40
56
  export function restart(): void;
41
57
  export function setUserVars(customVars: UserVars): void;
42
58
  export function shutdown(): void;
59
+ export function setVars(varScope: VarScope, properties?: { [key: string]: any }): void;
43
60
 
44
61
  // API functions that are available after /rec/page returns.
45
62
  // FullStory bootstrapping details: https://help.fullstory.com/hc/en-us/articles/360032975773
package/src/index.js CHANGED
@@ -37,8 +37,9 @@ export const consent = guard('consent');
37
37
  export const shutdown = guard('shutdown');
38
38
  export const restart = guard('restart');
39
39
  export const anonymize = guard('anonymize');
40
+ export const setVars = guard('setVars');
40
41
 
41
- const _init = (options) => {
42
+ const _init = (options, readyCallback) => {
42
43
  if (fs()) {
43
44
  // eslint-disable-next-line no-console
44
45
  console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
@@ -57,6 +58,10 @@ const _init = (options) => {
57
58
 
58
59
  snippet(options);
59
60
 
61
+ if (readyCallback) {
62
+ fs()('observe', { type: 'start', callback: readyCallback });
63
+ }
64
+
60
65
  if (options.devMode === true) {
61
66
  const message = 'FullStory was initialized in devMode and will stop recording';
62
67
  event('FullStory Dev Mode', {
@@ -79,3 +84,6 @@ const initOnce = (fn, message) => (...args) => {
79
84
  };
80
85
 
81
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;