From f5ceefa2ebc7ece7668bdcc66c288937fff957bf Mon Sep 17 00:00:00 2001 From: jffarge Date: Wed, 30 Mar 2022 15:34:10 +0200 Subject: [PATCH 1/3] website: add environment var to avoid crash issue signed-off-by: jffarge --- website/.env.example | 1 + 1 file changed, 1 insertion(+) create mode 100644 website/.env.example diff --git a/website/.env.example b/website/.env.example new file mode 100644 index 00000000..6bbcfa72 --- /dev/null +++ b/website/.env.example @@ -0,0 +1 @@ +REACT_APP_AMPLITUDE_ID= From fca6968bff84833c90beb0dc1ce2f7fdfdd75593 Mon Sep 17 00:00:00 2001 From: jffarge Date: Wed, 30 Mar 2022 15:59:53 +0200 Subject: [PATCH 2/3] fix: :adhesive_bandage: create a dev script with REACT_APP_AMPLITUDE_ID empty Signed-off-by: jffarge --- Makefile | 2 +- website/.env.example | 1 - website/package.json | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 website/.env.example diff --git a/Makefile b/Makefile index 4cf048ec..57121f67 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ mdlint: # Markdown lint for web .PHONY: web web: # Run the website locally yarn --cwd "./website" install - yarn --cwd "./website" start + yarn --cwd "./website" dev .PHONY: todo todo: # Find all TODO items diff --git a/website/.env.example b/website/.env.example deleted file mode 100644 index 6bbcfa72..00000000 --- a/website/.env.example +++ /dev/null @@ -1 +0,0 @@ -REACT_APP_AMPLITUDE_ID= diff --git a/website/package.json b/website/package.json index 69f527c4..2fc4683f 100644 --- a/website/package.json +++ b/website/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "docusaurus": "docusaurus", + "dev": "REACT_APP_AMPLITUDE_ID= docusaurus start", "start": "docusaurus start", "build": "docusaurus build", "swizzle": "docusaurus swizzle", From 8c9621e1373fe0d317983fbce500b778214dbee4 Mon Sep 17 00:00:00 2001 From: jffarge Date: Wed, 30 Mar 2022 16:48:24 +0200 Subject: [PATCH 3/3] fix: :adhesive_bandage: website: use docusaurus context Signed-off-by: jffarge --- Makefile | 2 +- website/docusaurus.config.js | 3 +++ website/package.json | 1 - website/src/theme/DocPage/index.js | 14 +++++++++----- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 57121f67..4cf048ec 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ mdlint: # Markdown lint for web .PHONY: web web: # Run the website locally yarn --cwd "./website" install - yarn --cwd "./website" dev + yarn --cwd "./website" start .PHONY: todo todo: # Find all TODO items diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 0ba89693..22640665 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -15,6 +15,9 @@ module.exports = { stylesheets: [ "https://fonts.googleapis.com/css2?family=Karla&family=Montserrat:wght@700&display=swap", ], + customFields: { + AMPLITUDE_ID: process.env.REACT_APP_AMPLITUDE_ID + }, themeConfig: { sidebarCollapsed: false, prism: { diff --git a/website/package.json b/website/package.json index 2fc4683f..69f527c4 100644 --- a/website/package.json +++ b/website/package.json @@ -4,7 +4,6 @@ "private": true, "scripts": { "docusaurus": "docusaurus", - "dev": "REACT_APP_AMPLITUDE_ID= docusaurus start", "start": "docusaurus start", "build": "docusaurus build", "swizzle": "docusaurus swizzle", diff --git a/website/src/theme/DocPage/index.js b/website/src/theme/DocPage/index.js index 0f0c6d60..f1e11606 100644 --- a/website/src/theme/DocPage/index.js +++ b/website/src/theme/DocPage/index.js @@ -7,6 +7,7 @@ import React, {useState, useEffect, useCallback} from 'react'; import {MDXProvider} from '@mdx-js/react'; import renderRoutes from '@docusaurus/renderRoutes'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import Layout from '@theme/Layout'; import DocSidebar from '@theme/DocSidebar'; import MDXComponents from '@theme/MDXComponents'; @@ -138,12 +139,15 @@ function DocPage(props) { matchPath(location.pathname, docRoute), ); - // DocPage Swizzle + // DocPage Swizzle + const {siteConfig} = useDocusaurusContext(); useEffect(() => { - var instance1 = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, null, { - apiEndpoint: `${window.location.hostname}/t` - }) - amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname }); + if(siteConfig.AMPLITUDE_ID) { + var instance1 = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, null, { + apiEndpoint: `${window.location.hostname}/t` + }) + amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname }); + } }, [location.pathname]) // End DocPageSwizzle