R
Railwayβ€’3w ago
Joshie

Posthog provider doesn't seem to work with railway

I have a frontend that uses posthog for its analytics. I used to have this whole project hosted elsewhere and everything worked perfectly. However, it does not seem to work on railway. I am defining my provider with
const options = {
api_host: "/ingest",
ui_host: import.meta.env.VITE_REACT_APP_PUBLIC_POSTHOG_HOST,
}
...
<PostHogProvider
apiKey={import.meta.env.VITE_REACT_APP_PUBLIC_POSTHOG_KEY}
options={options}
>
<RouterWithPosthog />
</PostHogProvider>
const options = {
api_host: "/ingest",
ui_host: import.meta.env.VITE_REACT_APP_PUBLIC_POSTHOG_HOST,
}
...
<PostHogProvider
apiKey={import.meta.env.VITE_REACT_APP_PUBLIC_POSTHOG_KEY}
options={options}
>
<RouterWithPosthog />
</PostHogProvider>
(this is React + Vite, setup very similar to the template; but not exaclty the same) What this should do, is send all analytic requests to posthog. But I don't see any requests being made in the network. Normally, I would then have
handle_path /ingest* {
rewrite * {path}
reverse_proxy https://us.i.posthog.com:443 {
header_up Host us.i.posthog.com
header_down -Access-Control-Allow-Origin
}
}
handle_path /ingest* {
rewrite * {path}
reverse_proxy https://us.i.posthog.com:443 {
header_up Host us.i.posthog.com
header_down -Access-Control-Allow-Origin
}
}
In a Caddyfile to actually handle that redirect. And this used to work. But it doesn't on railway. For some reason. I have tried to also not do this redirect thing btw, and just send request directly to posthog. However, it doesn't change anything. I have tried on both the new proxy and not. I have tried adding the handle_path to multiple locations (reverse proxy and frontend file server). I am not sure how to solve. Hopefully someone knows something that might help. And if not a direct tribal knowledge, at least tips on how to debug this would help πŸ˜„ project id: 1b326884-0c17-43ed-9b52-f443662e8f50
14 Replies
Percy
Percyβ€’3w ago
Project ID: 1b326884-0c17-43ed-9b52-f443662e8f50
Brody
Brodyβ€’3w ago
so let me get this straight, this would be a network request the user's browser makes?
Joshie
Joshieβ€’3w ago
Yea
Brody
Brodyβ€’3w ago
so basically the same kinda thing as calling Google analytics
Joshie
Joshieβ€’3w ago
Yea. Basically. If you have never heard of posthog, it is an analytics tool. 100x better than google analytics.
Brody
Brodyβ€’3w ago
can you send a link to your site where it should be making a call to posthog or your ingest endpoint
Joshie
Joshieβ€’3w ago
The site as a whole makes requests automagically. It was before I switched to railway. It triggers on events like loading a page or clicking a button. I mean you can add extra events and data. But there isn't any here. And there is also session replays. So simply being on the site, you should normally see regular outbound requests to /ingest. It would normally be to just us.posthog. Similar to how google analytics works. But it goes to /ingest to be able to be internally routed and prevent common analytic blocking. I did try to send the requests directly. But for some unknown (unknown to me) reason, posthog is just not trying to make any requests.
Brody
Brodyβ€’3w ago
so is your frontend even making a call to /ingest as of right now?
Joshie
Joshieβ€’3w ago
No. It does not seem to be Hmmmm. I actually wonder something :hmmmm: Going to have to test out something later. I will report back later
Brody
Brodyβ€’3w ago
would it make a call to /ingest locally?
Joshie
Joshieβ€’3w ago
Local as in CLI local? Or just local dev. Local dev, it does. But technically speaking, my local deploy is a different process (docker compose). So there are a few possible mixed wires going on. I have a few more rocks to flip over. If they all don't work, I will be back. But for now, I can try a few more things
Brody
Brodyβ€’3w ago
sounds good! best advice i can give would be to run your app locally as close as to how it would be ran on railway to see if you can reproduce locally
Joshie
Joshieβ€’3w ago
The biggest thing I can't replicate, is the private network. But yea, there are a few other little differnce between the two. So I will just bring down all of the debug stuff and see if actually makes a difference. But another thing I need to test, is environment variable stuff. Becuase I know these tools (Vite) can be picky sometimes. Although, like I said, it did used to work before. But, to be fair, railway wasn't the only change
Brody
Brodyβ€’3w ago
The biggest thing I can't replicate, is the private network
sure you can! http://127.0.0.1:3000