Skip to content

Commit

Permalink
Added plausible based on next config
Browse files Browse the repository at this point in the history
  • Loading branch information
dkildar committed Dec 9, 2024
1 parent ab96d0f commit cb79ad1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
5 changes: 3 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const withPWA = require("next-pwa")({
});
const appPackage = require("./package.json");
const { v4 } = require("uuid");
const { withPlausibleProxy } = require("next-plausible");

const config = {
productionBrowserSourceMaps: true,
Expand Down Expand Up @@ -149,5 +150,5 @@ const withSentry = withSentryConfig(config, {
});

/** @type {import('next').NextConfig} */
const nextWithPWA = withPWA(withSentry);
module.exports = process.env.NODE_ENV === "production" ? nextWithPWA : withSentry;
const prod = withPlausibleProxy()(withPWA(withSentry));
module.exports = process.env.NODE_ENV === "production" ? prod : withSentry;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"medium-zoom": "^1.1.0",
"moment": "^2.30.1",
"next": "15.0.2",
"next-plausible": "^3.12.4",
"next-pwa": "^5.6.0",
"numeral": "^2.0.6",
"path-to-regexp": "6.2.1",
Expand Down
2 changes: 1 addition & 1 deletion public/sw.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/sw.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { PropsWithChildren } from "react";
import { ClientProviders } from "@/app/client-providers";
import PlausibleProvider from "next-plausible";
import { EcencyConfigManager } from "@/config";

export default function Providers({ children }: PropsWithChildren) {
return <ClientProviders>{children}</ClientProviders>;
return (
<PlausibleProvider
domain={EcencyConfigManager.getConfigValue(
(config) => config.visionFeatures.analytics.plausible.domain
)}
>
<ClientProviders>{children}</ClientProviders>
</PlausibleProvider>
);
}
5 changes: 5 additions & 0 deletions src/config/config.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const CONFIG = {
}
},
visionFeatures: {
analytics: {
plausible: {
domain: "https://pl.ecency.com"
}
},
perks: {
enabled: true
},
Expand Down
5 changes: 5 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const CONFIG = {
}
},
visionFeatures: {
analytics: {
plausible: {
domain: "https://ecency.com"
}
},
perks: {
enabled: true
},
Expand Down
6 changes: 5 additions & 1 deletion src/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type { DefaultError } from "@tanstack/query-core";
export namespace EcencyConfigManager {
export const CONFIG = { ...config.visionConfig } as const;

export type ConfigBasedCondition = (config: typeof CONFIG) => boolean;
export type ConfigBasedCondition<T = boolean> = (config: typeof CONFIG) => T;

export function getConfigValue<T>(condition: ConfigBasedCondition<T>): T {
return condition(CONFIG);
}

export function withConditional<T>(condition: ConfigBasedCondition, callback: () => T) {
if (condition(CONFIG)) {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7171,6 +7171,11 @@ natural-compare@^1.4.0:
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==

next-plausible@^3.12.4:
version "3.12.4"
resolved "https://registry.yarnpkg.com/next-plausible/-/next-plausible-3.12.4.tgz#d0ac1d7dcbe9836b6c93e37d42b80e3661fdaa34"
integrity sha512-cD3+ixJxf8yBYvsideTxqli3fvrB7R4BXcvsNJz8Sm2X1QN039WfiXjCyNWkub4h5++rRs6fHhchUMnOuJokcg==

next-pwa@^5.6.0:
version "5.6.0"
resolved "https://registry.npmjs.org/next-pwa/-/next-pwa-5.6.0.tgz"
Expand Down

0 comments on commit cb79ad1

Please sign in to comment.