@commercetools-frontend/fullstory 1.0.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/README.md +119 -0
- package/constants/dist/commercetools-frontend-fullstory-constants.cjs.d.ts +1 -0
- package/constants/dist/commercetools-frontend-fullstory-constants.cjs.dev.js +10 -0
- package/constants/dist/commercetools-frontend-fullstory-constants.cjs.js +7 -0
- package/constants/dist/commercetools-frontend-fullstory-constants.cjs.prod.js +10 -0
- package/constants/dist/commercetools-frontend-fullstory-constants.esm.js +6 -0
- package/constants/package.json +4 -0
- package/dist/commercetools-frontend-fullstory.cjs.d.ts +1 -0
- package/dist/commercetools-frontend-fullstory.cjs.dev.js +126 -0
- package/dist/commercetools-frontend-fullstory.cjs.js +7 -0
- package/dist/commercetools-frontend-fullstory.cjs.prod.js +126 -0
- package/dist/commercetools-frontend-fullstory.esm.js +89 -0
- package/dist/declarations/src/constants.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +4 -0
- package/dist/declarations/src/initialize.d.ts +7 -0
- package/dist/declarations/src/send-event.d.ts +3 -0
- package/dist/declarations/src/set-user-vars.d.ts +3 -0
- package/dist/declarations/src/tracking-effect.d.ts +7 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @commercetools-frontend/fullstory
|
|
2
|
+
|
|
3
|
+
> This is a package used internally for Merchant Center applications. We do not provide any guarantees or support for the functionality.
|
|
4
|
+
|
|
5
|
+
This package provides an easy to use integration with FullStory. The official documentation of FullStory's SDK can be found [here](https://developer.fullstory.com).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ npm install --save @commercetools-frontend/fullstory
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Initialization
|
|
16
|
+
|
|
17
|
+
At first you will need to initialize FullStory and its SDK
|
|
18
|
+
|
|
19
|
+
You need to add this _before_ you render your application's entry point with for instance `ReactDOM.render`:
|
|
20
|
+
|
|
21
|
+
#### Configuration via a Custom Application configuration
|
|
22
|
+
|
|
23
|
+
If you are developing a Custom Application for the Merchant Center we recommend you to add a `FULLSTORY_ORGANIZATION_ID` as a value to the environment.
|
|
24
|
+
|
|
25
|
+
This environment variable should then we exposed via the `additionalEnv` and a `fullstoryOrganizationId` property in your Custom Application's configuration.
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
additionalEnv: {
|
|
29
|
+
fullstoryOrganizationId: '${env:FULLSTORY_ORGANIZATION_ID}',
|
|
30
|
+
},
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Given that you can just initialize FullStory like this:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { initialize as initializeFullStory } from '@commercetools-frontend/fullstory';
|
|
37
|
+
|
|
38
|
+
initializeFullStory();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
In order for the SDK to be able to connect with FullStory's APIs you have to extend the `headers.csp` property of your Custom Application config to contain the following properties:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { CONTENT_SECURITY_POLICIES as FULLSTORY_CONTENT_SECURITY_POLICIES } from '@commercetools-frontend/fullstory/constants';
|
|
45
|
+
|
|
46
|
+
headers: {
|
|
47
|
+
csp: {
|
|
48
|
+
'connect-src': [...FULLSTORY_CONTENT_SECURITY_POLICIES.CONNECT_SRC],
|
|
49
|
+
'script-src': [...FULLSTORY_CONTENT_SECURITY_POLICIES.SCRIPT_SRC],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Configuration without Custom Application configuration
|
|
55
|
+
|
|
56
|
+
If you are not building a Custom Application or prefer not to configure FullStory using the Custom Application's configuration you can pass the organization ID of FullStory as an argument like this:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { initialize as initializeFullStory } from '@commercetools-frontend/fullstory';
|
|
60
|
+
|
|
61
|
+
initializeFullStory('myFullStoryOrgId');
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Please also make sure that the `connect-src` and `script-src` Content Security Policies allow FullStory to connect with their services. If needed you can use the provided constants from `@commercetools-frontend/fullstory/constants` exported as `CONTENT_SECURITY_POLICIES`.
|
|
65
|
+
|
|
66
|
+
#### Setting up the tracking effect
|
|
67
|
+
|
|
68
|
+
As a last step for any case above you have to use the `useTrackingEffect` in the entry point of your application. Make sure that it is rendered below the `ApplicationShell` component as it depends on its React context.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { useTrackingEffect as useFullStoryTrackingEffect } from '@commercetools-frontend/fullstory';
|
|
72
|
+
|
|
73
|
+
function EntryPoint() {
|
|
74
|
+
useFullStoryTrackingEffect();
|
|
75
|
+
|
|
76
|
+
return <>
|
|
77
|
+
<Application>
|
|
78
|
+
</>
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
1. If you intend to send additional user variables you can pass them using the `additionalUserVars` object
|
|
83
|
+
2. If you intend to disable FullStory entirely (e.g. based on a feature flag), use the `disable` flag
|
|
84
|
+
- Note that you can only disable until you initialized once.
|
|
85
|
+
|
|
86
|
+
### Custom events
|
|
87
|
+
|
|
88
|
+
Domain-specific events recorded by FullStory add additional intelligence when you're searching across sessions and creating new user segments. You can define and record these events with FullStory custom events.
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
import { sendEvent as sendFullStoryEvent } from '@commercetools-frontend/fullstory';
|
|
92
|
+
|
|
93
|
+
sendFullStoryEvent('eventName', {});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Custom events should be needed only in very rare cases as any user interaction is tracked by default.
|
|
97
|
+
|
|
98
|
+
### User variables
|
|
99
|
+
|
|
100
|
+
FullStory allows to record custom user data which is an object or dictionary containing simple key/value pairs you'd like to record.
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import { setUserVars as setFullStoryUserVars } from '@commercetools-frontend/fullstory';
|
|
104
|
+
|
|
105
|
+
setFullStoryUserVars({ email: user.email });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
It's recommended to be mindful in what you send especially with Personal Identifiable Information.
|
|
109
|
+
|
|
110
|
+
## FAQ
|
|
111
|
+
|
|
112
|
+
Question: _I want to disable FullStory on a specific environment_
|
|
113
|
+
Answer: Unset or not set the `FULLSTORY_ORGANIZATION_ID` on that environments dotenv file.
|
|
114
|
+
|
|
115
|
+
Question: _I want to unmask a specific part of the page_
|
|
116
|
+
Answer: Add an `fs-unmask` class name to the outer most element of the area you intend to unmask.
|
|
117
|
+
|
|
118
|
+
Question: _A function of the FullStory SDK is not supported here. How can I use it?_
|
|
119
|
+
Answer: It's recommended to add wrapper to this package and release is to any FullStory SDK usage is encapsulated here.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/constants";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var CONTENT_SECURITY_POLICIES = {
|
|
6
|
+
CONNECT_SRC: ['*.fullstory.com'],
|
|
7
|
+
SCRIPT_SRC: ['*.fullstory.com']
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.CONTENT_SECURITY_POLICIES = CONTENT_SECURITY_POLICIES;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var CONTENT_SECURITY_POLICIES = {
|
|
6
|
+
CONNECT_SRC: ['*.fullstory.com'],
|
|
7
|
+
SCRIPT_SRC: ['*.fullstory.com']
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.CONTENT_SECURITY_POLICIES = CONTENT_SECURITY_POLICIES;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var FullStory = require('@fullstory/browser');
|
|
6
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
10
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
12
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
13
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
14
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
|
+
var react = require('react');
|
|
16
|
+
var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
|
|
17
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
function _interopNamespace(e) {
|
|
21
|
+
if (e && e.__esModule) return e;
|
|
22
|
+
var n = Object.create(null);
|
|
23
|
+
if (e) {
|
|
24
|
+
Object.keys(e).forEach(function (k) {
|
|
25
|
+
if (k !== 'default') {
|
|
26
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return e[k]; }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
n["default"] = e;
|
|
35
|
+
return Object.freeze(n);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var FullStory__namespace = /*#__PURE__*/_interopNamespace(FullStory);
|
|
39
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
40
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
41
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
43
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
44
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
45
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
46
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
47
|
+
|
|
48
|
+
function assertValidFullstoryOrganizationId(fullstoryOrganizationId) {
|
|
49
|
+
if (typeof fullstoryOrganizationId !== 'string') {
|
|
50
|
+
throw new Error('A valid FullStory organization id must be a string.');
|
|
51
|
+
}
|
|
52
|
+
if (fullstoryOrganizationId.length <= 0) {
|
|
53
|
+
throw new Error('A FullStory organization id can not be an empty string.');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function initialize() {
|
|
57
|
+
var fullstoryOrganizationId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app.fullstoryOrganizationId;
|
|
58
|
+
try {
|
|
59
|
+
try {
|
|
60
|
+
assertValidFullstoryOrganizationId(fullstoryOrganizationId);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.warn('[@commercetools-frontend/fullstory]: No valid `fullstoryOrganizationId` passed. Not initializing FullStory.');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
FullStory__namespace.init({
|
|
66
|
+
orgId: fullstoryOrganizationId,
|
|
67
|
+
devMode: process.env.NODE_ENV !== 'production'
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.warn('[@commercetools-frontend/fullstory]: Failed to initialize FullStory due to an error:', error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
75
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
76
|
+
var defaultTrackingArgs = {
|
|
77
|
+
disable: false,
|
|
78
|
+
additionalUserVars: undefined
|
|
79
|
+
};
|
|
80
|
+
function useTrackingEffect() {
|
|
81
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultTrackingArgs,
|
|
82
|
+
disable = _ref.disable,
|
|
83
|
+
additionalUserVars = _ref.additionalUserVars;
|
|
84
|
+
var _useApplicationContex = applicationShellConnectors.useApplicationContext(function (context) {
|
|
85
|
+
return {
|
|
86
|
+
user: context.user,
|
|
87
|
+
project: context.project,
|
|
88
|
+
tenant: context.environment.tenant
|
|
89
|
+
};
|
|
90
|
+
}),
|
|
91
|
+
project = _useApplicationContex.project,
|
|
92
|
+
user = _useApplicationContex.user,
|
|
93
|
+
tenant = _useApplicationContex.tenant;
|
|
94
|
+
react.useEffect(function () {
|
|
95
|
+
// It's not safe to invoke any FullStory SDK methods.
|
|
96
|
+
if (!FullStory__namespace.isInitialized() || disable) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!(user !== null && user !== void 0 && user.id)) {
|
|
100
|
+
FullStory__namespace.anonymize();
|
|
101
|
+
} else {
|
|
102
|
+
FullStory__namespace.identify(user.id, _objectSpread({
|
|
103
|
+
environment: tenant,
|
|
104
|
+
projectKey: project === null || project === void 0 ? void 0 : project.key,
|
|
105
|
+
userBusinessRole: user.businessRole,
|
|
106
|
+
userLocale: user.locale
|
|
107
|
+
}, additionalUserVars));
|
|
108
|
+
}
|
|
109
|
+
}, [disable, additionalUserVars, tenant, project === null || project === void 0 ? void 0 : project.key, user === null || user === void 0 ? void 0 : user.businessRole, user === null || user === void 0 ? void 0 : user.id, user === null || user === void 0 ? void 0 : user.locale]);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// NOTE: This type is not exported from the @fullstory/browser package.
|
|
114
|
+
|
|
115
|
+
function sendEvent(eventName, eventProperties) {
|
|
116
|
+
FullStory__namespace.event(eventName, eventProperties);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function setUserVars(userVars) {
|
|
120
|
+
FullStory__namespace.setUserVars(userVars);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
exports.initialize = initialize;
|
|
124
|
+
exports.sendEvent = sendEvent;
|
|
125
|
+
exports.setUserVars = setUserVars;
|
|
126
|
+
exports.useTrackingEffect = useTrackingEffect;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var FullStory = require('@fullstory/browser');
|
|
6
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
10
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
12
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
13
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
14
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
|
+
var react = require('react');
|
|
16
|
+
var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
|
|
17
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
function _interopNamespace(e) {
|
|
21
|
+
if (e && e.__esModule) return e;
|
|
22
|
+
var n = Object.create(null);
|
|
23
|
+
if (e) {
|
|
24
|
+
Object.keys(e).forEach(function (k) {
|
|
25
|
+
if (k !== 'default') {
|
|
26
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return e[k]; }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
n["default"] = e;
|
|
35
|
+
return Object.freeze(n);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var FullStory__namespace = /*#__PURE__*/_interopNamespace(FullStory);
|
|
39
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
40
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
41
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
43
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
44
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
45
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
46
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
47
|
+
|
|
48
|
+
function assertValidFullstoryOrganizationId(fullstoryOrganizationId) {
|
|
49
|
+
if (typeof fullstoryOrganizationId !== 'string') {
|
|
50
|
+
throw new Error('A valid FullStory organization id must be a string.');
|
|
51
|
+
}
|
|
52
|
+
if (fullstoryOrganizationId.length <= 0) {
|
|
53
|
+
throw new Error('A FullStory organization id can not be an empty string.');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function initialize() {
|
|
57
|
+
var fullstoryOrganizationId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app.fullstoryOrganizationId;
|
|
58
|
+
try {
|
|
59
|
+
try {
|
|
60
|
+
assertValidFullstoryOrganizationId(fullstoryOrganizationId);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.warn('[@commercetools-frontend/fullstory]: No valid `fullstoryOrganizationId` passed. Not initializing FullStory.');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
FullStory__namespace.init({
|
|
66
|
+
orgId: fullstoryOrganizationId,
|
|
67
|
+
devMode: "production" !== 'production'
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.warn('[@commercetools-frontend/fullstory]: Failed to initialize FullStory due to an error:', error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
75
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
76
|
+
var defaultTrackingArgs = {
|
|
77
|
+
disable: false,
|
|
78
|
+
additionalUserVars: undefined
|
|
79
|
+
};
|
|
80
|
+
function useTrackingEffect() {
|
|
81
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultTrackingArgs,
|
|
82
|
+
disable = _ref.disable,
|
|
83
|
+
additionalUserVars = _ref.additionalUserVars;
|
|
84
|
+
var _useApplicationContex = applicationShellConnectors.useApplicationContext(function (context) {
|
|
85
|
+
return {
|
|
86
|
+
user: context.user,
|
|
87
|
+
project: context.project,
|
|
88
|
+
tenant: context.environment.tenant
|
|
89
|
+
};
|
|
90
|
+
}),
|
|
91
|
+
project = _useApplicationContex.project,
|
|
92
|
+
user = _useApplicationContex.user,
|
|
93
|
+
tenant = _useApplicationContex.tenant;
|
|
94
|
+
react.useEffect(function () {
|
|
95
|
+
// It's not safe to invoke any FullStory SDK methods.
|
|
96
|
+
if (!FullStory__namespace.isInitialized() || disable) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!(user !== null && user !== void 0 && user.id)) {
|
|
100
|
+
FullStory__namespace.anonymize();
|
|
101
|
+
} else {
|
|
102
|
+
FullStory__namespace.identify(user.id, _objectSpread({
|
|
103
|
+
environment: tenant,
|
|
104
|
+
projectKey: project === null || project === void 0 ? void 0 : project.key,
|
|
105
|
+
userBusinessRole: user.businessRole,
|
|
106
|
+
userLocale: user.locale
|
|
107
|
+
}, additionalUserVars));
|
|
108
|
+
}
|
|
109
|
+
}, [disable, additionalUserVars, tenant, project === null || project === void 0 ? void 0 : project.key, user === null || user === void 0 ? void 0 : user.businessRole, user === null || user === void 0 ? void 0 : user.id, user === null || user === void 0 ? void 0 : user.locale]);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// NOTE: This type is not exported from the @fullstory/browser package.
|
|
114
|
+
|
|
115
|
+
function sendEvent(eventName, eventProperties) {
|
|
116
|
+
FullStory__namespace.event(eventName, eventProperties);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function setUserVars(userVars) {
|
|
120
|
+
FullStory__namespace.setUserVars(userVars);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
exports.initialize = initialize;
|
|
124
|
+
exports.sendEvent = sendEvent;
|
|
125
|
+
exports.setUserVars = setUserVars;
|
|
126
|
+
exports.useTrackingEffect = useTrackingEffect;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as FullStory from '@fullstory/browser';
|
|
2
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
3
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
4
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
5
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
6
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
7
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
8
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
9
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
10
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
|
|
13
|
+
|
|
14
|
+
function assertValidFullstoryOrganizationId(fullstoryOrganizationId) {
|
|
15
|
+
if (typeof fullstoryOrganizationId !== 'string') {
|
|
16
|
+
throw new Error('A valid FullStory organization id must be a string.');
|
|
17
|
+
}
|
|
18
|
+
if (fullstoryOrganizationId.length <= 0) {
|
|
19
|
+
throw new Error('A FullStory organization id can not be an empty string.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function initialize() {
|
|
23
|
+
var fullstoryOrganizationId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app.fullstoryOrganizationId;
|
|
24
|
+
try {
|
|
25
|
+
try {
|
|
26
|
+
assertValidFullstoryOrganizationId(fullstoryOrganizationId);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn('[@commercetools-frontend/fullstory]: No valid `fullstoryOrganizationId` passed. Not initializing FullStory.');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
FullStory.init({
|
|
32
|
+
orgId: fullstoryOrganizationId,
|
|
33
|
+
devMode: process.env.NODE_ENV !== 'production'
|
|
34
|
+
});
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn('[@commercetools-frontend/fullstory]: Failed to initialize FullStory due to an error:', error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
41
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
42
|
+
var defaultTrackingArgs = {
|
|
43
|
+
disable: false,
|
|
44
|
+
additionalUserVars: undefined
|
|
45
|
+
};
|
|
46
|
+
function useTrackingEffect() {
|
|
47
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultTrackingArgs,
|
|
48
|
+
disable = _ref.disable,
|
|
49
|
+
additionalUserVars = _ref.additionalUserVars;
|
|
50
|
+
var _useApplicationContex = useApplicationContext(function (context) {
|
|
51
|
+
return {
|
|
52
|
+
user: context.user,
|
|
53
|
+
project: context.project,
|
|
54
|
+
tenant: context.environment.tenant
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
project = _useApplicationContex.project,
|
|
58
|
+
user = _useApplicationContex.user,
|
|
59
|
+
tenant = _useApplicationContex.tenant;
|
|
60
|
+
useEffect(function () {
|
|
61
|
+
// It's not safe to invoke any FullStory SDK methods.
|
|
62
|
+
if (!FullStory.isInitialized() || disable) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!(user !== null && user !== void 0 && user.id)) {
|
|
66
|
+
FullStory.anonymize();
|
|
67
|
+
} else {
|
|
68
|
+
FullStory.identify(user.id, _objectSpread({
|
|
69
|
+
environment: tenant,
|
|
70
|
+
projectKey: project === null || project === void 0 ? void 0 : project.key,
|
|
71
|
+
userBusinessRole: user.businessRole,
|
|
72
|
+
userLocale: user.locale
|
|
73
|
+
}, additionalUserVars));
|
|
74
|
+
}
|
|
75
|
+
}, [disable, additionalUserVars, tenant, project === null || project === void 0 ? void 0 : project.key, user === null || user === void 0 ? void 0 : user.businessRole, user === null || user === void 0 ? void 0 : user.id, user === null || user === void 0 ? void 0 : user.locale]);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// NOTE: This type is not exported from the @fullstory/browser package.
|
|
80
|
+
|
|
81
|
+
function sendEvent(eventName, eventProperties) {
|
|
82
|
+
FullStory.event(eventName, eventProperties);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function setUserVars(userVars) {
|
|
86
|
+
FullStory.setUserVars(userVars);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { initialize, sendEvent, setUserVars, useTrackingEffect };
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools-frontend/fullstory",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/commercetools-frontend-fullstory.cjs.js",
|
|
9
|
+
"module": "dist/commercetools-frontend-fullstory.esm.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"typecheck": "tsc --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"constants",
|
|
16
|
+
"package.json",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"preconstruct": {
|
|
20
|
+
"entrypoints": [
|
|
21
|
+
"./index.ts",
|
|
22
|
+
"./constants.ts"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@babel/runtime": "^7.20.7",
|
|
27
|
+
"@babel/runtime-corejs3": "^7.20.7",
|
|
28
|
+
"@fullstory/browser": "1.6.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@commercetools-frontend/application-shell": "21.23.6",
|
|
32
|
+
"@types/node": "18.11.19"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@commercetools-frontend/application-shell-connectors": "21.x",
|
|
36
|
+
"react": "17.x"
|
|
37
|
+
}
|
|
38
|
+
}
|