mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-10 16:15:01 -04:00
38 lines
833 B
TypeScript
38 lines
833 B
TypeScript
import { noop } from 'lodash';
|
|
|
|
import Plausible from 'plausible-tracker';
|
|
import type { App } from 'vue';
|
|
import { config } from '@/config';
|
|
|
|
function createFakePlausibleInstance(): Pick<ReturnType<typeof Plausible>, 'trackEvent' | 'enableAutoPageviews'> {
|
|
return {
|
|
trackEvent: noop,
|
|
enableAutoPageviews: () => noop,
|
|
};
|
|
}
|
|
|
|
function createPlausibleInstance({
|
|
config,
|
|
}: {
|
|
config: {
|
|
isTrackerEnabled: boolean
|
|
domain: string
|
|
apiHost: string
|
|
trackLocalhost: boolean
|
|
}
|
|
}) {
|
|
if (config.isTrackerEnabled) {
|
|
return Plausible(config);
|
|
}
|
|
|
|
return createFakePlausibleInstance();
|
|
}
|
|
|
|
export const plausible = {
|
|
install: (app: App) => {
|
|
const plausible = createPlausibleInstance({ config: config.plausible });
|
|
plausible.enableAutoPageviews();
|
|
|
|
app.provide('plausible', plausible);
|
|
},
|
|
};
|