Merge pull request #5376 from matrix-org/t3chguy/countly
Fix countly method bindings and errors
This commit is contained in:
commit
0c6e597f4e
1 changed files with 22 additions and 5 deletions
|
@ -343,6 +343,18 @@ const getRoomStats = (roomId: string) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async wrapper for regex-powered String.prototype.replace
|
||||||
|
const strReplaceAsync = async (str: string, regex: RegExp, fn: (...args: string[]) => Promise<string>) => {
|
||||||
|
const promises: Promise<string>[] = [];
|
||||||
|
// dry-run to calculate the replace values
|
||||||
|
str.replace(regex, (...args: string[]) => {
|
||||||
|
promises.push(fn(...args));
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
const values = await Promise.all(promises);
|
||||||
|
return str.replace(regex, () => values.shift());
|
||||||
|
};
|
||||||
|
|
||||||
export default class CountlyAnalytics {
|
export default class CountlyAnalytics {
|
||||||
private baseUrl: URL = null;
|
private baseUrl: URL = null;
|
||||||
private appKey: string = null;
|
private appKey: string = null;
|
||||||
|
@ -495,7 +507,7 @@ export default class CountlyAnalytics {
|
||||||
return this.lastMsTs;
|
return this.lastMsTs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public recordError(err: Error | string, fatal = false) {
|
public async recordError(err: Error | string, fatal = false) {
|
||||||
if (this.disabled || this.anonymous) return;
|
if (this.disabled || this.anonymous) return;
|
||||||
|
|
||||||
let error = "";
|
let error = "";
|
||||||
|
@ -523,6 +535,11 @@ export default class CountlyAnalytics {
|
||||||
error = err + "";
|
error = err + "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sanitize the error from identifiers
|
||||||
|
error = await strReplaceAsync(error, /([!@+#]).+?:[\w:.]+/g, async (substring: string, glyph: string) => {
|
||||||
|
return glyph + await hashHex(substring.substring(1));
|
||||||
|
});
|
||||||
|
|
||||||
const metrics = this.getMetrics();
|
const metrics = this.getMetrics();
|
||||||
const ob: ICrash = {
|
const ob: ICrash = {
|
||||||
_resolution: metrics?._resolution,
|
_resolution: metrics?._resolution,
|
||||||
|
@ -666,11 +683,11 @@ export default class CountlyAnalytics {
|
||||||
return window.innerWidth > window.innerHeight ? Orientation.Landscape : Orientation.Portrait;
|
return window.innerWidth > window.innerHeight ? Orientation.Landscape : Orientation.Portrait;
|
||||||
};
|
};
|
||||||
|
|
||||||
private reportOrientation() {
|
private reportOrientation = () => {
|
||||||
this.track<IOrientationEvent>("[CLY]_orientation", {
|
this.track<IOrientationEvent>("[CLY]_orientation", {
|
||||||
mode: this.getOrientation(),
|
mode: this.getOrientation(),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
private startTime() {
|
private startTime() {
|
||||||
if (!this.trackTime) {
|
if (!this.trackTime) {
|
||||||
|
@ -754,7 +771,7 @@ export default class CountlyAnalytics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private endSession() {
|
private endSession = () => {
|
||||||
if (this.sessionStarted) {
|
if (this.sessionStarted) {
|
||||||
window.removeEventListener("resize", this.reportOrientation)
|
window.removeEventListener("resize", this.reportOrientation)
|
||||||
|
|
||||||
|
@ -765,7 +782,7 @@ export default class CountlyAnalytics {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.sessionStarted = false;
|
this.sessionStarted = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
private onVisibilityChange = () => {
|
private onVisibilityChange = () => {
|
||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
|
|
Loading…
Reference in a new issue