mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 08:46:15 -04:00
feat(plausible): disable plausible instance for self hosted instance
This commit is contained in:
parent
a599528044
commit
aa4dc0418e
2 changed files with 32 additions and 1 deletions
|
@ -29,6 +29,12 @@ export const config = figue({
|
|||
},
|
||||
},
|
||||
plausible: {
|
||||
isTrackerEnabled: {
|
||||
doc: 'Is the tracker enabled',
|
||||
format: 'boolean',
|
||||
default: false,
|
||||
env: 'VITE_TRACKER_ENABLED',
|
||||
},
|
||||
domain: {
|
||||
doc: 'Plausible current domain',
|
||||
format: 'string',
|
||||
|
|
|
@ -1,11 +1,36 @@
|
|||
import { config } from '@/config';
|
||||
import { noop } from 'lodash';
|
||||
|
||||
import Plausible from 'plausible-tracker';
|
||||
import type { App } from 'vue';
|
||||
|
||||
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 = Plausible(config.plausible);
|
||||
const plausible = createPlausibleInstance({ config: config.plausible });
|
||||
plausible.enableAutoPageviews();
|
||||
|
||||
app.provide('plausible', plausible);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue