simplify audio analytics

This commit is contained in:
adueck 2024-05-17 20:04:48 -04:00
parent 7b24fc381d
commit 3451115195
4 changed files with 10 additions and 22 deletions

View File

@ -15,7 +15,6 @@ function Entry({
textOptions,
nonClickable,
isolateEntry,
admin,
}: {
entry: T.DictionaryEntry;
textOptions: T.TextOptions;
@ -27,7 +26,7 @@ function Entry({
e: React.MouseEvent<HTMLElement, MouseEvent>
) {
e.stopPropagation();
playStorageAudio(entry.ts, entry.p, admin, () => null);
playStorageAudio(entry.ts, entry.p, () => null);
}
return (
<div

View File

@ -1,25 +1,19 @@
import { Types as T, InlinePs } from "@lingdocs/ps-react";
import { getAudioPath } from "./PlayStorageAudio";
import { LingdocsUser } from "../types/account-types";
import ReactGA from "react-ga4";
export function EntryAudioDisplay({
entry,
opts,
user,
}: {
entry: T.DictionaryEntry;
opts: T.TextOptions;
user: LingdocsUser | undefined;
}) {
const audioPath = getAudioPath(entry.ts);
if (!entry.a) {
return null;
}
function handlePlay() {
if (user && user.admin) {
return;
}
ReactGA.event({
category: "sounds",
action: `play ${entry.p} - ${entry.ts}`,
@ -27,12 +21,10 @@ export function EntryAudioDisplay({
}
function handleDownload() {
if (user && !user.admin) {
ReactGA.event({
category: "sounds",
action: `download ${entry.p} - ${entry.ts}`,
});
}
ReactGA.event({
category: "sounds",
action: `download ${entry.p} - ${entry.ts}`,
});
const documentName = `${entry.p}-${entry.ts}.mp3`;
fetch(audioPath)

View File

@ -7,16 +7,13 @@ export function getAudioPath(ts: number): string {
export default function playStorageAudio(
ts: number,
p: string,
admin: boolean,
callback: () => void
) {
if (!ts) return;
if (!admin) {
ReactGA.event({
category: "sounds",
action: `quick play ${p} - ${ts}`,
});
}
ReactGA.event({
category: "sounds",
action: `quick play ${p} - ${ts}`,
});
let audio = new Audio(getAudioPath(ts));
audio.addEventListener("ended", () => {
callback();

View File

@ -240,7 +240,7 @@ function IsolatedEntry({
</div>
</div>
</dl>
<EntryAudioDisplay entry={entry} opts={textOptions} user={state.user} />
<EntryAudioDisplay entry={entry} opts={textOptions} />
{wordlistWord && (
<>
{hasAttachment(wordlistWord, "audio") && (