mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-10 20:11:49 +00:00
Posthog (#551)
Co-authored-by: Ishaan Shrivastava <ishaan@storyteller.ai> Co-authored-by: Christopher Oliphant <christopheroliphant@christophersmbp.home> Co-authored-by: ArEnSc <6252325+ArEnSc@users.noreply.github.com>
This commit is contained in:
11 files changed
+132
-15
No files matched your search
@@ -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"
|
||||
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"
|
||||
+5
-1
@@ -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"
|
||||
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"
|
||||
+5
-1
@@ -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"
|
||||
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"
|
||||
@@ -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("<flag name>");
|
||||
if (flag) {
|
||||
setMyFlag(true);
|
||||
}
|
||||
}, []);
|
||||
```
|
||||
|
||||
## Other Documentation
|
||||
|
||||
Here is the Swagger documentation for the backend endpoints
|
||||
|
||||
@@ -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,
|
||||
<StrictMode>
|
||||
<RemixBrowser />
|
||||
<PosthogInit />
|
||||
</StrictMode>,
|
||||
);
|
||||
});
|
||||
@@ -82,17 +82,7 @@ export const PageEditor = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-screen" data-sl="canvas-mq">
|
||||
{/* <Helmet>
|
||||
<script type="text/javascript">{`
|
||||
window.smartlook||(function(d) {
|
||||
var o=smartlook=function(){ o.api.push(arguments)},h=d.getElementsByTagName('head')[0];
|
||||
var c=d.createElement('script');o.api=new Array();c.async=true;c.type='text/javascript';
|
||||
c.charset='utf-8';c.src='https://web-sdk.smartlook.com/recorder.js';h.appendChild(c);
|
||||
})(document);
|
||||
smartlook('init', '3d1ddaf51ab1fa28ffe0b2bd94aa0e233bb0fd9e', { region: 'eu' });
|
||||
`}</script>
|
||||
</Helmet> */}
|
||||
<div className="w-screen">
|
||||
<TopBar pageName="Edit Scene" />
|
||||
<div
|
||||
className="relative flex w-screen"
|
||||
|
||||
@@ -78,6 +78,18 @@ export async function loader() {
|
||||
CDN_API: process.env.CDN_API || "%BUILD_CDN_API%",
|
||||
// @ts-expect-error ProvessEnv is correct
|
||||
GRAVATAR_API: process.env.GRAVATAR_API || "%BUILD_GRAVATAR_API%",
|
||||
// @ts-expect-error ProvessEnv is correct
|
||||
DEPLOY_PRIME_URL: process.env.DEPLOY_PRIME_URL || "%DEPLOY_PRIME_URL%",
|
||||
REACT_APP_PUBLIC_POSTHOG_KEY:
|
||||
// @ts-expect-error ProvessEnv is correct
|
||||
process.env.REACT_APP_PUBLIC_POSTHOG_KEY ||
|
||||
"%REACT_APP_PUBLIC_POSTHOG_KEY%",
|
||||
REACT_APP_PUBLIC_POSTHOG_UI:
|
||||
// @ts-expect-error ProvessEnv is correct
|
||||
process.env.REACT_APP_PUBLIC_POSTHOG_UI ||
|
||||
"%REACT_APP_PUBLIC_POSTHOG_UI%",
|
||||
// @ts-expect-error ProvessEnv is correct
|
||||
CONTEXT: process.env.CONTEXT || "%CONTEXT%",
|
||||
} as Record<string, string | boolean>;
|
||||
return { ENV: env };
|
||||
}
|
||||
|
||||
+11
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
Generated
+27
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user