Skip to content

Commit

Permalink
Analytics is always last
Browse files Browse the repository at this point in the history
  • Loading branch information
WesSouza committed Dec 15, 2024
1 parent 64609a5 commit f24b74b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Wes95/components/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const Explorer = () => {
width: 480,
height: 520,
},
skipAnalytics: true,
},
);
},
Expand Down
5 changes: 5 additions & 0 deletions src/Wes95/lib/SessionManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { collect } from '../../utils/plausible';
import type { WindowState } from '../models/WindowState';
import { ScreenManager } from './ScreenManager';
import { WindowManager } from './WindowManager';
Expand Down Expand Up @@ -129,6 +130,8 @@ export class SessionManager {

params.append('a', activeIndex.toString());

collect('Session Encoded');

return params.toString();
};

Expand Down Expand Up @@ -198,6 +201,8 @@ export class SessionManager {

if (windows.length === 0) {
options?.cleanState?.();
} else {
collect('Session Restored');
}

this.initialized = true;
Expand Down
15 changes: 11 additions & 4 deletions src/Wes95/lib/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { modifyById, modifyByIds } from '../utils/array';
import { clamp } from '../utils/size';
import { ScreenManager } from './ScreenManager';
import { collect } from '../../utils/plausible';

let shared: WindowManager | undefined;

Expand Down Expand Up @@ -86,6 +87,7 @@ export type WindowInit = Partial<
active?: boolean | undefined;
position?: Point | undefined;
size?: Partial<Size> | undefined;
skipAnalytics?: boolean;
};

export type WindowManagerState = {
Expand Down Expand Up @@ -171,10 +173,8 @@ export class WindowManager {

this.#windowInits.set(id, windowInit);

const [WindowContentComponent, WindowDataSchema] = parseWindowURL(
url,
this.windowLibrary,
);
const [WindowContentComponent, WindowDataSchema, windowURL] =
parseWindowURL(url, this.windowLibrary);

if (!WindowContentComponent) {
this.messageDialog({
Expand Down Expand Up @@ -208,6 +208,13 @@ export class WindowManager {
}),
);

if (!windowInit.skipAnalytics) {
collect('Application Opened', {
app:
windowURL.protocol + '//' + windowURL.hostname + windowURL.pathname,
});
}

return window;
};

Expand Down
3 changes: 3 additions & 0 deletions src/Wes95/lib/ding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { onCleanup, onMount } from 'solid-js';
import { WES95_MEDIA_PATH } from '../../config';
import { collect } from '../../utils/plausible';

export function createDinger() {
let buffer: AudioBuffer | undefined;
Expand Down Expand Up @@ -35,5 +36,7 @@ export function createDinger() {
source.buffer = buffer;
source.connect(context.destination);
source.start();

collect('Sound Played', { sound: 'Ding' });
};
}
7 changes: 7 additions & 0 deletions src/components/BaseHeadMeta.astro
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ const { title, description = '', image = '/images/OgImage.png' } = Astro.props;
data-domain={SITE_DOMAIN}
is:inline
src="https://plausible.io/js/plausible.js"></script>
<script>
window.plausible =
window.plausible ||
function () {
(window.plausible.q = window.plausible.q || []).push(arguments);
};
</script>
6 changes: 6 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />

interface Plausible {
(...args: any[]): void;
q: IArguments[];
}

interface Window {
onYouTubeIframeAPIReady: () => void;
plausible: Plausible;
}
5 changes: 5 additions & 0 deletions src/utils/plausible.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function collect(eventName: string, props: Record<string, any> = {}) {
try {
window.plausible?.(eventName, { props });
} catch (error) {}

Check failure on line 4 in src/utils/plausible.ts

View workflow job for this annotation

GitHub Actions / pnpm check

'error' is defined but never used. Allowed unused caught errors must match /^_/u

Check failure on line 4 in src/utils/plausible.ts

View workflow job for this annotation

GitHub Actions / pnpm check

Empty block statement
}

0 comments on commit f24b74b

Please sign in to comment.