@grafana/faro-web-sdk 1.14.1 → 1.14.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/dist/bundle/faro-web-sdk.iife.js +1 -1
- package/dist/bundle/types/index.d.ts +4 -3
- package/dist/bundle/types/instrumentations/console/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/errors/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/index.d.ts +1 -0
- package/dist/bundle/types/instrumentations/performance/instrumentation.d.ts +4 -3
- package/dist/bundle/types/instrumentations/performance/navigation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/performance/performanceUtils.d.ts +0 -1
- package/dist/bundle/types/instrumentations/performance/resource.d.ts +3 -2
- package/dist/bundle/types/instrumentations/performance/types.d.ts +4 -0
- package/dist/bundle/types/instrumentations/session/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/userActions/const.d.ts +7 -0
- package/dist/bundle/types/instrumentations/userActions/domMutationMonitor.d.ts +2 -0
- package/dist/bundle/types/instrumentations/userActions/httpRequestMonitor.d.ts +5 -0
- package/dist/bundle/types/instrumentations/userActions/index.d.ts +3 -0
- package/dist/bundle/types/instrumentations/userActions/instrumentation.d.ts +6 -0
- package/dist/bundle/types/instrumentations/userActions/performanceEntriesMonitor.d.ts +2 -0
- package/dist/bundle/types/instrumentations/userActions/processUserActionEventHandler.d.ts +2 -0
- package/dist/bundle/types/instrumentations/userActions/types.d.ts +12 -0
- package/dist/bundle/types/instrumentations/userActions/util.d.ts +8 -0
- package/dist/bundle/types/instrumentations/view/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/webVitals/instrumentation.d.ts +1 -1
- package/dist/bundle/types/transports/console/transport.d.ts +1 -1
- package/dist/bundle/types/transports/fetch/transport.d.ts +1 -1
- package/dist/bundle/types/utils/index.d.ts +1 -1
- package/dist/bundle/types/utils/url.d.ts +12 -2
- package/dist/cjs/config/getWebInstrumentations.js +1 -0
- package/dist/cjs/config/getWebInstrumentations.js.map +1 -1
- package/dist/cjs/config/makeCoreConfig.js +20 -7
- package/dist/cjs/config/makeCoreConfig.js.map +1 -1
- package/dist/cjs/index.js +11 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/instrumentations/index.js +4 -1
- package/dist/cjs/instrumentations/index.js.map +1 -1
- package/dist/cjs/instrumentations/performance/instrumentation.js +5 -9
- package/dist/cjs/instrumentations/performance/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/performance/navigation.js +3 -2
- package/dist/cjs/instrumentations/performance/navigation.js.map +1 -1
- package/dist/cjs/instrumentations/performance/performanceUtils.js +1 -6
- package/dist/cjs/instrumentations/performance/performanceUtils.js.map +1 -1
- package/dist/cjs/instrumentations/performance/resource.js +8 -2
- package/dist/cjs/instrumentations/performance/resource.js.map +1 -1
- package/dist/cjs/instrumentations/performance/types.js.map +1 -1
- package/dist/cjs/instrumentations/userActions/const.js +11 -0
- package/dist/cjs/instrumentations/userActions/const.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/domMutationMonitor.js +20 -0
- package/dist/cjs/instrumentations/userActions/domMutationMonitor.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/httpRequestMonitor.js +88 -0
- package/dist/cjs/instrumentations/userActions/httpRequestMonitor.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/index.js +11 -0
- package/dist/cjs/instrumentations/userActions/index.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/instrumentation.js +37 -0
- package/dist/cjs/instrumentations/userActions/instrumentation.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/performanceEntriesMonitor.js +18 -0
- package/dist/cjs/instrumentations/userActions/performanceEntriesMonitor.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/processUserActionEventHandler.js +130 -0
- package/dist/cjs/instrumentations/userActions/processUserActionEventHandler.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/types.js +3 -0
- package/dist/cjs/instrumentations/userActions/types.js.map +1 -0
- package/dist/cjs/instrumentations/userActions/util.js +17 -0
- package/dist/cjs/instrumentations/userActions/util.js.map +1 -0
- package/dist/cjs/utils/index.js +3 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/url.js +15 -2
- package/dist/cjs/utils/url.js.map +1 -1
- package/dist/esm/config/getWebInstrumentations.js +2 -1
- package/dist/esm/config/getWebInstrumentations.js.map +1 -1
- package/dist/esm/config/makeCoreConfig.js +20 -8
- package/dist/esm/config/makeCoreConfig.js.map +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instrumentations/index.js +1 -0
- package/dist/esm/instrumentations/index.js.map +1 -1
- package/dist/esm/instrumentations/performance/instrumentation.js +4 -8
- package/dist/esm/instrumentations/performance/instrumentation.js.map +1 -1
- package/dist/esm/instrumentations/performance/navigation.js +4 -3
- package/dist/esm/instrumentations/performance/navigation.js.map +1 -1
- package/dist/esm/instrumentations/performance/performanceUtils.js +0 -3
- package/dist/esm/instrumentations/performance/performanceUtils.js.map +1 -1
- package/dist/esm/instrumentations/performance/resource.js +9 -3
- package/dist/esm/instrumentations/performance/resource.js.map +1 -1
- package/dist/esm/instrumentations/performance/types.js.map +1 -1
- package/dist/esm/instrumentations/userActions/const.js +8 -0
- package/dist/esm/instrumentations/userActions/const.js.map +1 -0
- package/dist/esm/instrumentations/userActions/domMutationMonitor.js +16 -0
- package/dist/esm/instrumentations/userActions/domMutationMonitor.js.map +1 -0
- package/dist/esm/instrumentations/userActions/httpRequestMonitor.js +84 -0
- package/dist/esm/instrumentations/userActions/httpRequestMonitor.js.map +1 -0
- package/dist/esm/instrumentations/userActions/index.js +3 -0
- package/dist/esm/instrumentations/userActions/index.js.map +1 -0
- package/dist/esm/instrumentations/userActions/instrumentation.js +15 -0
- package/dist/esm/instrumentations/userActions/instrumentation.js.map +1 -0
- package/dist/esm/instrumentations/userActions/performanceEntriesMonitor.js +14 -0
- package/dist/esm/instrumentations/userActions/performanceEntriesMonitor.js.map +1 -0
- package/dist/esm/instrumentations/userActions/processUserActionEventHandler.js +126 -0
- package/dist/esm/instrumentations/userActions/processUserActionEventHandler.js.map +1 -0
- package/dist/esm/instrumentations/userActions/types.js +2 -0
- package/dist/esm/instrumentations/userActions/types.js.map +1 -0
- package/dist/esm/instrumentations/userActions/util.js +13 -0
- package/dist/esm/instrumentations/userActions/util.js.map +1 -0
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/url.js +12 -1
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/types/instrumentations/console/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/errors/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/index.d.ts +1 -0
- package/dist/types/instrumentations/performance/instrumentation.d.ts +4 -3
- package/dist/types/instrumentations/performance/navigation.d.ts +1 -1
- package/dist/types/instrumentations/performance/performanceUtils.d.ts +0 -1
- package/dist/types/instrumentations/performance/resource.d.ts +3 -2
- package/dist/types/instrumentations/performance/types.d.ts +4 -0
- package/dist/types/instrumentations/session/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/userActions/const.d.ts +7 -0
- package/dist/types/instrumentations/userActions/domMutationMonitor.d.ts +2 -0
- package/dist/types/instrumentations/userActions/httpRequestMonitor.d.ts +5 -0
- package/dist/types/instrumentations/userActions/index.d.ts +3 -0
- package/dist/types/instrumentations/userActions/instrumentation.d.ts +6 -0
- package/dist/types/instrumentations/userActions/performanceEntriesMonitor.d.ts +2 -0
- package/dist/types/instrumentations/userActions/processUserActionEventHandler.d.ts +2 -0
- package/dist/types/instrumentations/userActions/types.d.ts +12 -0
- package/dist/types/instrumentations/userActions/util.d.ts +8 -0
- package/dist/types/instrumentations/view/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/webVitals/instrumentation.d.ts +1 -1
- package/dist/types/transports/console/transport.d.ts +1 -1
- package/dist/types/transports/fetch/transport.d.ts +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/url.d.ts +12 -2
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../../src/instrumentations/performance/resource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAsD;AAGtD,+DAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../../src/instrumentations/performance/resource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAsD;AAGtD,uCAA+C;AAE/C,+DAAwD;AACxD,uDAAuH;AAKvH,IAAM,uBAAuB,GAAG,EAAE,aAAa,EAAE,CAAC,gBAAgB,EAAE,OAAO,CAAC,EAAE,CAAC;AAE/E,SAAgB,sBAAsB,CACpC,gBAAwB,EACxB,SAAiC,EACjC,UAA4C;IAE5C,IAAM,cAAc,GAAG,gBAAI,CAAC,MAAM,CAAC,cAAc,CAAC;IAElD,IAAM,QAAQ,GAAG,IAAI,mBAAmB,CAAC,UAAC,eAAe;QACvD,IAAM,OAAO,GAAG,eAAe,CAAC,UAAU,EAAE,CAAC;QAE7C,KAA+B,UAAO,EAAP,mBAAO,EAAP,qBAAO,EAAP,IAAO,EAAE;YAAnC,IAAM,gBAAgB,gBAAA;YACzB,IAAI,IAAA,kBAAY,EAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE;gBACvC,OAAO;aACR;YAED,IAAM,iBAAiB,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC;YAEpD,IAAI,WAAW,GAAgB,IAAA,iDAA8B,EAAC,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,YAAY,CAAC,CAAC;YAE/F,IACE,CAAC,cAAc,IAAI,IAAI,IAAI,IAAA,0CAAuB,EAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC;gBAC/F,cAAc,EACd;gBACA,IAAM,iBAAiB,yBAClB,IAAA,2CAAwB,EAAC,iBAAiB,CAAC,KAC9C,gBAAgB,kBAAA,EAChB,cAAc,EAAE,IAAA,sBAAU,GAAE,GAC7B,CAAC;gBAEF,IAAI,gBAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE;oBACvC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,CAAC;wBACjB,IAAI,EAAE,qCAAc;qBACrB,CAAC,CAAC;iBACJ;gBAED,SAAS,CAAC,2BAA2B,EAAE,iBAAiB,EAAE,SAAS,EAAE;oBACnE,WAAW,aAAA;oBACX,oBAAoB,EAAE,WAAW,CAAC,UAAU,GAAG,iBAAiB,CAAC,SAAS;iBAC3E,CAAC,CAAC;aACJ;SACF;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,CAAC;QACf,IAAI,EAAE,qCAAc;QACpB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;AACL,CAAC;AA/CD,wDA+CC","sourcesContent":["import { faro, genShortID } from '@grafana/faro-core';\nimport type { EventsAPI, Observable, PushEventOptions } from '@grafana/faro-core';\n\nimport { isUrlIgnored } from '../../utils/url';\n\nimport { RESOURCE_ENTRY } from './performanceConstants';\nimport { createFaroResourceTiming, getSpanContextFromServerTiming, includePerformanceEntry } from './performanceUtils';\nimport type { ResourceEntryMessage } from './types';\n\ntype SpanContext = PushEventOptions['spanContext'];\n\nconst DEFAULT_TRACK_RESOURCES = { initiatorType: ['xmlhttprequest', 'fetch'] };\n\nexport function observeResourceTimings(\n faroNavigationId: string,\n pushEvent: EventsAPI['pushEvent'],\n observable: Observable<ResourceEntryMessage>\n) {\n const trackResources = faro.config.trackResources;\n\n const observer = new PerformanceObserver((observedEntries) => {\n const entries = observedEntries.getEntries();\n\n for (const resourceEntryRaw of entries) {\n if (isUrlIgnored(resourceEntryRaw.name)) {\n return;\n }\n\n const resourceEntryJson = resourceEntryRaw.toJSON();\n\n let spanContext: SpanContext = getSpanContextFromServerTiming(resourceEntryJson?.serverTiming);\n\n if (\n (trackResources == null && includePerformanceEntry(resourceEntryJson, DEFAULT_TRACK_RESOURCES)) ||\n trackResources\n ) {\n const faroResourceEntry = {\n ...createFaroResourceTiming(resourceEntryJson),\n faroNavigationId,\n faroResourceId: genShortID(),\n };\n\n if (faro.config.trackUserActionsPreview) {\n observable?.notify({\n type: RESOURCE_ENTRY,\n });\n }\n\n pushEvent('faro.performance.resource', faroResourceEntry, undefined, {\n spanContext,\n timestampOverwriteMs: performance.timeOrigin + resourceEntryJson.startTime,\n });\n }\n }\n });\n\n observer.observe({\n type: RESOURCE_ENTRY,\n buffered: true,\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instrumentations/performance/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { unknownString } from '@grafana/faro-core';\n\nexport type FaroNavigationTiming = Readonly<\n {\n duration: string;\n documentParsingTime: string;\n domProcessingTime: string;\n pageLoadTime: string;\n domContentLoadHandlerTime: string;\n onLoadTime: string;\n type: NavigationTimingType;\n } & FaroResourceTiming\n>;\n\nexport type FaroResourceTiming = Readonly<{\n name: string;\n duration: string;\n protocol: string;\n tcpHandshakeTime: string;\n dnsLookupTime: string;\n tlsNegotiationTime: string;\n responseStatus: string;\n redirectTime: string;\n requestTime: string;\n fetchTime: string;\n responseTime: string;\n serviceWorkerTime: string;\n decodedBodySize: string;\n encodedBodySize: string;\n cacheHitStatus: 'cache' | 'conditionalFetch' | 'fullLoad';\n renderBlockingStatus: 'blocking' | 'non-blocking' | typeof unknownString;\n initiatorType: string;\n // serverTiming: PerformanceServerTiming[];\n visibilityState: DocumentVisibilityState;\n ttfb: string;\n}>;\n\nexport type FaroNavigationItem = {\n faroNavigationId: string;\n faroPreviousNavigationId: string;\n} & FaroNavigationTiming &\n FaroResourceTiming;\n\nexport type FaroResourceItem = {\n faroNavigationId: string;\n faroResourceId: string;\n} & FaroResourceTiming;\n\nexport type CacheType = 'cache' | 'conditionalFetch' | 'fullLoad';\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instrumentations/performance/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { unknownString } from '@grafana/faro-core';\n\nimport type { RESOURCE_ENTRY } from './performanceConstants';\n\nexport type FaroNavigationTiming = Readonly<\n {\n duration: string;\n documentParsingTime: string;\n domProcessingTime: string;\n pageLoadTime: string;\n domContentLoadHandlerTime: string;\n onLoadTime: string;\n type: NavigationTimingType;\n } & FaroResourceTiming\n>;\n\nexport type FaroResourceTiming = Readonly<{\n name: string;\n duration: string;\n protocol: string;\n tcpHandshakeTime: string;\n dnsLookupTime: string;\n tlsNegotiationTime: string;\n responseStatus: string;\n redirectTime: string;\n requestTime: string;\n fetchTime: string;\n responseTime: string;\n serviceWorkerTime: string;\n decodedBodySize: string;\n encodedBodySize: string;\n cacheHitStatus: 'cache' | 'conditionalFetch' | 'fullLoad';\n renderBlockingStatus: 'blocking' | 'non-blocking' | typeof unknownString;\n initiatorType: string;\n // serverTiming: PerformanceServerTiming[];\n visibilityState: DocumentVisibilityState;\n ttfb: string;\n}>;\n\nexport type FaroNavigationItem = {\n faroNavigationId: string;\n faroPreviousNavigationId: string;\n} & FaroNavigationTiming &\n FaroResourceTiming;\n\nexport type FaroResourceItem = {\n faroNavigationId: string;\n faroResourceId: string;\n} & FaroResourceTiming;\n\nexport type CacheType = 'cache' | 'conditionalFetch' | 'fullLoad';\n\nexport type ResourceEntryMessage = {\n type: typeof RESOURCE_ENTRY;\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.userActionDataAttribute = exports.userActionDataAttributeParsed = exports.MESSAGE_TYPE_DOM_MUTATION = exports.MESSAGE_TYPE_HTTP_REQUEST_PENDING = exports.MESSAGE_TYPE_HTTP_REQUEST_END = exports.MESSAGE_TYPE_HTTP_REQUEST_START = exports.MESSAGE_TYPE_RESOURCE_ENTRY = void 0;
|
|
4
|
+
exports.MESSAGE_TYPE_RESOURCE_ENTRY = 'resource-entry';
|
|
5
|
+
exports.MESSAGE_TYPE_HTTP_REQUEST_START = 'http-request-start';
|
|
6
|
+
exports.MESSAGE_TYPE_HTTP_REQUEST_END = 'http-request-end';
|
|
7
|
+
exports.MESSAGE_TYPE_HTTP_REQUEST_PENDING = 'http-request-pending';
|
|
8
|
+
exports.MESSAGE_TYPE_DOM_MUTATION = 'dom-mutation';
|
|
9
|
+
exports.userActionDataAttributeParsed = 'faroUserActionName';
|
|
10
|
+
exports.userActionDataAttribute = 'data-faro-user-action-name';
|
|
11
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/const.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG,gBAAgB,CAAC;AAC/C,QAAA,+BAA+B,GAAG,oBAAoB,CAAC;AACvD,QAAA,6BAA6B,GAAG,kBAAkB,CAAC;AACnD,QAAA,iCAAiC,GAAG,sBAAsB,CAAC;AAC3D,QAAA,yBAAyB,GAAG,cAAc,CAAC;AAE3C,QAAA,6BAA6B,GAAG,oBAAoB,CAAC;AACrD,QAAA,uBAAuB,GAAG,4BAA4B,CAAC","sourcesContent":["export const MESSAGE_TYPE_RESOURCE_ENTRY = 'resource-entry';\nexport const MESSAGE_TYPE_HTTP_REQUEST_START = 'http-request-start';\nexport const MESSAGE_TYPE_HTTP_REQUEST_END = 'http-request-end';\nexport const MESSAGE_TYPE_HTTP_REQUEST_PENDING = 'http-request-pending';\nexport const MESSAGE_TYPE_DOM_MUTATION = 'dom-mutation';\n\nexport const userActionDataAttributeParsed = 'faroUserActionName';\nexport const userActionDataAttribute = 'data-faro-user-action-name';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monitorDomMutations = void 0;
|
|
4
|
+
var faro_core_1 = require("@grafana/faro-core");
|
|
5
|
+
var const_1 = require("./const");
|
|
6
|
+
function monitorDomMutations() {
|
|
7
|
+
var observable = new faro_core_1.Observable();
|
|
8
|
+
var observer = new MutationObserver(function (_mutationsList, _observer) {
|
|
9
|
+
observable.notify({ type: const_1.MESSAGE_TYPE_DOM_MUTATION });
|
|
10
|
+
});
|
|
11
|
+
observer.observe(document, {
|
|
12
|
+
attributes: true,
|
|
13
|
+
childList: true,
|
|
14
|
+
subtree: true,
|
|
15
|
+
characterData: true,
|
|
16
|
+
});
|
|
17
|
+
return observable;
|
|
18
|
+
}
|
|
19
|
+
exports.monitorDomMutations = monitorDomMutations;
|
|
20
|
+
//# sourceMappingURL=domMutationMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domMutationMonitor.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/domMutationMonitor.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AAEhD,iCAAoD;AAGpD,SAAgB,mBAAmB;IACjC,IAAM,UAAU,GAAG,IAAI,sBAAU,EAAsB,CAAC;IAExD,IAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,UAAC,cAAc,EAAE,SAAS;QAC9D,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,iCAAyB,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE;QACzB,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC;AAfD,kDAeC","sourcesContent":["import { Observable } from '@grafana/faro-core';\n\nimport { MESSAGE_TYPE_DOM_MUTATION } from './const';\nimport type { DomMutationMessage } from './types';\n\nexport function monitorDomMutations(): Observable {\n const observable = new Observable<DomMutationMessage>();\n\n const observer = new MutationObserver((_mutationsList, _observer) => {\n observable.notify({ type: MESSAGE_TYPE_DOM_MUTATION });\n });\n\n observer.observe(document, {\n attributes: true,\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n return observable;\n}\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monitorHttpRequests = void 0;
|
|
4
|
+
var faro_core_1 = require("@grafana/faro-core");
|
|
5
|
+
var url_1 = require("../../utils/url");
|
|
6
|
+
var const_1 = require("./const");
|
|
7
|
+
/**
|
|
8
|
+
* Monitors if any http requests are in progress.
|
|
9
|
+
*/
|
|
10
|
+
function monitorHttpRequests() {
|
|
11
|
+
var observable = new faro_core_1.Observable();
|
|
12
|
+
var pendingXhrRequests = 0;
|
|
13
|
+
var pendingFetchRequests = 0;
|
|
14
|
+
function emitStartMessage() {
|
|
15
|
+
observable.notify({ type: const_1.MESSAGE_TYPE_HTTP_REQUEST_START, pending: pendingXhrRequests + pendingFetchRequests });
|
|
16
|
+
}
|
|
17
|
+
function emitEndMessage() {
|
|
18
|
+
observable.notify({ type: const_1.MESSAGE_TYPE_HTTP_REQUEST_END, pending: pendingXhrRequests + pendingFetchRequests });
|
|
19
|
+
}
|
|
20
|
+
monitorFetch(function () {
|
|
21
|
+
pendingFetchRequests++;
|
|
22
|
+
emitStartMessage();
|
|
23
|
+
}, function () {
|
|
24
|
+
pendingFetchRequests--;
|
|
25
|
+
emitEndMessage();
|
|
26
|
+
});
|
|
27
|
+
monitorXhr(function () {
|
|
28
|
+
pendingXhrRequests++;
|
|
29
|
+
emitStartMessage();
|
|
30
|
+
}, function () {
|
|
31
|
+
pendingXhrRequests--;
|
|
32
|
+
emitEndMessage();
|
|
33
|
+
});
|
|
34
|
+
return observable;
|
|
35
|
+
}
|
|
36
|
+
exports.monitorHttpRequests = monitorHttpRequests;
|
|
37
|
+
function monitorXhr(onRequestStart, onRequestEnd) {
|
|
38
|
+
var originalOpen = XMLHttpRequest.prototype.open;
|
|
39
|
+
var originalSend = XMLHttpRequest.prototype.send;
|
|
40
|
+
XMLHttpRequest.prototype.open = function () {
|
|
41
|
+
var url = arguments[1];
|
|
42
|
+
var isIgnoredUrl = (0, url_1.isUrlIgnored)(url);
|
|
43
|
+
this.addEventListener('loadstart', function () {
|
|
44
|
+
if (!isIgnoredUrl) {
|
|
45
|
+
onRequestStart();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
this.addEventListener('loadend', function () {
|
|
49
|
+
if (!isIgnoredUrl) {
|
|
50
|
+
onRequestEnd();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
originalOpen.apply(this, arguments);
|
|
54
|
+
};
|
|
55
|
+
XMLHttpRequest.prototype.send = function () {
|
|
56
|
+
originalSend.apply(this, arguments);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function monitorFetch(onRequestsStart, onRequestEnd) {
|
|
60
|
+
var originalFetch = window.fetch;
|
|
61
|
+
window.fetch = function () {
|
|
62
|
+
var url = getUrlFromResource(arguments[0]);
|
|
63
|
+
var isIgnoredUrl = (0, url_1.isUrlIgnored)(url);
|
|
64
|
+
// fetch started
|
|
65
|
+
if (!isIgnoredUrl) {
|
|
66
|
+
onRequestsStart();
|
|
67
|
+
}
|
|
68
|
+
return originalFetch.apply(this, arguments).finally(function () {
|
|
69
|
+
// fetch ended
|
|
70
|
+
if (!isIgnoredUrl) {
|
|
71
|
+
onRequestEnd();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getUrlFromResource(resource) {
|
|
77
|
+
if ((0, faro_core_1.isString)(resource)) {
|
|
78
|
+
return resource;
|
|
79
|
+
}
|
|
80
|
+
else if (resource instanceof URL) {
|
|
81
|
+
return resource.href;
|
|
82
|
+
}
|
|
83
|
+
else if ((0, faro_core_1.isFunction)(resource === null || resource === void 0 ? void 0 : resource.toString)) {
|
|
84
|
+
return resource.toString();
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=httpRequestMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpRequestMonitor.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/httpRequestMonitor.ts"],"names":[],"mappings":";;;AAAA,gDAAsE;AAEtE,uCAA+C;AAE/C,iCAAyF;AAGzF;;GAEG;AACH,SAAgB,mBAAmB;IACjC,IAAM,UAAU,GAAG,IAAI,sBAAU,EAAmD,CAAC;IAErF,IAAI,kBAAkB,GAAG,CAAC,CAAC;IAC3B,IAAI,oBAAoB,GAAG,CAAC,CAAC;IAE7B,SAAS,gBAAgB;QACvB,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,uCAA+B,EAAE,OAAO,EAAE,kBAAkB,GAAG,oBAAoB,EAAE,CAAC,CAAC;IACnH,CAAC;IAED,SAAS,cAAc;QACrB,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,qCAA6B,EAAE,OAAO,EAAE,kBAAkB,GAAG,oBAAoB,EAAE,CAAC,CAAC;IACjH,CAAC;IAED,YAAY,CACV;QACE,oBAAoB,EAAE,CAAC;QACvB,gBAAgB,EAAE,CAAC;IACrB,CAAC,EACD;QACE,oBAAoB,EAAE,CAAC;QACvB,cAAc,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;IAEF,UAAU,CACR;QACE,kBAAkB,EAAE,CAAC;QACrB,gBAAgB,EAAE,CAAC;IACrB,CAAC,EACD;QACE,kBAAkB,EAAE,CAAC;QACrB,cAAc,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC;AArCD,kDAqCC;AAED,SAAS,UAAU,CAAC,cAA0B,EAAE,YAAwB;IACtE,IAAM,YAAY,GAAG,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC;IACnD,I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AAS,kBAAkB,CAAC,QAAa;IACvC,IAAI,IAAA,oBAAQ,EAAC,QAAQ,CAAC,EAAE;QACtB,OAAO,QAAQ,CAAC;KACjB;SAAM,IAAI,QAAQ,YAAY,GAAG,EAAE;QAClC,OAAO,QAAQ,CAAC,IAAI,CAAC;KACtB;SAAM,IAAI,IAAA,sBAAU,EAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,CAAC,EAAE;QACzC,OAAO,QAAQ,CAAC,QAAQ,EAAE,CAAC;KAC5B;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { isFunction, isString, Observable } from '@grafana/faro-core';\n\nimport { isUrlIgnored } from '../../utils/url';\n\nimport { MESSAGE_TYPE_HTTP_REQUEST_END, MESSAGE_TYPE_HTTP_REQUEST_START } from './const';\nimport type { HttpRequestEndMessage, HttpRequestStartMessage } from './types';\n\n/**\n * Monitors if any http requests are in progress.\n */\nexport function monitorHttpRequests(): Observable {\n const observable = new Observable<HttpRequestStartMessage | HttpRequestEndMessage>();\n\n let pendingXhrRequests = 0;\n let pendingFetchRequests = 0;\n\n function emitStartMessage() {\n observable.notify({ type: MESSAGE_TYPE_HTTP_REQUEST_START, pending: pendingXhrRequests + pendingFetchRequests });\n }\n\n function emitEndMessage() {\n observable.notify({ type: MESSAGE_TYPE_HTTP_REQUEST_END, pending: pendingXhrRequests + pendingFetchRequests });\n }\n\n monitorFetch(\n () => {\n pendingFetchRequests++;\n emitStartMessage();\n },\n () => {\n pendingFetchRequests--;\n emitEndMessage();\n }\n );\n\n monitorXhr(\n () => {\n pendingXhrRequests++;\n emitStartMessage();\n },\n () => {\n pendingXhrRequests--;\n emitEndMessage();\n }\n );\n\n return observable;\n}\n\nfunction monitorXhr(onRequestStart: () => void, onRequestEnd: () => void) {\n const originalOpen = XMLHttpRequest.prototype.open;\n const originalSend = XMLHttpRequest.prototype.send;\n\n XMLHttpRequest.prototype.open = function () {\n const url = arguments[1];\n const isIgnoredUrl = isUrlIgnored(url);\n\n this.addEventListener('loadstart', () => {\n if (!isIgnoredUrl) {\n onRequestStart();\n }\n });\n\n this.addEventListener('loadend', () => {\n if (!isIgnoredUrl) {\n onRequestEnd();\n }\n });\n\n originalOpen.apply(this, arguments as any);\n };\n\n XMLHttpRequest.prototype.send = function () {\n originalSend.apply(this, arguments as any);\n };\n}\n\nfunction monitorFetch(onRequestsStart: () => void, onRequestEnd: () => void) {\n const originalFetch = window.fetch;\n\n window.fetch = function () {\n const url = getUrlFromResource(arguments[0]);\n const isIgnoredUrl = isUrlIgnored(url);\n\n // fetch started\n if (!isIgnoredUrl) {\n onRequestsStart();\n }\n\n return originalFetch.apply(this, arguments as any).finally(() => {\n // fetch ended\n if (!isIgnoredUrl) {\n onRequestEnd();\n }\n });\n };\n}\n\nfunction getUrlFromResource(resource: any): string | undefined {\n if (isString(resource)) {\n return resource;\n } else if (resource instanceof URL) {\n return resource.href;\n } else if (isFunction(resource?.toString)) {\n return resource.toString();\n }\n return undefined;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.userActionDataAttribute = exports.MESSAGE_TYPE_HTTP_REQUEST_START = exports.MESSAGE_TYPE_HTTP_REQUEST_END = exports.MESSAGE_TYPE_DOM_MUTATION = exports.UserActionInstrumentation = void 0;
|
|
4
|
+
var instrumentation_1 = require("./instrumentation");
|
|
5
|
+
Object.defineProperty(exports, "UserActionInstrumentation", { enumerable: true, get: function () { return instrumentation_1.UserActionInstrumentation; } });
|
|
6
|
+
var const_1 = require("./const");
|
|
7
|
+
Object.defineProperty(exports, "MESSAGE_TYPE_DOM_MUTATION", { enumerable: true, get: function () { return const_1.MESSAGE_TYPE_DOM_MUTATION; } });
|
|
8
|
+
Object.defineProperty(exports, "MESSAGE_TYPE_HTTP_REQUEST_END", { enumerable: true, get: function () { return const_1.MESSAGE_TYPE_HTTP_REQUEST_END; } });
|
|
9
|
+
Object.defineProperty(exports, "MESSAGE_TYPE_HTTP_REQUEST_START", { enumerable: true, get: function () { return const_1.MESSAGE_TYPE_HTTP_REQUEST_START; } });
|
|
10
|
+
Object.defineProperty(exports, "userActionDataAttribute", { enumerable: true, get: function () { return const_1.userActionDataAttribute; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/index.ts"],"names":[],"mappings":";;;AAAA,qDAA8D;AAArD,4HAAA,yBAAyB,OAAA;AAElC,iCAKiB;AAJf,kHAAA,yBAAyB,OAAA;AACzB,sHAAA,6BAA6B,OAAA;AAC7B,wHAAA,+BAA+B,OAAA;AAC/B,gHAAA,uBAAuB,OAAA","sourcesContent":["export { UserActionInstrumentation } from './instrumentation';\nexport type { DomMutationMessage, HttpRequestEndMessage, HttpRequestStartMessage } from './types';\nexport {\n MESSAGE_TYPE_DOM_MUTATION,\n MESSAGE_TYPE_HTTP_REQUEST_END,\n MESSAGE_TYPE_HTTP_REQUEST_START,\n userActionDataAttribute,\n} from './const';\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.UserActionInstrumentation = void 0;
|
|
19
|
+
var faro_core_1 = require("@grafana/faro-core");
|
|
20
|
+
var processUserActionEventHandler_1 = require("./processUserActionEventHandler");
|
|
21
|
+
var UserActionInstrumentation = /** @class */ (function (_super) {
|
|
22
|
+
__extends(UserActionInstrumentation, _super);
|
|
23
|
+
function UserActionInstrumentation() {
|
|
24
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
25
|
+
_this.name = '@grafana/faro-web-sdk:instrumentation-user-action';
|
|
26
|
+
_this.version = faro_core_1.VERSION;
|
|
27
|
+
return _this;
|
|
28
|
+
}
|
|
29
|
+
UserActionInstrumentation.prototype.initialize = function () {
|
|
30
|
+
var processUserEventHandler = (0, processUserActionEventHandler_1.getUserEventHandler)(faro_core_1.faro);
|
|
31
|
+
window.addEventListener('pointerdown', processUserEventHandler);
|
|
32
|
+
window.addEventListener('keydown', processUserEventHandler);
|
|
33
|
+
};
|
|
34
|
+
return UserActionInstrumentation;
|
|
35
|
+
}(faro_core_1.BaseInstrumentation));
|
|
36
|
+
exports.UserActionInstrumentation = UserActionInstrumentation;
|
|
37
|
+
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAAwE;AAExE,iFAAsE;AAEtE;IAA+C,6CAAmB;IAAlE;QAAA,qEASC;QARU,UAAI,GAAG,mDAAmD,CAAC;QAC3D,aAAO,GAAG,mBAAO,CAAC;;IAO7B,CAAC;IALC,8CAAU,GAAV;QACE,IAAM,uBAAuB,GAAG,IAAA,mDAAmB,EAAC,gBAAI,CAAC,CAAC;QAC1D,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC;QAChE,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,uBAAuB,CAAC,CAAC;IAC9D,CAAC;IACH,gCAAC;AAAD,CAAC,AATD,CAA+C,+BAAmB,GASjE;AATY,8DAAyB","sourcesContent":["import { BaseInstrumentation, faro, VERSION } from '@grafana/faro-core';\n\nimport { getUserEventHandler } from './processUserActionEventHandler';\n\nexport class UserActionInstrumentation extends BaseInstrumentation {\n readonly name = '@grafana/faro-web-sdk:instrumentation-user-action';\n readonly version = VERSION;\n\n initialize(): void {\n const processUserEventHandler = getUserEventHandler(faro);\n window.addEventListener('pointerdown', processUserEventHandler);\n window.addEventListener('keydown', processUserEventHandler);\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monitorPerformanceEntries = void 0;
|
|
4
|
+
var faro_core_1 = require("@grafana/faro-core");
|
|
5
|
+
var instrumentation_1 = require("../performance/instrumentation");
|
|
6
|
+
var performanceConstants_1 = require("../performance/performanceConstants");
|
|
7
|
+
var const_1 = require("./const");
|
|
8
|
+
function monitorPerformanceEntries() {
|
|
9
|
+
var observable = new faro_core_1.Observable();
|
|
10
|
+
instrumentation_1.performanceEntriesSubscription.subscribe(function (data) {
|
|
11
|
+
if (data.type === performanceConstants_1.RESOURCE_ENTRY) {
|
|
12
|
+
observable.notify({ type: const_1.MESSAGE_TYPE_RESOURCE_ENTRY });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return observable;
|
|
16
|
+
}
|
|
17
|
+
exports.monitorPerformanceEntries = monitorPerformanceEntries;
|
|
18
|
+
//# sourceMappingURL=performanceEntriesMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performanceEntriesMonitor.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/performanceEntriesMonitor.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AAEhD,kEAAgF;AAChF,4EAAqE;AAErE,iCAAsD;AAEtD,SAAgB,yBAAyB;IACvC,IAAM,UAAU,GAAG,IAAI,sBAAU,EAAE,CAAC;IAEpC,gDAA8B,CAAC,SAAS,CAAC,UAAC,IAAI;QAC5C,IAAI,IAAI,CAAC,IAAI,KAAK,qCAAc,EAAE;YAChC,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,mCAA2B,EAAE,CAAC,CAAC;SAC1D;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC;AAVD,8DAUC","sourcesContent":["import { Observable } from '@grafana/faro-core';\n\nimport { performanceEntriesSubscription } from '../performance/instrumentation';\nimport { RESOURCE_ENTRY } from '../performance/performanceConstants';\n\nimport { MESSAGE_TYPE_RESOURCE_ENTRY } from './const';\n\nexport function monitorPerformanceEntries(): Observable {\n const observable = new Observable();\n\n performanceEntriesSubscription.subscribe((data) => {\n if (data.type === RESOURCE_ENTRY) {\n observable.notify({ type: MESSAGE_TYPE_RESOURCE_ENTRY });\n }\n });\n\n return observable;\n}\n"]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUserEventHandler = void 0;
|
|
4
|
+
var faro_core_1 = require("@grafana/faro-core");
|
|
5
|
+
var const_1 = require("./const");
|
|
6
|
+
var domMutationMonitor_1 = require("./domMutationMonitor");
|
|
7
|
+
var httpRequestMonitor_1 = require("./httpRequestMonitor");
|
|
8
|
+
var performanceEntriesMonitor_1 = require("./performanceEntriesMonitor");
|
|
9
|
+
var util_1 = require("./util");
|
|
10
|
+
function getUserEventHandler(faro) {
|
|
11
|
+
var api = faro.api, config = faro.config;
|
|
12
|
+
var httpMonitor = (0, httpRequestMonitor_1.monitorHttpRequests)();
|
|
13
|
+
var domMutationsMonitor = (0, domMutationMonitor_1.monitorDomMutations)();
|
|
14
|
+
var performanceEntriesMonitor = (0, performanceEntriesMonitor_1.monitorPerformanceEntries)();
|
|
15
|
+
var allMonitorsSub;
|
|
16
|
+
var allMonitorsObserver;
|
|
17
|
+
var timeoutId;
|
|
18
|
+
var actionRunning = false;
|
|
19
|
+
function processUserEvent(event) {
|
|
20
|
+
var _a;
|
|
21
|
+
var userActionName = getUserActionName(event.target, (_a = config.trackUserActionsDataAttributeName) !== null && _a !== void 0 ? _a : const_1.userActionDataAttributeParsed);
|
|
22
|
+
if (actionRunning || userActionName == null) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
actionRunning = true;
|
|
26
|
+
var startTime = (0, faro_core_1.dateNow)();
|
|
27
|
+
var endTime;
|
|
28
|
+
var actionId = (0, faro_core_1.genShortID)();
|
|
29
|
+
faro_core_1.apiMessageBus.notify({
|
|
30
|
+
type: faro_core_1.USER_ACTION_START_MESSAGE_TYPE,
|
|
31
|
+
name: userActionName,
|
|
32
|
+
startTime: startTime,
|
|
33
|
+
parentId: actionId,
|
|
34
|
+
});
|
|
35
|
+
// Triggers if no initial action happened within the first 100ms
|
|
36
|
+
timeoutId = startTimeout(timeoutId, function () {
|
|
37
|
+
endTime = (0, faro_core_1.dateNow)();
|
|
38
|
+
// Listening for follow up activities stops once action is cancelled (set to false)
|
|
39
|
+
actionRunning = false;
|
|
40
|
+
sendUserActionCancelMessage(userActionName, actionId);
|
|
41
|
+
});
|
|
42
|
+
allMonitorsObserver = (0, faro_core_1.merge)(httpMonitor, domMutationsMonitor, performanceEntriesMonitor);
|
|
43
|
+
allMonitorsSub = allMonitorsObserver
|
|
44
|
+
.takeWhile(function () { return actionRunning; })
|
|
45
|
+
.subscribe(function () {
|
|
46
|
+
// A http request, a DOM mutation or a performance entry happened so we have a follow up activity and start the timeout again
|
|
47
|
+
// If timeout is triggered the user action is done and we send respective messages and events
|
|
48
|
+
timeoutId = startTimeout(timeoutId, function () {
|
|
49
|
+
endTime = (0, faro_core_1.dateNow)();
|
|
50
|
+
var duration = endTime - startTime;
|
|
51
|
+
var eventType = event.type;
|
|
52
|
+
// order matters, first emit the user-action-end event and then push the event
|
|
53
|
+
faro_core_1.apiMessageBus.notify({
|
|
54
|
+
type: faro_core_1.USER_ACTION_END_MESSAGE_TYPE,
|
|
55
|
+
name: userActionName,
|
|
56
|
+
id: actionId,
|
|
57
|
+
startTime: startTime,
|
|
58
|
+
endTime: endTime,
|
|
59
|
+
duration: duration,
|
|
60
|
+
eventType: eventType,
|
|
61
|
+
});
|
|
62
|
+
// Send the final action parent event
|
|
63
|
+
api.pushEvent(userActionName, {
|
|
64
|
+
userActionStartTime: startTime.toString(),
|
|
65
|
+
userActionEndTime: endTime.toString(),
|
|
66
|
+
userActionDuration: duration.toString(),
|
|
67
|
+
userActionEventType: eventType,
|
|
68
|
+
}, undefined, {
|
|
69
|
+
timestampOverwriteMs: startTime,
|
|
70
|
+
customPayloadTransformer: function (payload) {
|
|
71
|
+
payload.action = {
|
|
72
|
+
id: actionId,
|
|
73
|
+
name: userActionName,
|
|
74
|
+
};
|
|
75
|
+
return payload;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
// Ensure action is blocked until it is fully processed.
|
|
79
|
+
actionRunning = false;
|
|
80
|
+
allMonitorsSub === null || allMonitorsSub === void 0 ? void 0 : allMonitorsSub.unsubscribe();
|
|
81
|
+
allMonitorsObserver === null || allMonitorsObserver === void 0 ? void 0 : allMonitorsObserver.unsubscribeAll();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
registerVisibilityChangeHandler(allMonitorsSub, allMonitorsObserver);
|
|
86
|
+
return processUserEvent;
|
|
87
|
+
}
|
|
88
|
+
exports.getUserEventHandler = getUserEventHandler;
|
|
89
|
+
function getUserActionName(element, dataAttributeName) {
|
|
90
|
+
var parsedDataAttributeName = (0, util_1.convertDataAttributeName)(dataAttributeName);
|
|
91
|
+
var dataset = element.dataset;
|
|
92
|
+
for (var key in dataset) {
|
|
93
|
+
if (key === parsedDataAttributeName) {
|
|
94
|
+
return dataset[key];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
function startTimeout(timeoutId, cb) {
|
|
100
|
+
var maxTimeSpanTillUserActionEnd = 100;
|
|
101
|
+
if (timeoutId) {
|
|
102
|
+
clearTimeout(timeoutId);
|
|
103
|
+
}
|
|
104
|
+
//@ts-expect-error for some reason vscode is using the node types
|
|
105
|
+
timeoutId = setTimeout(function () {
|
|
106
|
+
cb();
|
|
107
|
+
}, maxTimeSpanTillUserActionEnd);
|
|
108
|
+
return timeoutId;
|
|
109
|
+
}
|
|
110
|
+
function sendUserActionCancelMessage(userActionName, actionId) {
|
|
111
|
+
faro_core_1.apiMessageBus.notify({
|
|
112
|
+
type: faro_core_1.USER_ACTION_CANCEL_MESSAGE_TYPE,
|
|
113
|
+
name: userActionName,
|
|
114
|
+
parentId: actionId,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function registerVisibilityChangeHandler(allMonitorsSub, allMonitorsObserver) {
|
|
118
|
+
// stop monitoring in background tabs
|
|
119
|
+
document.addEventListener('visibilitychange', function () {
|
|
120
|
+
if (document.visibilityState === 'hidden') {
|
|
121
|
+
// Unsubscribe from all monitors when the tab goes into the background to free up resources (merge.unsubscribe() also unsubscribes from all inner observables)
|
|
122
|
+
// Monitors will be re-subscribed in the processEvent function when the first user action is detected
|
|
123
|
+
allMonitorsSub === null || allMonitorsSub === void 0 ? void 0 : allMonitorsSub.unsubscribe();
|
|
124
|
+
allMonitorsSub = undefined;
|
|
125
|
+
allMonitorsObserver === null || allMonitorsObserver === void 0 ? void 0 : allMonitorsObserver.unsubscribeAll();
|
|
126
|
+
allMonitorsObserver = undefined;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=processUserActionEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processUserActionEvent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Q,EAAE;YACzC,8JAA8J;YAC9J,qGAAqG;YACrG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,WAAW,EAAE,CAAC;YAC9B,cAAc,GAAG,SAAS,CAAC;YAE3B,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,cAAc,EAAE,CAAC;YACtC,mBAAmB,GAAG,SAAS,CAAC;SACjC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n apiMessageBus,\n dateNow,\n Faro,\n genShortID,\n merge,\n Observable,\n Subscription,\n USER_ACTION_CANCEL_MESSAGE_TYPE,\n USER_ACTION_END_MESSAGE_TYPE,\n USER_ACTION_START_MESSAGE_TYPE,\n} from '@grafana/faro-core';\n\nimport { userActionDataAttributeParsed as userActionDataAttribute } from './const';\nimport { monitorDomMutations } from './domMutationMonitor';\nimport { monitorHttpRequests } from './httpRequestMonitor';\nimport { monitorPerformanceEntries } from './performanceEntriesMonitor';\nimport { convertDataAttributeName } from './util';\n\nexport function getUserEventHandler(faro: Faro) {\n const { api, config } = faro;\n\n const httpMonitor = monitorHttpRequests();\n const domMutationsMonitor = monitorDomMutations();\n const performanceEntriesMonitor = monitorPerformanceEntries();\n\n let allMonitorsSub: Subscription | undefined;\n let allMonitorsObserver: Observable | undefined;\n\n let timeoutId: number | undefined;\n let actionRunning = false;\n\n function processUserEvent(event: PointerEvent | KeyboardEvent) {\n const userActionName = getUserActionName(\n event.target as HTMLElement,\n config.trackUserActionsDataAttributeName ?? userActionDataAttribute\n );\n\n if (actionRunning || userActionName == null) {\n return;\n }\n\n actionRunning = true;\n\n const startTime = dateNow();\n let endTime: number | undefined;\n\n const actionId = genShortID();\n\n apiMessageBus.notify({\n type: USER_ACTION_START_MESSAGE_TYPE,\n name: userActionName,\n startTime: startTime,\n parentId: actionId,\n });\n\n // Triggers if no initial action happened within the first 100ms\n timeoutId = startTimeout(timeoutId, () => {\n endTime = dateNow();\n\n // Listening for follow up activities stops once action is cancelled (set to false)\n actionRunning = false;\n sendUserActionCancelMessage(userActionName, actionId);\n });\n\n allMonitorsObserver = merge(httpMonitor, domMutationsMonitor, performanceEntriesMonitor);\n\n allMonitorsSub = allMonitorsObserver\n .takeWhile(() => actionRunning)\n .subscribe(() => {\n // A http request, a DOM mutation or a performance entry happened so we have a follow up activity and start the timeout again\n // If timeout is triggered the user action is done and we send respective messages and events\n timeoutId = startTimeout(timeoutId, () => {\n endTime = dateNow();\n\n const duration = endTime - startTime;\n const eventType = event.type;\n\n // order matters, first emit the user-action-end event and then push the event\n apiMessageBus.notify({\n type: USER_ACTION_END_MESSAGE_TYPE,\n name: userActionName,\n id: actionId,\n startTime,\n endTime,\n duration,\n eventType,\n });\n\n // Send the final action parent event\n api.pushEvent(\n userActionName,\n {\n userActionStartTime: startTime.toString(),\n userActionEndTime: endTime.toString(),\n userActionDuration: duration.toString(),\n userActionEventType: eventType,\n },\n undefined,\n {\n timestampOverwriteMs: startTime,\n customPayloadTransformer: (payload) => {\n payload.action = {\n id: actionId,\n name: userActionName,\n };\n\n return payload;\n },\n }\n );\n\n // Ensure action is blocked until it is fully processed.\n actionRunning = false;\n allMonitorsSub?.unsubscribe();\n allMonitorsObserver?.unsubscribeAll();\n });\n });\n }\n\n registerVisibilityChangeHandler(allMonitorsSub, allMonitorsObserver);\n\n return processUserEvent;\n}\n\nfunction getUserActionName(element: HTMLElement, dataAttributeName: string): string | undefined {\n const parsedDataAttributeName = convertDataAttributeName(dataAttributeName);\n const dataset = element.dataset;\n\n for (const key in dataset) {\n if (key === parsedDataAttributeName) {\n return dataset[key];\n }\n }\n\n return undefined;\n}\n\nfunction startTimeout(timeoutId: number | undefined, cb: () => void) {\n const maxTimeSpanTillUserActionEnd = 100;\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n\n //@ts-expect-error for some reason vscode is using the node types\n timeoutId = setTimeout(() => {\n cb();\n }, maxTimeSpanTillUserActionEnd);\n\n return timeoutId;\n}\n\nfunction sendUserActionCancelMessage(userActionName: string, actionId: string) {\n apiMessageBus.notify({\n type: USER_ACTION_CANCEL_MESSAGE_TYPE,\n name: userActionName,\n parentId: actionId,\n });\n}\n\nfunction registerVisibilityChangeHandler(\n allMonitorsSub: Subscription | undefined,\n allMonitorsObserver: Observable | undefined\n) {\n // stop monitoring in background tabs\n document.addEventListener('visibilitychange', () => {\n if (document.visibilityState === 'hidden') {\n // Unsubscribe from all monitors when the tab goes into the background to free up resources (merge.unsubscribe() also unsubscribes from all inner observables)\n // Monitors will be re-subscribed in the processEvent function when the first user action is detected\n allMonitorsSub?.unsubscribe();\n allMonitorsSub = undefined;\n\n allMonitorsObserver?.unsubscribeAll();\n allMonitorsObserver = undefined;\n }\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n MESSAGE_TYPE_DOM_MUTATION,\n MESSAGE_TYPE_HTTP_REQUEST_END,\n MESSAGE_TYPE_HTTP_REQUEST_START,\n} from './const';\n\nexport type DomMutationMessage = {\n type: typeof MESSAGE_TYPE_DOM_MUTATION;\n};\n\nexport type HttpRequestStartMessage = {\n type: typeof MESSAGE_TYPE_HTTP_REQUEST_START;\n pending: number;\n};\n\nexport type HttpRequestEndMessage = {\n type: typeof MESSAGE_TYPE_HTTP_REQUEST_END;\n pending: number;\n};\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertDataAttributeName = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Parses the action attribute name by removing the 'data-' prefix and converting
|
|
6
|
+
* the remaining string to camelCase.
|
|
7
|
+
*
|
|
8
|
+
* This is needed because the browser will remove the 'data-' prefix and the dashes from
|
|
9
|
+
* data attributes and make then camelCase.
|
|
10
|
+
*/
|
|
11
|
+
function convertDataAttributeName(userActionDataAttribute) {
|
|
12
|
+
var withoutData = userActionDataAttribute.split('data-')[1];
|
|
13
|
+
var withUpperCase = withoutData === null || withoutData === void 0 ? void 0 : withoutData.replace(/-(.)/g, function (_, char) { return char.toUpperCase(); });
|
|
14
|
+
return withUpperCase === null || withUpperCase === void 0 ? void 0 : withUpperCase.replace(/-/g, '');
|
|
15
|
+
}
|
|
16
|
+
exports.convertDataAttributeName = convertDataAttributeName;
|
|
17
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/instrumentations/userActions/util.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,wBAAwB,CAAC,uBAA+B;IACtE,IAAM,WAAW,GAAG,uBAAuB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,IAAM,aAAa,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,OAAO,EAAE,UAAC,CAAC,EAAE,IAAI,IAAK,OAAA,IAAI,CAAC,WAAW,EAAE,EAAlB,CAAkB,CAAC,CAAC;IACrF,OAAO,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC1C,CAAC;AAJD,4DAIC","sourcesContent":["/**\n * Parses the action attribute name by removing the 'data-' prefix and converting\n * the remaining string to camelCase.\n *\n * This is needed because the browser will remove the 'data-' prefix and the dashes from\n * data attributes and make then camelCase.\n */\nexport function convertDataAttributeName(userActionDataAttribute: string) {\n const withoutData = userActionDataAttribute.split('data-')[1];\n const withUpperCase = withoutData?.replace(/-(.)/g, (_, char) => char.toUpperCase());\n return withUpperCase?.replace(/-/g, '');\n}\n"]}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIgnoreUrls = exports.throttle = exports.
|
|
3
|
+
exports.getIgnoreUrls = exports.throttle = exports.webStorageType = exports.setItem = exports.removeItem = exports.isWebStorageAvailable = exports.isSessionStorageAvailable = exports.isLocalStorageAvailable = exports.getItem = void 0;
|
|
4
4
|
var webStorage_1 = require("./webStorage");
|
|
5
|
+
Object.defineProperty(exports, "getItem", { enumerable: true, get: function () { return webStorage_1.getItem; } });
|
|
5
6
|
Object.defineProperty(exports, "isLocalStorageAvailable", { enumerable: true, get: function () { return webStorage_1.isLocalStorageAvailable; } });
|
|
6
7
|
Object.defineProperty(exports, "isSessionStorageAvailable", { enumerable: true, get: function () { return webStorage_1.isSessionStorageAvailable; } });
|
|
7
|
-
Object.defineProperty(exports, "webStorageType", { enumerable: true, get: function () { return webStorage_1.webStorageType; } });
|
|
8
|
-
Object.defineProperty(exports, "getItem", { enumerable: true, get: function () { return webStorage_1.getItem; } });
|
|
9
8
|
Object.defineProperty(exports, "isWebStorageAvailable", { enumerable: true, get: function () { return webStorage_1.isWebStorageAvailable; } });
|
|
10
9
|
Object.defineProperty(exports, "removeItem", { enumerable: true, get: function () { return webStorage_1.removeItem; } });
|
|
11
10
|
Object.defineProperty(exports, "setItem", { enumerable: true, get: function () { return webStorage_1.setItem; } });
|
|
11
|
+
Object.defineProperty(exports, "webStorageType", { enumerable: true, get: function () { return webStorage_1.webStorageType; } });
|
|
12
12
|
var throttle_1 = require("./throttle");
|
|
13
13
|
Object.defineProperty(exports, "throttle", { enumerable: true, get: function () { return throttle_1.throttle; } });
|
|
14
14
|
var url_1 = require("./url");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,2CAQsB;AAPpB,qHAAA,uBAAuB,OAAA;AACvB,uHAAA,yBAAyB,OAAA;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,2CAQsB;AAPpB,qGAAA,OAAO,OAAA;AACP,qHAAA,uBAAuB,OAAA;AACvB,uHAAA,yBAAyB,OAAA;AACzB,mHAAA,qBAAqB,OAAA;AACrB,wGAAA,UAAU,OAAA;AACV,qGAAA,OAAO,OAAA;AACP,4GAAA,cAAc,OAAA;AAGhB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAEjB,6BAAsC;AAA7B,oGAAA,aAAa,OAAA","sourcesContent":["export {\n getItem,\n isLocalStorageAvailable,\n isSessionStorageAvailable,\n isWebStorageAvailable,\n removeItem,\n setItem,\n webStorageType,\n} from './webStorage';\n\nexport { throttle } from './throttle';\n\nexport { getIgnoreUrls } from './url';\n"]}
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIgnoreUrls = void 0;
|
|
3
|
+
exports.isUrlIgnored = exports.getIgnoreUrls = void 0;
|
|
4
4
|
var faro_core_1 = require("@grafana/faro-core");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Retrieves a list of URLs to be ignored by aggregating the ignore URLs from all transports.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string[]} An array of URLs to be ignored.
|
|
7
9
|
*/
|
|
8
10
|
function getIgnoreUrls() {
|
|
9
11
|
return faro_core_1.faro.transports.transports.flatMap(function (transport) { return transport.getIgnoreUrls(); });
|
|
10
12
|
}
|
|
11
13
|
exports.getIgnoreUrls = getIgnoreUrls;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the given URL should be ignored based on a list of ignored URLs.
|
|
16
|
+
*
|
|
17
|
+
* @param url - The URL to check.
|
|
18
|
+
* @returns `true` if the URL is in the list of ignored URLs, `false` otherwise.
|
|
19
|
+
*/
|
|
20
|
+
function isUrlIgnored(url) {
|
|
21
|
+
if (url === void 0) { url = ''; }
|
|
22
|
+
return getIgnoreUrls().some(function (ignoredUrl) { return url && url.match(ignoredUrl) != null; });
|
|
23
|
+
}
|
|
24
|
+
exports.isUrlIgnored = isUrlIgnored;
|
|
12
25
|
//# sourceMappingURL=url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/utils/url.ts"],"names":[],"mappings":";;;AAAA,gDAA0C;AAG1C
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/utils/url.ts"],"names":[],"mappings":";;;AAAA,gDAA0C;AAG1C;;;;GAIG;AACH,SAAgB,aAAa;IAC3B,OAAO,gBAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,UAAC,SAAoB,IAAK,OAAA,SAAS,CAAC,aAAa,EAAE,EAAzB,CAAyB,CAAC,CAAC;AACjG,CAAC;AAFD,sCAEC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,GAAQ;IAAR,oBAAA,EAAA,QAAQ;IACnC,OAAO,aAAa,EAAE,CAAC,IAAI,CAAC,UAAC,UAAU,IAAK,OAAA,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,IAAI,EAApC,CAAoC,CAAC,CAAC;AACpF,CAAC;AAFD,oCAEC","sourcesContent":["import { faro } from '@grafana/faro-core';\nimport type { Patterns, Transport } from '@grafana/faro-core';\n\n/**\n * Retrieves a list of URLs to be ignored by aggregating the ignore URLs from all transports.\n *\n * @returns {string[]} An array of URLs to be ignored.\n */\nexport function getIgnoreUrls(): Patterns {\n return faro.transports.transports.flatMap((transport: Transport) => transport.getIgnoreUrls());\n}\n\n/**\n * Checks if the given URL should be ignored based on a list of ignored URLs.\n *\n * @param url - The URL to check.\n * @returns `true` if the URL is in the list of ignored URLs, `false` otherwise.\n */\nexport function isUrlIgnored(url = ''): boolean {\n return getIgnoreUrls().some((ignoredUrl) => url && url.match(ignoredUrl) != null);\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ConsoleInstrumentation, ErrorsInstrumentation, PerformanceInstrumentation, SessionInstrumentation, ViewInstrumentation, WebVitalsInstrumentation, } from '../instrumentations';
|
|
1
|
+
import { ConsoleInstrumentation, ErrorsInstrumentation, PerformanceInstrumentation, SessionInstrumentation, UserActionInstrumentation, ViewInstrumentation, WebVitalsInstrumentation, } from '../instrumentations';
|
|
2
2
|
export function getWebInstrumentations(options = {}) {
|
|
3
3
|
const instrumentations = [
|
|
4
|
+
new UserActionInstrumentation(),
|
|
4
5
|
new ErrorsInstrumentation(),
|
|
5
6
|
new WebVitalsInstrumentation(),
|
|
6
7
|
new SessionInstrumentation(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWebInstrumentations.js","sourceRoot":"","sources":["../../../src/config/getWebInstrumentations.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAI7B,MAAM,UAAU,sBAAsB,CAAC,UAAyC,EAAE;IAChF,MAAM,gBAAgB,GAAsB;QAC1C,IAAI,qBAAqB,EAAE;QAC3B,IAAI,wBAAwB,EAAE;QAC9B,IAAI,sBAAsB,EAAE;QAC5B,IAAI,mBAAmB,EAAE;KAC1B,CAAC;IAEF,IAAI,OAAO,CAAC,gCAAgC,KAAK,KAAK,EAAE;QACtD,iFAAiF;QACjF,gBAAgB,CAAC,OAAO,CAAC,IAAI,0BAA0B,EAAE,CAAC,CAAC;KAC5D;IAED,IAAI,OAAO,CAAC,cAAc,KAAK,KAAK,EAAE;QACpC,gBAAgB,CAAC,IAAI,CACnB,IAAI,sBAAsB,CAAC;YACzB,cAAc,EAAE,OAAO,CAAC,4BAA4B;SACrD,CAAC,CACH,CAAC;KACH;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import type { Instrumentation } from '@grafana/faro-core';\n\nimport {\n ConsoleInstrumentation,\n ErrorsInstrumentation,\n PerformanceInstrumentation,\n SessionInstrumentation,\n ViewInstrumentation,\n WebVitalsInstrumentation,\n} from '../instrumentations';\n\nimport type { GetWebInstrumentationsOptions } from './types';\n\nexport function getWebInstrumentations(options: GetWebInstrumentationsOptions = {}): Instrumentation[] {\n const instrumentations: Instrumentation[] = [\n new ErrorsInstrumentation(),\n new WebVitalsInstrumentation(),\n new SessionInstrumentation(),\n new ViewInstrumentation(),\n ];\n\n if (options.enablePerformanceInstrumentation !== false) {\n // unshift to ensure that initialization starts before the other instrumentations\n instrumentations.unshift(new PerformanceInstrumentation());\n }\n\n if (options.captureConsole !== false) {\n instrumentations.push(\n new ConsoleInstrumentation({\n disabledLevels: options.captureConsoleDisabledLevels,\n })\n );\n }\n\n return instrumentations;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getWebInstrumentations.js","sourceRoot":"","sources":["../../../src/config/getWebInstrumentations.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAI7B,MAAM,UAAU,sBAAsB,CAAC,UAAyC,EAAE;IAChF,MAAM,gBAAgB,GAAsB;QAC1C,IAAI,yBAAyB,EAAE;QAC/B,IAAI,qBAAqB,EAAE;QAC3B,IAAI,wBAAwB,EAAE;QAC9B,IAAI,sBAAsB,EAAE;QAC5B,IAAI,mBAAmB,EAAE;KAC1B,CAAC;IAEF,IAAI,OAAO,CAAC,gCAAgC,KAAK,KAAK,EAAE;QACtD,iFAAiF;QACjF,gBAAgB,CAAC,OAAO,CAAC,IAAI,0BAA0B,EAAE,CAAC,CAAC;KAC5D;IAED,IAAI,OAAO,CAAC,cAAc,KAAK,KAAK,EAAE;QACpC,gBAAgB,CAAC,IAAI,CACnB,IAAI,sBAAsB,CAAC;YACzB,cAAc,EAAE,OAAO,CAAC,4BAA4B;SACrD,CAAC,CACH,CAAC;KACH;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import type { Instrumentation } from '@grafana/faro-core';\n\nimport {\n ConsoleInstrumentation,\n ErrorsInstrumentation,\n PerformanceInstrumentation,\n SessionInstrumentation,\n UserActionInstrumentation,\n ViewInstrumentation,\n WebVitalsInstrumentation,\n} from '../instrumentations';\n\nimport type { GetWebInstrumentationsOptions } from './types';\n\nexport function getWebInstrumentations(options: GetWebInstrumentationsOptions = {}): Instrumentation[] {\n const instrumentations: Instrumentation[] = [\n new UserActionInstrumentation(),\n new ErrorsInstrumentation(),\n new WebVitalsInstrumentation(),\n new SessionInstrumentation(),\n new ViewInstrumentation(),\n ];\n\n if (options.enablePerformanceInstrumentation !== false) {\n // unshift to ensure that initialization starts before the other instrumentations\n instrumentations.unshift(new PerformanceInstrumentation());\n }\n\n if (options.captureConsole !== false) {\n instrumentations.push(\n new ConsoleInstrumentation({\n disabledLevels: options.captureConsoleDisabledLevels,\n })\n );\n }\n\n return instrumentations;\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createInternalLogger, defaultBatchingConfig, defaultGlobalObjectKey, defaultInternalLoggerLevel, defaultLogArgsSerializer, defaultUnpatchedConsole, isEmpty, isObject, } from '@grafana/faro-core';
|
|
1
|
+
import { createInternalLogger, defaultBatchingConfig, defaultGlobalObjectKey, defaultInternalLoggerLevel, defaultLogArgsSerializer, defaultUnpatchedConsole, isBoolean, isEmpty, isObject, } from '@grafana/faro-core';
|
|
2
2
|
import { defaultEventDomain } from '../consts';
|
|
3
3
|
import { parseStacktrace } from '../instrumentations';
|
|
4
4
|
import { defaultSessionTrackingConfig } from '../instrumentations/session';
|
|
5
|
+
import { userActionDataAttribute } from '../instrumentations/userActions/const';
|
|
5
6
|
import { browserMeta } from '../metas';
|
|
6
7
|
import { k6Meta } from '../metas/k6';
|
|
7
8
|
import { createPageMeta } from '../metas/page';
|
|
@@ -26,15 +27,15 @@ export function makeCoreConfig(browserConfig) {
|
|
|
26
27
|
else {
|
|
27
28
|
internalLogger.error('either "url" or "transports" must be defined');
|
|
28
29
|
}
|
|
29
|
-
const { app, batching, beforeSend, consoleInstrumentation, ignoreErrors, sessionTracking, trackResources, trackWebVitalsAttribution, user, view,
|
|
30
|
+
const { app, batching, beforeSend, consoleInstrumentation, ignoreErrors, sessionTracking, trackResources, trackWebVitalsAttribution, user, view, trackGeolocation,
|
|
30
31
|
// properties with default values
|
|
31
|
-
dedupe = true, eventDomain = defaultEventDomain, globalObjectKey = defaultGlobalObjectKey, instrumentations = getWebInstrumentations(), internalLoggerLevel = defaultInternalLoggerLevel, isolate = false, logArgsSerializer = defaultLogArgsSerializer, metas = createDefaultMetas(browserConfig), paused = false, preventGlobalExposure = false, unpatchedConsole = defaultUnpatchedConsole, webVitalsInstrumentation, } = browserConfig;
|
|
32
|
+
dedupe = true, eventDomain = defaultEventDomain, globalObjectKey = defaultGlobalObjectKey, instrumentations = getWebInstrumentations(), internalLoggerLevel = defaultInternalLoggerLevel, isolate = false, logArgsSerializer = defaultLogArgsSerializer, metas = createDefaultMetas(browserConfig), paused = false, preventGlobalExposure = false, unpatchedConsole = defaultUnpatchedConsole, webVitalsInstrumentation, trackUserActionsPreview = false, trackUserActionsDataAttributeName = userActionDataAttribute, trackUserActionsExcludeItem, } = browserConfig;
|
|
32
33
|
return {
|
|
33
34
|
app,
|
|
34
35
|
batching: Object.assign(Object.assign({}, defaultBatchingConfig), batching),
|
|
35
36
|
dedupe: dedupe,
|
|
36
37
|
globalObjectKey,
|
|
37
|
-
instrumentations,
|
|
38
|
+
instrumentations: getFilteredInstrumentations(instrumentations, browserConfig),
|
|
38
39
|
internalLoggerLevel,
|
|
39
40
|
isolate,
|
|
40
41
|
logArgsSerializer,
|
|
@@ -49,15 +50,26 @@ export function makeCoreConfig(browserConfig) {
|
|
|
49
50
|
ignoreErrors,
|
|
50
51
|
// ignore cloud collector urls by default. These are URLs ending with /collect or /collect/ followed by alphanumeric characters.
|
|
51
52
|
ignoreUrls: ((_a = browserConfig.ignoreUrls) !== null && _a !== void 0 ? _a : []).concat([/\/collect(?:\/[\w]*)?$/]),
|
|
52
|
-
sessionTracking: Object.assign(Object.assign(Object.assign({}, defaultSessionTrackingConfig), sessionTracking), crateSessionMeta({
|
|
53
|
+
sessionTracking: Object.assign(Object.assign(Object.assign({}, defaultSessionTrackingConfig), sessionTracking), crateSessionMeta({ trackGeolocation, sessionTracking })),
|
|
53
54
|
user,
|
|
54
55
|
view,
|
|
55
56
|
trackResources,
|
|
56
57
|
trackWebVitalsAttribution,
|
|
57
58
|
consoleInstrumentation,
|
|
58
59
|
webVitalsInstrumentation,
|
|
60
|
+
trackUserActionsPreview,
|
|
61
|
+
trackUserActionsDataAttributeName,
|
|
62
|
+
trackUserActionsExcludeItem,
|
|
59
63
|
};
|
|
60
64
|
}
|
|
65
|
+
function getFilteredInstrumentations(instrumentations, { trackUserActionsPreview }) {
|
|
66
|
+
return instrumentations.filter((instr) => {
|
|
67
|
+
if (instr.name === '@grafana/faro-web-sdk:instrumentation-user-action' && !trackUserActionsPreview) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
61
73
|
function createDefaultMetas(browserConfig) {
|
|
62
74
|
var _a, _b;
|
|
63
75
|
const { page, generatePageId } = (_a = browserConfig === null || browserConfig === void 0 ? void 0 : browserConfig.pageTracking) !== null && _a !== void 0 ? _a : {};
|
|
@@ -72,11 +84,11 @@ function createDefaultMetas(browserConfig) {
|
|
|
72
84
|
}
|
|
73
85
|
return initialMetas;
|
|
74
86
|
}
|
|
75
|
-
function crateSessionMeta({
|
|
87
|
+
function crateSessionMeta({ trackGeolocation, sessionTracking, }) {
|
|
76
88
|
var _a;
|
|
77
89
|
const overrides = {};
|
|
78
|
-
if ((
|
|
79
|
-
overrides.geoLocationTrackingEnabled =
|
|
90
|
+
if (isBoolean(trackGeolocation)) {
|
|
91
|
+
overrides.geoLocationTrackingEnabled = trackGeolocation;
|
|
80
92
|
}
|
|
81
93
|
if (isEmpty(overrides)) {
|
|
82
94
|
return {};
|