build: switch from yarn to npm to manage js dependencies and move js contents to root
yarn v1 is being deprecated and starts to have some issues Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
58
src/services/statistics/index.ts
Normal file
58
src/services/statistics/index.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { IAnalyticsConfig, IKeyValueConfig } from "@/types/config.model";
|
||||
|
||||
let app: any = null;
|
||||
|
||||
export const setAppForAnalytics = (newApp: any) => {
|
||||
app = newApp;
|
||||
};
|
||||
|
||||
export const statistics = async (
|
||||
configAnalytics: IAnalyticsConfig[],
|
||||
environement: any
|
||||
) => {
|
||||
console.debug("Loading statistics", configAnalytics);
|
||||
const matomoConfig = checkProviderConfig(configAnalytics, "matomo");
|
||||
if (matomoConfig?.enabled === true) {
|
||||
const { matomo } = (await import("./matomo")) as any;
|
||||
matomo({ ...environement, app }, convertConfig(matomoConfig.configuration));
|
||||
}
|
||||
|
||||
const sentryConfig = checkProviderConfig(configAnalytics, "sentry");
|
||||
if (sentryConfig?.enabled === true) {
|
||||
const { sentry } = (await import("./sentry")) as any;
|
||||
sentry({ ...environement, app }, convertConfig(sentryConfig.configuration));
|
||||
}
|
||||
};
|
||||
|
||||
export const checkProviderConfig = (
|
||||
configAnalytics: IAnalyticsConfig[],
|
||||
providerName: string
|
||||
): IAnalyticsConfig | undefined => {
|
||||
return configAnalytics?.find((provider) => provider.id === providerName);
|
||||
};
|
||||
|
||||
export const convertConfig = (
|
||||
configs: IKeyValueConfig[]
|
||||
): Record<string, any> => {
|
||||
return configs.reduce(
|
||||
(acc, config) => {
|
||||
acc[config.key] = toType(config.value, config.type);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, any>
|
||||
);
|
||||
};
|
||||
|
||||
const toType = (value: string, type: string): string | number | boolean => {
|
||||
switch (type) {
|
||||
case "boolean":
|
||||
return value === "true";
|
||||
case "integer":
|
||||
return parseInt(value, 10);
|
||||
case "float":
|
||||
return parseFloat(value);
|
||||
case "string":
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
14
src/services/statistics/matomo.ts
Normal file
14
src/services/statistics/matomo.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import VueMatomo from "vue-matomo";
|
||||
|
||||
export const matomo = (environment: any, matomoConfiguration: any) => {
|
||||
console.debug("Loading Matomo statistics");
|
||||
console.debug(
|
||||
"Calling VueMatomo with the following configuration",
|
||||
matomoConfiguration
|
||||
);
|
||||
environment.app.use(VueMatomo, {
|
||||
...matomoConfiguration,
|
||||
router: environment.router,
|
||||
debug: import.meta.env.DEV,
|
||||
});
|
||||
};
|
||||
9
src/services/statistics/plausible.ts
Normal file
9
src/services/statistics/plausible.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { VuePlausible } from "vue-plausible";
|
||||
export default (environment: any, plausibleConfiguration: any) => {
|
||||
console.debug("Loading Plausible statistics");
|
||||
|
||||
environment.app.use(VuePlausible, {
|
||||
// see configuration section
|
||||
...plausibleConfiguration,
|
||||
});
|
||||
};
|
||||
54
src/services/statistics/sentry.ts
Normal file
54
src/services/statistics/sentry.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as Sentry from "@sentry/vue";
|
||||
import { Integrations } from "@sentry/tracing";
|
||||
|
||||
export const sentry = (environment: any, sentryConfiguration: any) => {
|
||||
console.debug("Loading Sentry statistics");
|
||||
console.debug(
|
||||
"Calling Sentry with the following configuration",
|
||||
sentryConfiguration
|
||||
);
|
||||
// Don't attach errors to previous events
|
||||
window.sessionStorage.removeItem("lastEventId");
|
||||
Sentry.init({
|
||||
app: environment.app,
|
||||
dsn: sentryConfiguration.dsn,
|
||||
debug: import.meta.env.DEV,
|
||||
integrations: [
|
||||
new Integrations.BrowserTracing({
|
||||
routingInstrumentation: Sentry.vueRouterInstrumentation(
|
||||
environment.router
|
||||
),
|
||||
tracingOrigins: [window.origin, /^\//],
|
||||
}),
|
||||
],
|
||||
beforeSend(event) {
|
||||
// Check if it is an exception, and if so, save it in session storage
|
||||
// so that it can be retreived from the error component
|
||||
if (event.exception && event.event_id) {
|
||||
window.sessionStorage.setItem("lastEventId", event.event_id);
|
||||
}
|
||||
return event;
|
||||
},
|
||||
// Set tracesSampleRate to 1.0 to capture 100%
|
||||
// of transactions for performance monitoring.
|
||||
// We recommend adjusting this value in production
|
||||
tracesSampleRate: Number.parseFloat(sentryConfiguration.tracesSampleRate),
|
||||
release: environment.version,
|
||||
logErrors: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const submitFeedback = async (
|
||||
endpoint: string,
|
||||
dsn: string,
|
||||
params: Record<string, string>
|
||||
): Promise<void> => {
|
||||
await fetch(endpoint, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
Authorization: `DSN ${dsn}`,
|
||||
},
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user