Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions projects/every-voice/src/lib/every-voice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ export class EveryVoiceService {
}
console.log("[DEBUG] Audio is playing");
this.status$.next({ id: audioId, status: "PLAYING" });
//opted into plausible
if ((window as any).plausible) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find where this .plausible variable gets initialized. How does this work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the plausible script is added to the index page it initialize itself into the global window namespace. The code is checking for that before attempting to generate the event.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if plausible is not defined at all, the fact that window has no plausible attribute just yields something undefined, which is falsish, unlike Python where that would raise an exception, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would yield undefined and so the code block would not execute since undefined is not 'truthy'

try {
const win = window;

(win as any).plausible(`Used TTS`, {
props: {},
});
} catch (err) {
console.error(err);
}
}
};

this.audioPlayer.onerror = (event) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class ConjugationService {
}
}
});
this.generatePlausibleEvent();
return conjugations.filter((x) =>
["option", "agent", "patient", "root"].every(
(k) =>
Expand All @@ -92,6 +93,8 @@ export class ConjugationService {
}

conjugate$(selection: TableviewerState | WordmakerState) {
this.generatePlausibleEvent();

return this.conjugations$.pipe(
map((conjugations) => this.filterConjugations(conjugations, selection))
);
Expand Down Expand Up @@ -139,4 +142,18 @@ export class ConjugationService {
});
return { structuredData, uniqueMain, uniqueCol, uniqueRow };
}
private generatePlausibleEvent(
eventName: string = "Conjugate",
eventProps: object = {}
) {
if ((window as any).plausible)
try {
const win = window;
(win as any).plausible(eventName, {
props: eventProps,
});
} catch (err) {
console.error(err);
}
}
}
Loading