From 0189f99c3634782be410580b33484e85bc7511fc Mon Sep 17 00:00:00 2001 From: Kichiyaki Date: Sun, 7 Nov 2021 08:03:21 +0100 Subject: [PATCH] add and setup Plausible --- .github/workflows/publish.yml | 5 ++++- Dockerfile | 16 +++++++++++++-- next.config.js | 2 +- package.json | 1 + src/libs/plausible/PlausibleProvider.tsx | 25 ++++++++++++++++++++++++ src/pages/_app.tsx | 11 +++++++---- yarn.lock | 5 +++++ 7 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 src/libs/plausible/PlausibleProvider.tsx diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b0c46c2..2d1a583 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,13 +39,16 @@ jobs: with: context: . build-args: | - ENABLE_SENTRY_WEBPACK_PLUGIN=true + SENTRY_WEBPACK_PLUGIN_ENABLED=true SENTRY_URL=${{ secrets.SENTRY_URL }} SENTRY_ORG=${{ secrets.SENTRY_ORG }} SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }} SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_DSN=${{ secrets.SENTRY_DSN }} VERSION=v${{ steps.get_version.outputs.VERSION }} + PLAUSIBLE_ENABLED=true + PLAUSIBLE_DOMAIN=${{ secrets.PLAUSIBLE_DOMAIN }} + PLAUSIBLE_CUSTOM_DOMAIN=${{ secrets.PLAUSIBLE_CUSTOM_DOMAIN }} tags: | ${{ secrets.REGISTRY_NAME }}/zdam-egzamin-zawodowy-website:latest ${{ secrets.REGISTRY_NAME }}/zdam-egzamin-zawodowy-website:${{ steps.get_version.outputs.VERSION }} diff --git a/Dockerfile b/Dockerfile index 7125505..d6df22e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,16 +10,19 @@ RUN yarn install --frozen-lockfile FROM node:14.18.1-alpine AS builder ARG VERSION="v0.0.0" -ARG ENABLE_SENTRY_WEBPACK_PLUGIN="false" +ARG SENTRY_WEBPACK_PLUGIN_ENABLED="false" ARG SENTRY_URL="" ARG SENTRY_ORG="" ARG SENTRY_PROJECT="" ARG SENTRY_AUTH_TOKEN="" ARG SENTRY_DSN="" +ARG PLAUSIBLE_ENABLED="false" +ARG PLAUSIBLE_DOMAIN="" +ARG PLAUSIBLE_CUSTOM_DOMAIN="" WORKDIR /app -ENV ENABLE_SENTRY_WEBPACK_PLUGIN=$ENABLE_SENTRY_WEBPACK_PLUGIN \ +ENV SENTRY_WEBPACK_PLUGIN_ENABLED=$SENTRY_WEBPACK_PLUGIN_ENABLED \ SENTRY_URL=$SENTRY_URL \ SENTRY_ORG=$SENTRY_ORG \ SENTRY_PROJECT=$SENTRY_PROJECT \ @@ -27,6 +30,9 @@ ENV ENABLE_SENTRY_WEBPACK_PLUGIN=$ENABLE_SENTRY_WEBPACK_PLUGIN \ SENTRY_DSN=$SENTRY_DSN \ NEXT_PUBLIC_SENTRY_DSN=$SENTRY_DSN \ NEXT_PUBLIC_VERSION=$VERSION \ + NEXT_PUBLIC_PLAUSIBLE_ENABLED=$PLAUSIBLE_ENABLED \ + NEXT_PUBLIC_PLAUSIBLE_DOMAIN=$PLAUSIBLE_DOMAIN \ + NEXT_PUBLIC_PLAUSIBLE_CUSTOM_DOMAIN = $PLAUSIBLE_CUSTOM_DOMAIN \ BUILDING_PROCESS=true COPY . . @@ -41,12 +47,18 @@ WORKDIR /app ARG VERSION="v0.0.0" ARG SENTRY_DSN="" +ARG PLAUSIBLE_ENABLED="false" +ARG PLAUSIBLE_DOMAIN="" +ARG PLAUSIBLE_CUSTOM_DOMAIN="" ENV NODE_ENV=production \ SENTRY_DSN=$SENTRY_DSN \ NEXT_PUBLIC_SENTRY_DSN=$SENTRY_DSN \ VERSION=$VERSION \ NEXT_PUBLIC_VERSION=$VERSION \ + NEXT_PUBLIC_PLAUSIBLE_ENABLED=$PLAUSIBLE_ENABLED \ + NEXT_PUBLIC_PLAUSIBLE_DOMAIN=$PLAUSIBLE_DOMAIN \ + NEXT_PUBLIC_PLAUSIBLE_CUSTOM_DOMAIN = $PLAUSIBLE_CUSTOM_DOMAIN \ BUILDING_PROCESS=false COPY --from=builder /app/next.config.js ./ diff --git a/next.config.js b/next.config.js index 82947c6..59c8aa3 100644 --- a/next.config.js +++ b/next.config.js @@ -7,7 +7,7 @@ const CDN = process.env.NEXT_PUBLIC_CDN_URI const cfg = { sentry: { disableServerWebpackPlugin: - process.env.ENABLE_SENTRY_WEBPACK_PLUGIN !== 'true', + process.env.SENTRY_WEBPACK_PLUGIN_ENABLED !== 'true', get disableClientWebpackPlugin() { return this.disableServerWebpackPlugin; }, diff --git a/package.json b/package.json index 5ffd0f7..ed2ffc6 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "graphql-request": "^3.4.0", "lodash": "^4.17.21", "next": "12.0.3", + "next-plausible": "^3.1.3", "next-sitemap": "^1.6.25", "polish-plurals": "^1.1.0", "react": "17.0.2", diff --git a/src/libs/plausible/PlausibleProvider.tsx b/src/libs/plausible/PlausibleProvider.tsx new file mode 100644 index 0000000..b5fe3cd --- /dev/null +++ b/src/libs/plausible/PlausibleProvider.tsx @@ -0,0 +1,25 @@ +import React, { PropsWithChildren } from 'react'; +import PlausibleProvider from 'next-plausible'; + +type PlausibleProviderProps = PropsWithChildren< + Partial[0]> +>; + +const MyPlausibleProvider = ({ children, ...rest }: PlausibleProviderProps) => { + return ( + + {children} + + ); +}; + +export default MyPlausibleProvider; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 4173cb6..8299228 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,9 +1,10 @@ import '@kichiyaki/roboto'; import { useEffect } from 'react'; import { AppProps } from 'next/app'; +import PlausibleProvider from 'libs/plausible/PlausibleProvider'; import ThemeProvider from 'libs/material-ui/ThemeProvider'; -function MyApp({ Component, pageProps }: AppProps) { +const App = ({ Component, pageProps }: AppProps) => { useEffect(() => { const jssStyles = document.querySelector('#jss-server-side'); if (jssStyles && jssStyles.parentElement) { @@ -13,9 +14,11 @@ function MyApp({ Component, pageProps }: AppProps) { return ( - + + + ); -} +}; -export default MyApp; +export default App; diff --git a/yarn.lock b/yarn.lock index 78fa6f1..75367b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4700,6 +4700,11 @@ natural-compare@^1.4.0: resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= +next-plausible@^3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/next-plausible/-/next-plausible-3.1.3.tgz#7c798822a7d581270fc0e0cb430c60083bce5b8e" + integrity sha512-5e4jODgfF5sqL8E2HDrK8iWy1z67fFZJ4KsrbF+c0ZorhbqKl/kbocKESOWlelrl5gZpXIGb9Od2+XTuOUZAiA== + next-sitemap@^1.6.25: version "1.6.148" resolved "https://registry.yarnpkg.com/next-sitemap/-/next-sitemap-1.6.148.tgz#59ae167bd9317e8a285f586d9ceaab8bdf1817aa"