From 7b3c480506833ccee8a544ec7873bae5f619a8e2 Mon Sep 17 00:00:00 2001 From: Bart Date: Fri, 2 Apr 2021 14:35:35 +0200 Subject: [PATCH] Add cloudflare web analytics --- .github/workflows/deploy_dev.yml | 4 +++- apps/blueprints/next.config.js | 3 ++- apps/blueprints/src/pages/_app.tsx | 9 ++++++++- apps/blueprints/src/utils/env.ts | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml index c47b12b..f9bdcbb 100644 --- a/.github/workflows/deploy_dev.yml +++ b/.github/workflows/deploy_dev.yml @@ -27,6 +27,8 @@ jobs: - run: yarn - run: yarn db-gen - run: yarn nx build blueprints + env: + CF_WEB_ANALYTICS: 6c563c1e5db141129a5fc95d5c459722 - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@master with: @@ -42,4 +44,4 @@ jobs: push: true tags: eu.gcr.io/factorio-sites/blueprints:dev - run: gsutil -h "Cache-Control:public, max-age=31536000" -m rsync -r -d ./dist/apps/blueprints/.next/static gs://factorio-blueprints-assets/dev/_next/static - - run: gcloud run deploy factorio-blueprints-dev --image=eu.gcr.io/factorio-sites/blueprints:dev --platform managed --region=europe-west4 --remove-env-vars PUBLIC_URL --update-env-vars ASSET_PREFIX=https://storage.googleapis.com/factorio-blueprints-assets/dev + - run: gcloud run deploy factorio-blueprints-dev --image=eu.gcr.io/factorio-sites/blueprints:dev --platform managed --region=europe-west4 --remove-env-vars PUBLIC_URL --update-env-vars ASSET_PREFIX=https://storage.googleapis.com/factorio-blueprints-assets/dev,CF_WEB_ANALYTICS=6c563c1e5db141129a5fc95d5c459722 diff --git a/apps/blueprints/next.config.js b/apps/blueprints/next.config.js index 52da61d..8c43b8c 100644 --- a/apps/blueprints/next.config.js +++ b/apps/blueprints/next.config.js @@ -8,7 +8,8 @@ module.exports = { reactStrictMode: true, assetPrefix: process.env.ASSET_PREFIX ? process.env.ASSET_PREFIX : "", publicRuntimeConfig: { - PUBLIC_URL: process.env.PUBLIC_URL || "", + PUBLIC_URL: process.env.PUBLIC_URL, + CF_WEB_ANALYTICS: process.env.CF_WEB_ANALYTICS, }, webpack(config, options) { const { dev, isServer } = options; diff --git a/apps/blueprints/src/pages/_app.tsx b/apps/blueprints/src/pages/_app.tsx index 76d0a04..13a92f1 100644 --- a/apps/blueprints/src/pages/_app.tsx +++ b/apps/blueprints/src/pages/_app.tsx @@ -9,7 +9,7 @@ import { getSessionToken } from "@factorio-sites/node-utils"; import { Header } from "../components/Header"; import { AuthContext, AuthContextProps } from "../providers/auth"; import { useFetch } from "../hooks/fetch"; -import { PUBLIC_URL } from "../utils/env"; +import { CF_WEB_ANALYTICS, PUBLIC_URL } from "../utils/env"; const globalStyles = css` @font-face { @@ -95,6 +95,13 @@ const BlueprintsApp = ({ )} + {CF_WEB_ANALYTICS && ( + + )} diff --git a/apps/blueprints/src/utils/env.ts b/apps/blueprints/src/utils/env.ts index aee97a3..e7c92bd 100644 --- a/apps/blueprints/src/utils/env.ts +++ b/apps/blueprints/src/utils/env.ts @@ -1,4 +1,5 @@ import getConfig from "next/config"; const { publicRuntimeConfig } = getConfig(); -export const PUBLIC_URL = publicRuntimeConfig.PUBLIC_URL as string; +export const PUBLIC_URL = (publicRuntimeConfig.PUBLIC_URL as string) || ""; +export const CF_WEB_ANALYTICS = (publicRuntimeConfig.CF_WEB_ANALYTICS as string) || null;