diff --git a/.env b/.env index f907cb85f8..a6b28343ce 100644 --- a/.env +++ b/.env @@ -2,4 +2,8 @@ BASE_API="https://api.storyteller.ai" GOOGLE_API="https://storage.googleapis.com" FUNNEL_API="https://style.storyteller.ai" CDN_API="https://cdn.storyteller.ai" -GRAVATAR_API="https://www.gravatar.com" \ No newline at end of file +GRAVATAR_API="https://www.gravatar.com" +DEPLOY_PRIME_URL="https://studio-staging.studio.storyteller.ai" +REACT_APP_PUBLIC_POSTHOG_KEY="phc_jBFgac0mVALAFk3negnSfYCcHgvkT00yBLQDmCDYNBb" +REACT_APP_PUBLIC_POSTHOG_UI="https://us.i.posthog.com" +CONTEXT="PRODUCTION" diff --git a/.env-local-proxy b/.env-local-proxy index 2478c54ee0..6366906887 100644 --- a/.env-local-proxy +++ b/.env-local-proxy @@ -2,4 +2,8 @@ BASE_API="http://localhost:3000" GOOGLE_API="http://localhost:3000/google" FUNNEL_API="http://localhost:3000/funnel" CDN_API="http://localhost:3000/cdn" -GRAVATAR_API="https://www.gravatar.com" \ No newline at end of file +GRAVATAR_API="https://www.gravatar.com" +DEPLOY_PRIME_URL="http://localhost:5173" +REACT_APP_PUBLIC_POSTHOG_KEY="phc_jBFgac0mVALAFk3negnSfYCcHgvkT00yBLQDmCDYNBb" +REACT_APP_PUBLIC_POSTHOG_UI="https://us.i.posthog.com" +CONTEXT="DEVELOPMENT" \ No newline at end of file diff --git a/.env-no-proxy b/.env-no-proxy index f907cb85f8..4767d588a0 100644 --- a/.env-no-proxy +++ b/.env-no-proxy @@ -2,4 +2,8 @@ BASE_API="https://api.storyteller.ai" GOOGLE_API="https://storage.googleapis.com" FUNNEL_API="https://style.storyteller.ai" CDN_API="https://cdn.storyteller.ai" -GRAVATAR_API="https://www.gravatar.com" \ No newline at end of file +GRAVATAR_API="https://www.gravatar.com" +DEPLOY_PRIME_URL="https://studio.storyteller.ai" +REACT_APP_PUBLIC_POSTHOG_KEY="phc_jBFgac0mVALAFk3negnSfYCcHgvkT00yBLQDmCDYNBb" +REACT_APP_PUBLIC_POSTHOG_UI="https://us.i.posthog.com" +CONTEXT="DEVELOPMENT" \ No newline at end of file diff --git a/README.md b/README.md index b9194db895..b38648c807 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,23 @@ npm install npm run dev ``` +## PostHog + +PostHog is installed and working. To create a feature flag go to https://us.posthog.com/project/75284/feature_flags +Add the feature flag for all users. + +To check the feature flag in the app use code similar to this + +```ts +const [myFlag, setMyFlag] = useState(false); +useEffect(() => { + const flag = posthog.isFeatureEnabled(""); + if (flag) { + setMyFlag(true); + } +}, []); +``` + ## Other Documentation Here is the Swagger documentation for the backend endpoints diff --git a/app/entry.client.tsx b/app/entry.client.tsx new file mode 100644 index 0000000000..dd1ccfcf2f --- /dev/null +++ b/app/entry.client.tsx @@ -0,0 +1,30 @@ +import { RemixBrowser } from "@remix-run/react"; +import { startTransition, StrictMode, useEffect } from "react"; +import { hydrateRoot } from "react-dom/client"; +import posthog from "posthog-js"; +import EnvironmentVariables from "~/Classes/EnvironmentVariables"; + +function PosthogInit() { + useEffect(() => { + const data = EnvironmentVariables.values; + + const apiKey = data.REACT_APP_PUBLIC_POSTHOG_KEY as string; + + posthog.init(apiKey, { + ui_host: data.DEPLOY_PRIME_URL as string, + api_host: data.REACT_APP_PUBLIC_POSTHOG_UI as string, + }); + }, []); + + return null; +} + +startTransition(() => { + hydrateRoot( + document, + + + + , + ); +}); diff --git a/app/pages/PageEnigma/PageEditor.tsx b/app/pages/PageEnigma/PageEditor.tsx index 0c55a66ac6..0c3305a3f1 100644 --- a/app/pages/PageEnigma/PageEditor.tsx +++ b/app/pages/PageEnigma/PageEditor.tsx @@ -82,17 +82,7 @@ export const PageEditor = () => { }; return ( -
- {/* - - */} +
; return { ENV: env }; } diff --git a/build-ci.sh b/build-ci.sh index b5436e5325..ff5ee081f6 100755 --- a/build-ci.sh +++ b/build-ci.sh @@ -49,9 +49,19 @@ find . -type f -exec sed -i "s${d}%BUILD_CDN_API%${d}${CDN_API}${d}g" {} + find . -type f -exec sed -i "s${d}%BUILD_UPLOAD_VIDEO%${d}${UPLOAD_VIDEO_API}${d}g" {} + find . -type f -exec sed -i "s${d}%BUILD_MEDIA_VIDEO%${d}${MEDIA_VIDEO_API}${d}g" {} + find . -type f -exec sed -i "s${d}%BUILD_GRAVATAR_VIDEO%${d}${GRAVATAR_API}${d}g" {} + +find . -type f -exec sed -i "s${d}%DEPLOY_PRIME_URL%${d}${DEPLOY_PRIME_URL}${d}g" {} + +find . -type f -exec sed -i "s${d}%CONTEXT%${d}${CONTEXT}${d}g" {} + + +# Replace Posthog env variables in the code +find . -type f -exec sed -i "s${d}%REACT_APP_PUBLIC_POSTHOG_KEY%${d}${REACT_APP_PUBLIC_POSTHOG_KEY}${d}g" {} + +find . -type f -exec sed -i "s${d}%REACT_APP_PUBLIC_POSTHOG_UI%${d}${REACT_APP_PUBLIC_POSTHOG_UI}${d}g" {} + # TODO: Run tests when we add them. -# Run build. +# Ensure the environment variables are exported +export REACT_APP_PUBLIC_POSTHOG_KEY +export REACT_APP_PUBLIC_POSTHOG_UI +export CONTEXT +# Run build.x npm run build diff --git a/netlify.toml b/netlify.toml index 52703a0246..9f44653c67 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,6 +2,10 @@ command = "./build-ci.sh" publish = "build/client" +[build.environment] +REACT_APP_PUBLIC_POSTHOG_KEY = "phc_jBFgac0mVALAFk3negnSfYCcHgvkT00yBLQDmCDYNBb" +REACT_APP_PUBLIC_POSTHOG_UI = "https://us.i.posthog.com" + [dev] command = "npm run dev" framework = "vite" @@ -14,3 +18,17 @@ for = "/build/*" [headers.values] "Cache-Control" = "public, max-age=31560000, immutable" + +[[redirects]] + from = "/ingest/static/*" + to = "https://us-assets.i.posthog.com/static/:splat" + host = "us-assets.i.posthog.com" + status = 200 + force = true + +[[redirects]] + from = "/ingest/*" + to = "https://us.i.posthog.com/:splat" + host = "us.i.posthog.com" + status = 200 + force = true diff --git a/package-lock.json b/package-lock.json index 18c0a4a146..cdb51e40ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "detect-gpu": "^5.0.38", "http-proxy-middleware": "^3.0.0", "isbot": "^4.1.0", + "posthog-js": "^1.141.0", "react": "^18.2.0", "react-copy-to-clipboard": "^5.1.0", "react-dom": "^18.2.0", @@ -19338,6 +19339,32 @@ "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz", "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" }, + "node_modules/posthog-js": { + "version": "1.141.0", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.141.0.tgz", + "integrity": "sha512-EuVCq86izPX7+1eD/o87lF1HalRD6Nk5735w+FKZJ5KAPwoQjr5FCaL2V8Ed36DyQQz4gQj+PEx5i6DFKCiDzA==", + "license": "MIT", + "dependencies": { + "fflate": "^0.4.8", + "preact": "^10.19.3" + } + }, + "node_modules/posthog-js/node_modules/fflate": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz", + "integrity": "sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==", + "license": "MIT" + }, + "node_modules/preact": { + "version": "10.22.0", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.22.0.tgz", + "integrity": "sha512-RRurnSjJPj4rp5K6XoP45Ui33ncb7e4H7WiOHVpjbkvqvA3U+N8Z6Qbo0AE6leGYBV66n8EhEaFixvIu3SkxFw==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/package.json b/package.json index ffd16d9ed2..121ec2100a 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "detect-gpu": "^5.0.38", "http-proxy-middleware": "^3.0.0", "isbot": "^4.1.0", + "posthog-js": "^1.141.0", "react": "^18.2.0", "react-copy-to-clipboard": "^5.1.0", "react-dom": "^18.2.0",