Skip to content

Commit

Permalink
add app entry to gist events
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Jun 13, 2024
1 parent f8326f7 commit 7d05f8e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
25 changes: 14 additions & 11 deletions frontend/src/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { httpPostJSON } from "./httputil";

export let disableEvents = false;

/**
Expand Down Expand Up @@ -28,21 +26,26 @@ export function logEventRaw(o) {
});
}

export function logEvent(name, durMs = 0, meta = {}) {
export function logGistEvent(name, durMs = 0, o = {}) {
if (durMs > 0) {
meta.dur = durMs.toFixed(0);
o.dur = durMs.toFixed(0);
}
meta["name"] = name;
logEventRaw(meta);
logEventRaw({
app: "gist",
name: name,
...o,
});
}

export function logNpEvent(name, durMs = 0, meta = {}) {
export function logNpEvent(name, durMs = 0, o = {}) {
if (durMs > 0) {
meta.dur = durMs.toFixed(0);
o.dur = durMs.toFixed(0);
}
meta["app"] = "notepad2";
meta["name"] = name;
logEventRaw(meta);
logEventRaw({
app: "notepad2",
name: name,
...o,
});
}

export function logWcEvent(name, o = {}) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/gisteditor/EditorCodeMirror.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
refreshGistsForLoggedUser,
} from "./store.js";
import { ghtoken, getLoggedUser } from "../github_login.js";
import { logEvent } from "../events.js";
import { logGistEvent } from "../events.js";
import { goToGistById, goGistEditorHome } from "./router.js";
import Messages from "../Messages.svelte";
Expand Down Expand Up @@ -722,7 +722,7 @@
async function deleteLocal() {
// not logged directly in deleteLocalGist because
// deleteLocalGist is also called when saving local to github
logEvent("deleteLocalGist");
logGistEvent("deleteLocalGist");
await deleteLocalGist(gist.id);
location.href = "./";
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/gisteditor/GistLine.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { positionnode } from "../actions/positionnode.js";
import * as githubapi from "../githubapi.js";
import { deleteLocalGist, refreshGistsForLoggedUser } from "./store.js";
import { logEvent } from "../events.js";
import { logGistEvent } from "../events.js";
import { removeDescriptionAd } from "../util.js";
export let gist = {
Expand Down Expand Up @@ -35,7 +35,7 @@
async function deleteLocal() {
// not logged directly in deleteLocalGist because
// deleteLocalGist is also called when saving local to github
logEvent("deleteLocalGist");
logGistEvent("deleteLocalGist");
await deleteLocalGist(gist.id);
// window.goToURL("/home", "Home");
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/gisteditor/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { len, startTimer } from "../util.js";
// @ts-ignore
import Dexie from "https://esm.sh/dexie@3.2.3";
import { getLoggedUser } from "../github_login.js";
import { logEvent } from "../events.js";
import { logGistEvent } from "../events.js";
import { writable } from "svelte/store";

// localStorage key for gists
Expand Down Expand Up @@ -239,7 +239,7 @@ export async function getGistsForLoggedUser() {
fromCache: v.fromCache,
user: getLoggedUser(),
};
logEvent("getGistsForLoggedUser", elapsedFn(), meta);
logGistEvent("getGistsForLoggedUser", elapsedFn(), meta);
console.log(`getGistsForLoggedUser: ${len(gists)} in ${elapsedFn()} ms`);
return v;
}
Expand Down Expand Up @@ -445,7 +445,7 @@ export async function downloadGist(gistId) {
const meta = {
gistId: gistId,
};
logEvent("downloadGist", elapsedFn(), meta);
logGistEvent("downloadGist", elapsedFn(), meta);
return checkForError(gist);
}

Expand Down
6 changes: 4 additions & 2 deletions frontend/src/github_login.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as githubapi from "./githubapi.js";
import { get, writable } from "svelte/store";
import { getLocalStorageAsJSON, setLocalStorageFromJSON } from "./util.js";

import { logEvent } from "./events.js";
import { logEventRaw } from "./events.js";
import popup from "./popup.js";
import { showError } from "./Messages.svelte";

Expand Down Expand Up @@ -103,7 +103,9 @@ export function openLoginWindow() {

export function logout() {
// must log before clearing tokens to log user
logEvent("logout");
logEventRaw({
name: "logout",
});

localStorage.removeItem(keyGitHubToken);
setGitHubToken(null);
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/githubapi.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { showMessage, clearMessage, showError } from "./Messages.svelte";
import { clearMessage, showError, showMessage } from "./Messages.svelte";

import { getGitHubToken } from "./github_login";
import { logGistEvent } from "./events.js";
import { startTimer } from "./util.js";
import { logEvent } from "./events.js";

export function addHeader(opts, key, val) {
opts.headers = opts.headers || {};
Expand Down Expand Up @@ -187,7 +187,7 @@ export async function getGistsForUser(userID) {
const ev = {
user: userID,
};
logEvent("getGistsForUser", elapsedFn(), ev)
logGistEvent("getGistsForUser", elapsedFn(), ev)
console.log(`getGistsForUser: '${userID} ${len(gists)} in ${elapsedFn()} ms`);
return checkForError(gists);
}
Expand All @@ -213,7 +213,7 @@ export async function updateGist(gistId, data) {
const meta = {
gistId: gistId,
};
logEvent("updateGist", elapsedFn(), meta);
logGistEvent("updateGist", elapsedFn(), meta);
return checkForError(gist);
}

Expand All @@ -226,7 +226,7 @@ export async function createGist(gist) {
console.log("createGist:", gist);
showMessage(`creating a new gist`, 10000);
const res = await apiPost(`/gists`, gist);
logEvent("createGist", elapsedFn());
logGistEvent("createGist", elapsedFn());
return checkForError(res);
}

Expand All @@ -244,6 +244,6 @@ export async function deleteGist(gistId) {
const meta = {
gistId: gistId,
};
logEvent("deleteGist", elapsedFn(), meta);
logGistEvent("deleteGist", elapsedFn(), meta);
return ok;
}
2 changes: 1 addition & 1 deletion frontend/src/notepad2/Notepad2.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
} from "./np2store";
import Messages, { showError } from "../Messages.svelte";
import DialogSelectScheme from "./DialogSelectScheme.svelte";
import { logEventRaw, logNpEvent } from "../events";
import { logNpEvent } from "../events";
let toolbarFuncs;
Expand Down

0 comments on commit 7d05f8e

Please sign in to comment.