mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-08 06:29:03 +00:00
feat(telemetry): send weekly pings if enabled
This commit is contained in:
parent
3e379f44e8
commit
5a91e58104
6
bin.mjs
6
bin.mjs
@ -363,11 +363,11 @@ try {
|
||||
default:
|
||||
printHelp(commands, options);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (err) {
|
||||
stopSpinner();
|
||||
const message = error.message.split("\n")[0];
|
||||
const message = err.message.split("\n")[0];
|
||||
if (__debug) {
|
||||
print`{bold.red ${error.name}:} ${message}\n{grey ${error.stack
|
||||
print`{bold.red ${err.name}:} ${message}\n{grey ${err.stack
|
||||
.split("\n")
|
||||
.splice(1)
|
||||
.map((at) => at.replace(/\s{4}/g, " "))
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "notion-enhancer",
|
||||
"version": "0.11.1-dev",
|
||||
"version": "0.11.1",
|
||||
"author": "dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)",
|
||||
"description": "an enhancer/customiser for the all-in-one productivity workspace notion.so",
|
||||
"homepage": "https://notion-enhancer.github.io",
|
||||
|
@ -71,7 +71,8 @@ const initDatabase = (namespace, fallbacks = {}) => {
|
||||
init.run();
|
||||
|
||||
// schema:
|
||||
// - ("agreedToTerms") -> boolean
|
||||
// - ("agreedToTerms") -> string: semver
|
||||
// - ("lastTelemetryPing") -> string: iso
|
||||
// - ("telemetryEnabled") -> boolean
|
||||
// - ("profileIds") -> $profileId[]
|
||||
// - ("activeProfile") -> $profileId
|
||||
|
@ -24,7 +24,7 @@ function Telemetry() {
|
||||
platform: html`<code></code>`,
|
||||
version: html`<code></code>`,
|
||||
timezone: html`<code></code>`,
|
||||
enabledMods: html`<code></code>`,
|
||||
enabled_mods: html`<code></code>`,
|
||||
};
|
||||
useState(["rerender"], async () => {
|
||||
const telemetryData = await collectTelemetryData();
|
||||
@ -41,7 +41,7 @@ function Telemetry() {
|
||||
where the notion-enhancer is used. This data is anonymous and includes
|
||||
only your platform (${$.platform}), notion-enhancer version
|
||||
(${$.version}), timezone (${$.timezone}), and enabled mods
|
||||
(${$.enabledMods}). You can opt in or out of telemetry at any time. This
|
||||
(${$.enabled_mods}). You can opt in or out of telemetry at any time. This
|
||||
setting syncs across configuration profiles. For more information, read
|
||||
the notion-enhancer's
|
||||
<a href=${privacyPolicy} class="ml-[3px]">privacy policy</a>.`}
|
||||
|
@ -4,24 +4,42 @@
|
||||
* (https://notion-enhancer.github.io/) under the MIT license
|
||||
*/
|
||||
|
||||
const collectTelemetryData = async () => {
|
||||
const pingEndpoint = "https://notion-enhancer.deno.dev/api/ping",
|
||||
collectTelemetryData = async () => {
|
||||
const { platform, version } = globalThis.__enhancerApi,
|
||||
{ getMods, isEnabled } = globalThis.__enhancerApi,
|
||||
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
// prettier-ignore
|
||||
enabledMods = (await getMods(async (mod) => {
|
||||
enabled_mods = (await getMods(async (mod) => {
|
||||
if (mod._src === "core") return false;
|
||||
return await isEnabled(mod.id);
|
||||
})).map(mod => mod.id);
|
||||
return { platform, version, timezone, enabledMods };
|
||||
return { platform, version, timezone, enabled_mods };
|
||||
},
|
||||
sendTelemetryPing = async () => {
|
||||
const db = globalThis.__enhancerApi.initDatabase(),
|
||||
const db = __enhancerApi.initDatabase(),
|
||||
{ version } = globalThis.__enhancerApi,
|
||||
agreedToTerms = await db.get("agreedToTerms"),
|
||||
telemetryEnabled = (await db.get("telemetryEnabled")) ?? true;
|
||||
if (!telemetryEnabled || agreedToTerms !== version) return;
|
||||
// telemetry
|
||||
const telemetryData = await collectTelemetryData();
|
||||
|
||||
const lastTelemetryPing = await db.get("lastTelemetryPing");
|
||||
if (lastTelemetryPing) {
|
||||
const msSincePing = Date.now() - new Date(lastTelemetryPing);
|
||||
// send ping only once a week
|
||||
if (msSincePing / 8.64e7 < 7) return;
|
||||
}
|
||||
|
||||
try {
|
||||
const telemetryData = await collectTelemetryData(),
|
||||
pingTimestamp = await fetch(pingEndpoint, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(telemetryData),
|
||||
}).then((res) => res.text());
|
||||
await db.set("lastTelemetryPing", pingTimestamp);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
export { collectTelemetryData, sendTelemetryPing };
|
||||
|
Loading…
Reference in New Issue
Block a user