swetrix 2.3.1 → 3.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/.prettierrc.js ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ printWidth: 120, // max 120 chars in line, code is easy to read
3
+ useTabs: false, // use spaces instead of tabs
4
+ tabWidth: 2, // "visual width" of of the "tab"
5
+ trailingComma: 'all', // add trailing commas in objects, arrays, etc.
6
+ semi: false, // Only add semicolons at the beginning of lines that may introduce ASI failures
7
+ singleQuote: true, // '' for stings instead of ""
8
+ bracketSpacing: true, // import { some } ... instead of import {some} ...
9
+ arrowParens: 'always', // braces even for single param in arrow functions (a) => { }
10
+ jsxSingleQuote: true, // '' for react props
11
+ bracketSameLine: false, // pretty JSX
12
+ endOfLine: 'lf', // 'lf' for linux, 'crlf' for windows, we need to use 'lf' for git
13
+ }
@@ -1,8 +1,8 @@
1
1
  export interface LibOptions {
2
2
  /**
3
- * When set to `true`, all tracking logs will be printed to console and localhost events will be sent to server.
3
+ * When set to `true`, localhost events will be sent to server.
4
4
  */
5
- debug?: boolean;
5
+ devMode?: boolean;
6
6
  /**
7
7
  * When set to `true`, the tracking library won't send any data to server.
8
8
  * Useful for development purposes when this value is set based on `.env` var.
@@ -25,6 +25,26 @@ export interface TrackEventOptions {
25
25
  [key: string]: string;
26
26
  };
27
27
  }
28
+ export interface IPageViewPayload {
29
+ lc: string | undefined;
30
+ tz: string | undefined;
31
+ ref: string | undefined;
32
+ so: string | undefined;
33
+ me: string | undefined;
34
+ ca: string | undefined;
35
+ pg: string;
36
+ prev: string | null | undefined;
37
+ }
38
+ interface IPerfPayload {
39
+ dns: number;
40
+ tls: number;
41
+ conn: number;
42
+ response: number;
43
+ render: number;
44
+ dom_load: number;
45
+ page_load: number;
46
+ ttfb: number;
47
+ }
28
48
  /**
29
49
  * The object returned by `trackPageViews()`, used to stop tracking pages.
30
50
  */
@@ -44,16 +64,25 @@ export interface PageViewsOptions {
44
64
  * This param is useful when tracking single-page landing websites.
45
65
  */
46
66
  unique?: boolean;
47
- /** A list of Regular Expressions or string pathes to ignore. */
48
- ignore?: Array<string | RegExp>;
49
- /** Do not send paths from ignore list to API. If set to `false`, the page view information will be sent to the Swetrix API, but the page will be displayed as a 'Redacted page' in the dashboard. */
50
- doNotAnonymise?: boolean;
51
- /** Do not send Heartbeat requests to the server. */
52
- noHeartbeat?: boolean;
53
67
  /** Send Heartbeat requests when the website tab is not active in the browser. */
54
68
  heartbeatOnBackground?: boolean;
55
- /** Disable user-flow */
56
- noUserFlow?: boolean;
69
+ /**
70
+ * Set to `true` to enable hash-based routing.
71
+ * For example if you have pages like /#/path or want to track pages like /path#hash
72
+ */
73
+ hash?: boolean;
74
+ /**
75
+ * Set to `true` to enable search-based routing.
76
+ * For example if you have pages like /path?search
77
+ */
78
+ search?: boolean;
79
+ /**
80
+ * Callback to edit / prevent sending pageviews.
81
+ *
82
+ * @param payload - The pageview payload.
83
+ * @returns The edited payload or `false` to prevent sending the pageview. If `true` is returned, the payload will be sent as-is.
84
+ */
85
+ callback?: (payload: IPageViewPayload) => IPageViewPayload | boolean;
57
86
  }
58
87
  export declare const defaultPageActions: {
59
88
  stop(): void;
@@ -68,13 +97,13 @@ export declare class Lib {
68
97
  constructor(projectID: string, options?: LibOptions | undefined);
69
98
  track(event: TrackEventOptions): void;
70
99
  trackPageViews(options?: PageViewsOptions): PageActions;
71
- getPerformanceStats(): object;
100
+ getPerformanceStats(): IPerfPayload | {};
72
101
  private heartbeat;
73
- private checkIgnore;
74
102
  private trackPathChange;
75
103
  private getPreviousPage;
76
104
  private trackPage;
77
- private debug;
105
+ submitPageView(pg: string, prev: string | null | undefined, unique: boolean, perf: IPerfPayload | {}, evokeCallback?: boolean): void;
78
106
  private canTrack;
79
107
  private sendRequest;
80
108
  }
109
+ export {};
@@ -19,6 +19,7 @@ export class Lib {
19
19
  return;
20
20
  }
21
21
  const data = {
22
+ ...event,
22
23
  pid: this.projectID,
23
24
  pg: this.activePage,
24
25
  lc: getLocale(),
@@ -27,7 +28,6 @@ export class Lib {
27
28
  so: getUTMSource(),
28
29
  me: getUTMMedium(),
29
30
  ca: getUTMCampaign(),
30
- ...event,
31
31
  };
32
32
  this.sendRequest('custom', data);
33
33
  }
@@ -39,15 +39,16 @@ export class Lib {
39
39
  return this.pageData.actions;
40
40
  }
41
41
  this.pageViewsOptions = options;
42
- let hbInterval, interval;
42
+ let interval;
43
43
  if (!options?.unique) {
44
44
  interval = setInterval(this.trackPathChange, 2000);
45
45
  }
46
- if (!options?.noHeartbeat) {
47
- setTimeout(this.heartbeat, 3000);
48
- hbInterval = setInterval(this.heartbeat, 28000);
49
- }
50
- const path = getPath();
46
+ setTimeout(this.heartbeat, 3000);
47
+ const hbInterval = setInterval(this.heartbeat, 28000);
48
+ const path = getPath({
49
+ hash: options?.hash,
50
+ search: options?.search,
51
+ });
51
52
  this.pageData = {
52
53
  path,
53
54
  actions: {
@@ -71,23 +72,17 @@ export class Lib {
71
72
  this.perfStatsCollected = true;
72
73
  return {
73
74
  // Network
74
- // @ts-ignore
75
- dns: perf.domainLookupEnd - perf.domainLookupStart,
76
- // @ts-ignore
77
- tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0,
78
- // @ts-ignore
79
- conn: perf.secureConnectionStart ? perf.secureConnectionStart - perf.connectStart : perf.connectEnd - perf.connectStart,
80
- // @ts-ignore
81
- response: perf.responseEnd - perf.responseStart,
75
+ dns: perf.domainLookupEnd - perf.domainLookupStart, // DNS Resolution
76
+ tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0, // TLS Setup; checking if secureConnectionStart is not 0 (it's 0 for non-https websites)
77
+ conn: perf.secureConnectionStart
78
+ ? perf.secureConnectionStart - perf.connectStart
79
+ : perf.connectEnd - perf.connectStart, // Connection time
80
+ response: perf.responseEnd - perf.responseStart, // Response Time (Download)
82
81
  // Frontend
83
- // @ts-ignore
84
- render: perf.domComplete - perf.domContentLoadedEventEnd,
85
- // @ts-ignore
86
- dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
87
- // @ts-ignore
88
- page_load: perf.loadEventStart,
82
+ render: perf.domComplete - perf.domContentLoadedEventEnd, // Browser rendering the HTML time
83
+ dom_load: perf.domContentLoadedEventEnd - perf.responseEnd, // DOM loading timing
84
+ page_load: perf.loadEventStart, // Page load time
89
85
  // Backend
90
- // @ts-ignore
91
86
  ttfb: perf.responseStart - perf.requestStart,
92
87
  };
93
88
  }
@@ -100,24 +95,14 @@ export class Lib {
100
95
  };
101
96
  this.sendRequest('hb', data);
102
97
  }
103
- checkIgnore(path) {
104
- const ignore = this.pageViewsOptions?.ignore;
105
- if (Array.isArray(ignore)) {
106
- for (let i = 0; i < ignore.length; ++i) {
107
- if (ignore[i] === path)
108
- return true;
109
- // @ts-ignore
110
- if (ignore[i] instanceof RegExp && ignore[i].test(path))
111
- return true;
112
- }
113
- }
114
- return false;
115
- }
116
98
  // Tracking path changes. If path changes -> calling this.trackPage method
117
99
  trackPathChange() {
118
100
  if (!this.pageData)
119
101
  return;
120
- const newPath = getPath();
102
+ const newPath = getPath({
103
+ hash: this.pageViewsOptions?.hash,
104
+ search: this.pageViewsOptions?.search,
105
+ });
121
106
  const { path } = this.pageData;
122
107
  if (path !== newPath) {
123
108
  this.trackPage(newPath, false);
@@ -127,11 +112,7 @@ export class Lib {
127
112
  // Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
128
113
  // That method of getting previous page works for SPA websites
129
114
  if (this.activePage) {
130
- const shouldIgnore = this.checkIgnore(this.activePage);
131
- if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
132
- return null;
133
- }
134
- return shouldIgnore ? null : this.activePage;
115
+ return this.activePage;
135
116
  }
136
117
  // Checking if URL is supported by the browser (for example, IE11 does not support it)
137
118
  if (typeof URL === 'function') {
@@ -147,11 +128,7 @@ export class Lib {
147
128
  if (host !== refHost) {
148
129
  return null;
149
130
  }
150
- const shouldIgnore = this.checkIgnore(pathname);
151
- if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise) {
152
- return null;
153
- }
154
- return shouldIgnore ? null : pathname;
131
+ return pathname;
155
132
  }
156
133
  catch {
157
134
  return null;
@@ -163,53 +140,45 @@ export class Lib {
163
140
  if (!this.pageData)
164
141
  return;
165
142
  this.pageData.path = pg;
166
- const shouldIgnore = this.checkIgnore(pg);
167
- if (shouldIgnore && this.pageViewsOptions?.doNotAnonymise)
168
- return;
169
143
  const perf = this.getPerformanceStats();
170
- let prev;
171
- if (!this.pageViewsOptions?.noUserFlow) {
172
- prev = this.getPreviousPage();
173
- }
174
- const data = {
144
+ const prev = this.getPreviousPage();
145
+ this.activePage = pg;
146
+ this.submitPageView(pg, prev, unique, perf, true);
147
+ }
148
+ submitPageView(pg, prev, unique, perf, evokeCallback) {
149
+ const privateData = {
175
150
  pid: this.projectID,
151
+ perf,
152
+ unique,
153
+ };
154
+ const pvPayload = {
176
155
  lc: getLocale(),
177
156
  tz: getTimezone(),
178
157
  ref: getReferrer(),
179
158
  so: getUTMSource(),
180
159
  me: getUTMMedium(),
181
160
  ca: getUTMCampaign(),
182
- unique,
183
- pg: shouldIgnore ? null : pg,
184
- perf,
161
+ pg,
185
162
  prev,
186
163
  };
187
- this.activePage = pg;
188
- this.sendRequest('', data);
189
- }
190
- debug(message) {
191
- if (this.options?.debug) {
192
- console.log('[Swetrix]', message);
164
+ if (evokeCallback && this.pageViewsOptions?.callback) {
165
+ const callbackResult = this.pageViewsOptions.callback(pvPayload);
166
+ if (callbackResult === false) {
167
+ return;
168
+ }
169
+ if (callbackResult && typeof callbackResult === 'object') {
170
+ Object.assign(pvPayload, callbackResult);
171
+ }
193
172
  }
173
+ Object.assign(pvPayload, privateData);
174
+ this.sendRequest('', pvPayload);
194
175
  }
195
176
  canTrack() {
196
- if (this.options?.disabled) {
197
- this.debug('Tracking disabled: the \'disabled\' setting is set to true.');
198
- return false;
199
- }
200
- if (!isInBrowser()) {
201
- this.debug('Tracking disabled: script does not run in browser environment.');
202
- return false;
203
- }
204
- if (this.options?.respectDNT && window.navigator?.doNotTrack === '1') {
205
- this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
206
- return false;
207
- }
208
- if (!this.options?.debug && isLocalhost()) {
209
- return false;
210
- }
211
- if (isAutomated()) {
212
- this.debug('Tracking disabled: navigation is automated by WebDriver.');
177
+ if (this.options?.disabled ||
178
+ !isInBrowser() ||
179
+ (this.options?.respectDNT && window.navigator?.doNotTrack === '1') ||
180
+ (!this.options?.devMode && isLocalhost()) ||
181
+ isAutomated()) {
213
182
  return false;
214
183
  }
215
184
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"Lib.js","sourceRoot":"","sources":["../../src/Lib.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAC1E,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,GACpD,MAAM,SAAS,CAAA;AA2EhB,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,KAAI,CAAC;CACV,CAAA;AAED,MAAM,gBAAgB,GAAG,6BAA6B,CAAA;AAEtD,MAAM,OAAO,GAAG;IAMd,YAAoB,SAAiB,EAAU,OAAoB;QAA/C,cAAS,GAAT,SAAS,CAAQ;QAAU,YAAO,GAAP,OAAO,CAAa;QAL3D,aAAQ,GAAoB,IAAI,CAAA;QAChC,qBAAgB,GAAwC,IAAI,CAAA;QAC5D,uBAAkB,GAAY,KAAK,CAAA;QACnC,eAAU,GAAkB,IAAI,CAAA;QAGtC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED,KAAK,CAAC,KAAwB;QAC5B,IAAI,CAAC,IAA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AE,MAAM,IAAI,gBAAgB,CAAA;QACrD,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAA;QAChC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;QACzC,GAAG,CAAC,gBAAgB,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;QACxD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAChC,CAAC;CACF"}
@@ -25,3 +25,13 @@ export declare function track(event: TrackEventOptions): void;
25
25
  * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
26
26
  */
27
27
  export declare function trackViews(options?: PageViewsOptions): Promise<PageActions>;
28
+ /**
29
+ * This function is used to manually track a page view event.
30
+ * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
31
+ *
32
+ * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
33
+ * @param prev Path of the previous page.
34
+ * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
35
+ * @returns void
36
+ */
37
+ export declare function trackPageview(path: string, prev?: string, unique?: boolean): void;
@@ -1,4 +1,4 @@
1
- import { Lib, defaultPageActions, } from './Lib';
1
+ import { Lib, defaultPageActions } from './Lib';
2
2
  export let LIB_INSTANCE = null;
3
3
  /**
4
4
  * Initialise the tracking library instance (other methods won't work if the library is not initialised).
@@ -51,4 +51,18 @@ export function trackViews(options) {
51
51
  }
52
52
  });
53
53
  }
54
+ /**
55
+ * This function is used to manually track a page view event.
56
+ * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
57
+ *
58
+ * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
59
+ * @param prev Path of the previous page.
60
+ * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
61
+ * @returns void
62
+ */
63
+ export function trackPageview(path, prev, unique) {
64
+ if (!LIB_INSTANCE)
65
+ return;
66
+ LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
67
+ }
54
68
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAAgE,kBAAkB,GACtF,MAAM,OAAO,CAAA;AAEd,MAAM,CAAC,IAAI,YAAY,GAAe,IAAI,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAC,GAAW,EAAE,OAAoB;IACpD,IAAI,CAAC,YAAY,EAAE;QACjB,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;KACrC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,KAAwB;IAC5C,IAAI,CAAC,YAAY;QAAE,OAAM;IAEzB,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO,CAAC,kBAAkB,CAAC,CAAA;YAC3B,OAAM;SACP;QAED,8GAA8G;QAC9G,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,CAAC,UAAU,KAAK,UAAU,EAAE;YACzE,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;SAC9C;aAAM;YACL,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;gBACnC,aAAa;gBACb,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;YAC/C,CAAC,CAAC,CAAA;SACH;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"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CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AACtE,CAAC"}
@@ -1,3 +1,7 @@
1
+ interface IGetPath {
2
+ hash?: boolean;
3
+ search?: boolean;
4
+ }
1
5
  export declare const isInBrowser: () => boolean;
2
6
  export declare const isLocalhost: () => boolean;
3
7
  export declare const isAutomated: () => boolean;
@@ -7,4 +11,19 @@ export declare const getReferrer: () => string | undefined;
7
11
  export declare const getUTMSource: () => string | undefined;
8
12
  export declare const getUTMMedium: () => string | undefined;
9
13
  export declare const getUTMCampaign: () => string | undefined;
10
- export declare const getPath: () => string;
14
+ /**
15
+ * Function used to track the current page (path) of the application.
16
+ * Will work in cases where the path looks like:
17
+ * - /path
18
+ * - /#/path
19
+ * - /path?search
20
+ * - /path?search#hash
21
+ * - /path#hash?search
22
+ *
23
+ * @param options - Options for the function.
24
+ * @param options.hash - Whether to trigger on hash change.
25
+ * @param options.search - Whether to trigger on search change.
26
+ * @returns The path of the current page.
27
+ */
28
+ export declare const getPath: (options: IGetPath) => string;
29
+ export {};
@@ -31,8 +31,32 @@ export const getReferrer = () => {
31
31
  export const getUTMSource = () => findInSearch(utmSourceRegex);
32
32
  export const getUTMMedium = () => findInSearch(utmMediumRegex);
33
33
  export const getUTMCampaign = () => findInSearch(utmCampaignRegex);
34
- export const getPath = () => {
35
- // TODO: Maybe we should also include such data as location.hash or location.search
36
- return location.pathname || '';
34
+ /**
35
+ * Function used to track the current page (path) of the application.
36
+ * Will work in cases where the path looks like:
37
+ * - /path
38
+ * - /#/path
39
+ * - /path?search
40
+ * - /path?search#hash
41
+ * - /path#hash?search
42
+ *
43
+ * @param options - Options for the function.
44
+ * @param options.hash - Whether to trigger on hash change.
45
+ * @param options.search - Whether to trigger on search change.
46
+ * @returns The path of the current page.
47
+ */
48
+ export const getPath = (options) => {
49
+ let result = location.pathname || '';
50
+ if (options.hash) {
51
+ const hashIndex = location.hash.indexOf('?');
52
+ const hashString = hashIndex > -1 ? location.hash.substring(0, hashIndex) : location.hash;
53
+ result += hashString;
54
+ }
55
+ if (options.search) {
56
+ const hashIndex = location.hash.indexOf('?');
57
+ const searchString = location.search || (hashIndex > -1 ? location.hash.substring(hashIndex) : '');
58
+ result += searchString;
59
+ }
60
+ return result;
37
61
  };
38
62
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,GAAW,EAAsB,EAAE;IACvD,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACtC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAA;AACrC,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,sCAAsC,CAAA;AAC7D,MAAM,gBAAgB,GAAG,6BAA6B,CAAA;AACtD,MAAM,cAAc,GAAG,2BAA2B,CAAA;AAElD,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,OAAO,OAAO,MAAM,KAAK,WAAW,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,OAAO,QAAQ,EAAE,QAAQ,KAAK,WAAW,IAAI,QAAQ,EAAE,QAAQ,KAAK,WAAW,IAAI,QAAQ,EAAE,QAAQ,KAAK,EAAE,CAAA;AAC9G,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,OAAO,SAAS,EAAE,SAAS,CAAA;AAC7B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,OAAO,OAAO,SAAS,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,C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