,
This commit is contained in:
parent
70423851ba
commit
1fe5015056
55 changed files with 2036 additions and 685 deletions
69
src/analytics.ts
Normal file
69
src/analytics.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import {
|
||||
init as plausibleInit,
|
||||
track as plausibleTrack,
|
||||
type PlausibleEventOptions,
|
||||
} from '@plausible-analytics/tracker';
|
||||
|
||||
let isInitialized = false;
|
||||
|
||||
const track = (eventName: string, options: PlausibleEventOptions = {}) => {
|
||||
try {
|
||||
plausibleTrack(eventName, options);
|
||||
} catch (error) {
|
||||
console.warn(`Could not track analytics event "${eventName}".`, error);
|
||||
}
|
||||
};
|
||||
|
||||
export const initAnalytics = () => {
|
||||
if (isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
plausibleInit({
|
||||
domain: 'schmelczer.dev/floating',
|
||||
endpoint: 'https://stats.schmelczer.dev/status',
|
||||
autoCapturePageviews: true,
|
||||
captureOnLocalhost: true,
|
||||
logging: true,
|
||||
fileDownloads: true,
|
||||
outboundLinks: true,
|
||||
hashBasedRouting: true,
|
||||
});
|
||||
isInitialized = true;
|
||||
} catch (error) {
|
||||
console.warn('Could not initialize analytics.', error);
|
||||
}
|
||||
};
|
||||
|
||||
export const trackVibeChange = ({
|
||||
vibeId,
|
||||
vibeName,
|
||||
source,
|
||||
}: {
|
||||
vibeId: string;
|
||||
vibeName: string;
|
||||
source: string;
|
||||
}) => {
|
||||
track('Vibe Change', {
|
||||
props: {
|
||||
vibeId,
|
||||
vibeName,
|
||||
source,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const trackExport = ({ vibeId }: { vibeId: string }) => {
|
||||
track('Export', {
|
||||
props: {
|
||||
format: 'png',
|
||||
resolution: '4k',
|
||||
vibeId,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const trackSettingsOpen = () => {
|
||||
track('Settings Open');
|
||||
};
|
||||
Loading…
Reference in a new issue