@openreplay/tracker 3.4.17-beta.1 → 3.5.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/cjs/index.js CHANGED
@@ -81,7 +81,7 @@ class API {
81
81
  (navigator.doNotTrack == '1'
82
82
  // @ts-ignore
83
83
  || window.doNotTrack == '1');
84
- this.app = doNotTrack ||
84
+ const app = this.app = doNotTrack ||
85
85
  !('Map' in window) ||
86
86
  !('Set' in window) ||
87
87
  !('MutationObserver' in window) ||
@@ -92,20 +92,34 @@ class API {
92
92
  !('Worker' in window)
93
93
  ? null
94
94
  : new index_js_1.default(options.projectKey, options.sessionToken, options);
95
- if (this.app !== null) {
96
- (0, viewport_js_1.default)(this.app);
97
- (0, cssrules_js_1.default)(this.app);
98
- (0, connection_js_1.default)(this.app);
99
- (0, console_js_1.default)(this.app, options);
100
- (0, exception_js_1.default)(this.app, options);
101
- (0, img_js_1.default)(this.app);
102
- (0, input_js_1.default)(this.app, options);
103
- (0, mouse_js_1.default)(this.app);
104
- (0, timing_js_1.default)(this.app, options);
105
- (0, performance_js_1.default)(this.app, options);
106
- (0, scroll_js_1.default)(this.app);
107
- (0, longtasks_js_1.default)(this.app);
95
+ if (app !== null) {
96
+ (0, viewport_js_1.default)(app);
97
+ (0, cssrules_js_1.default)(app);
98
+ (0, connection_js_1.default)(app);
99
+ (0, console_js_1.default)(app, options);
100
+ (0, exception_js_1.default)(app, options);
101
+ (0, img_js_1.default)(app);
102
+ (0, input_js_1.default)(app, options);
103
+ (0, mouse_js_1.default)(app);
104
+ (0, timing_js_1.default)(app, options);
105
+ (0, performance_js_1.default)(app, options);
106
+ (0, scroll_js_1.default)(app);
107
+ (0, longtasks_js_1.default)(app);
108
108
  window.__OPENREPLAY__ = this;
109
+ if (options.autoResetOnWindowOpen) {
110
+ const wOpen = window.open;
111
+ app.attachStartCallback(() => {
112
+ // @ts-ignore ?
113
+ window.open = function (...args) {
114
+ app.resetNextPageSession(true);
115
+ wOpen.call(window, ...args);
116
+ app.resetNextPageSession(false);
117
+ };
118
+ });
119
+ app.attachStopCallback(() => {
120
+ window.open = wOpen;
121
+ });
122
+ }
109
123
  }
110
124
  else {
111
125
  console.log("OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1.");
@@ -115,7 +129,7 @@ class API {
115
129
  // no-cors issue only with text/plain or not-set Content-Type
116
130
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
117
131
  req.send(JSON.stringify({
118
- trackerVersion: '3.4.17-beta.1',
132
+ trackerVersion: '3.5.2',
119
133
  projectKey: options.projectKey,
120
134
  doNotTrack,
121
135
  // TODO: add precise reason (an exact API missing)
@@ -131,11 +145,7 @@ class API {
131
145
  }
132
146
  return this.app.active();
133
147
  }
134
- active() {
135
- (0, utils_js_1.deprecationWarn)("'active' method", "'isActive' method", "/");
136
- return this.isActive();
137
- }
138
- start() {
148
+ start(startOpts) {
139
149
  if (!utils_js_1.IN_BROWSER) {
140
150
  console.error(`OpenReplay: you are trying to start Tracker on a node.js environment. If you want to use OpenReplay with SSR, please, use componentDidMount or useEffect API for placing the \`tracker.start()\` line. Check documentation on ${utils_js_1.DOCS_HOST}${DOCS_SETUP}`);
141
151
  return Promise.reject("Trying to start not in browser.");
@@ -143,7 +153,8 @@ class API {
143
153
  if (this.app === null) {
144
154
  return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
145
155
  }
146
- return this.app.start();
156
+ // TODO: check argument typing
157
+ return this.app.start(startOpts);
147
158
  }
148
159
  stop() {
149
160
  if (this.app === null) {
@@ -223,11 +234,5 @@ class API {
223
234
  this.app.send(new index_js_3.CustomIssue(key, payload));
224
235
  }
225
236
  }
226
- resetNextPageSession(flag) {
227
- if (typeof flag !== 'boolean' || !this.app) {
228
- return;
229
- }
230
- this.app.resetNextPageSession(flag);
231
- }
232
237
  }
233
238
  exports.default = API;
@@ -18,7 +18,7 @@ function printString(arg) {
18
18
  if (Array.isArray(arg)) {
19
19
  return `Array(${arg.length})`;
20
20
  }
21
- return arg.toString();
21
+ return String(arg);
22
22
  }
23
23
  function printFloat(arg) {
24
24
  if (typeof arg !== 'number')
@@ -57,6 +57,7 @@ function _getTarget(target) {
57
57
  if (tag === 'BUTTON' ||
58
58
  tag === 'A' ||
59
59
  tag === 'LI' ||
60
+ tag === 'SELECT' ||
60
61
  element.onclick != null ||
61
62
  element.getAttribute('role') === 'button' ||
62
63
  (0, utils_js_1.getLabelAttribute)(element) !== null) {
@@ -83,6 +84,7 @@ function default_1(app) {
83
84
  if (tag === 'BUTTON' ||
84
85
  tag === 'A' ||
85
86
  tag === 'LI' ||
87
+ tag === 'SELECT' ||
86
88
  target.onclick != null ||
87
89
  target.getAttribute('role') === 'button') {
88
90
  const label = app.sanitizer.getInnerTextSecure(target);
package/cjs/utils.d.ts CHANGED
@@ -3,14 +3,6 @@ export declare const stars: (str: string) => string;
3
3
  export declare function normSpaces(str: string): string;
4
4
  export declare function isURL(s: string): boolean;
5
5
  export declare const IN_BROWSER: boolean;
6
- export declare const log: {
7
- (...data: any[]): void;
8
- (message?: any, ...optionalParams: any[]): void;
9
- };
10
- export declare const warn: {
11
- (...data: any[]): void;
12
- (message?: any, ...optionalParams: any[]): void;
13
- };
14
6
  export declare const DOCS_HOST = "https://docs.openreplay.com";
15
7
  export declare function deprecationWarn(nameOfFeature: string, useInstead: string, docsPath?: string): void;
16
8
  export declare function getLabelAttribute(e: Element): string | null;
package/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.warn = exports.log = exports.IN_BROWSER = exports.isURL = exports.normSpaces = exports.stars = exports.timestamp = void 0;
3
+ exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.IN_BROWSER = exports.isURL = exports.normSpaces = exports.stars = exports.timestamp = void 0;
4
4
  function timestamp() {
5
5
  return Math.round(performance.now()) + performance.timing.navigationStart;
6
6
  }
@@ -18,15 +18,14 @@ function isURL(s) {
18
18
  }
19
19
  exports.isURL = isURL;
20
20
  exports.IN_BROWSER = !(typeof window === "undefined");
21
- exports.log = console.log;
22
- exports.warn = console.warn;
21
+ // TODO: JOIN IT WITH LOGGER somehow (use logging decorators?); Don't forget about index.js loggin when there is no logger instance.
23
22
  exports.DOCS_HOST = 'https://docs.openreplay.com';
24
23
  const warnedFeatures = {};
25
24
  function deprecationWarn(nameOfFeature, useInstead, docsPath = "/") {
26
25
  if (warnedFeatures[nameOfFeature]) {
27
26
  return;
28
27
  }
29
- (0, exports.warn)(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
28
+ console.warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
30
29
  warnedFeatures[nameOfFeature] = true;
31
30
  }
32
31
  exports.deprecationWarn = deprecationWarn;
@@ -2,14 +2,21 @@ import Message from "../messages/message.js";
2
2
  import Nodes from "./nodes.js";
3
3
  import Sanitizer from "./sanitizer.js";
4
4
  import Ticker from "./ticker.js";
5
+ import Logger from "./logger.js";
5
6
  import type { Options as ObserverOptions } from "./observer/top_observer.js";
6
7
  import type { Options as SanitizerOptions } from "./sanitizer.js";
8
+ import type { Options as LoggerOptions } from "./logger.js";
7
9
  import type { Options as WebworkerOptions } from "../messages/webworker.js";
8
10
  export interface OnStartInfo {
9
11
  sessionID: string;
10
12
  sessionToken: string;
11
13
  userUUID: string;
12
14
  }
15
+ export interface StartOptions {
16
+ userID?: string;
17
+ metadata?: Record<string, string>;
18
+ forceNew: boolean;
19
+ }
13
20
  declare type AppOptions = {
14
21
  revID: string;
15
22
  node_id: string;
@@ -19,20 +26,24 @@ declare type AppOptions = {
19
26
  local_uuid_key: string;
20
27
  ingestPoint: string;
21
28
  resourceBaseHref: string | null;
29
+ verbose: boolean;
22
30
  __is_snippet: boolean;
23
31
  __debug_report_edp: string | null;
24
- __debug_log: boolean;
32
+ __debug__?: LoggerOptions;
25
33
  onStart?: (info: OnStartInfo) => void;
26
34
  } & WebworkerOptions;
27
35
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
28
36
  declare type Callback = () => void;
29
37
  declare type CommitCallback = (messages: Array<Message>) => void;
38
+ export declare const CANCELED = "canceled";
30
39
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
31
40
  export default class App {
32
41
  readonly nodes: Nodes;
33
42
  readonly ticker: Ticker;
34
43
  readonly projectKey: string;
35
44
  readonly sanitizer: Sanitizer;
45
+ readonly debug: Logger;
46
+ readonly notify: Logger;
36
47
  private readonly messages;
37
48
  private readonly observer;
38
49
  private readonly startCallbacks;
@@ -41,19 +52,34 @@ export default class App {
41
52
  private readonly options;
42
53
  private readonly revID;
43
54
  private _sessionID;
44
- private isActive;
55
+ private _userID;
56
+ private _metadata;
57
+ private activityState;
45
58
  private version;
46
59
  private readonly worker?;
47
60
  constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
48
61
  private _debug;
62
+ private readonly preStartMessages;
49
63
  send(message: Message, urgent?: boolean): void;
50
64
  private commit;
51
65
  attachCommitCallback(cb: CommitCallback): void;
52
- addCommitCallback(cb: CommitCallback): void;
53
66
  safe<T extends (...args: any[]) => void>(fn: T): T;
54
67
  attachStartCallback(cb: Callback): void;
55
68
  attachStopCallback(cb: Callback): void;
56
69
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
70
+ checkRequiredVersion(version: string): boolean;
71
+ private getStartInfo;
72
+ getSessionInfo(): {
73
+ userUUID: string | null;
74
+ projectKey: string;
75
+ revID: string;
76
+ timestamp: number;
77
+ trackerVersion: string;
78
+ userID: string | null;
79
+ isSnippet: boolean;
80
+ sessionID: string | null;
81
+ metadata: Record<string, string>;
82
+ };
57
83
  getSessionToken(): string | undefined;
58
84
  getSessionID(): string | undefined;
59
85
  getHost(): string;
@@ -64,7 +90,7 @@ export default class App {
64
90
  active(): boolean;
65
91
  resetNextPageSession(flag: boolean): void;
66
92
  private _start;
67
- start(reset?: boolean): Promise<OnStartInfo>;
93
+ start(options?: StartOptions): Promise<OnStartInfo>;
68
94
  stop(): void;
69
95
  }
70
96
  export {};