Posthog provider doesn't seem to work with railway

coderjoshdk
TRIAL

a year ago

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,
}
...

(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
        }
}

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

0 Replies

a year ago

so let me get this straight, this would be a network request the user's browser makes?


coderjoshdk
TRIAL

a year ago

Yea


a year ago

so basically the same kinda thing as calling Google analytics


coderjoshdk
TRIAL

a year ago

Yea. Basically. If you have never heard of posthog, it is an analytics tool. 100x better than google analytics.


a year ago

can you send a link to your site where it should be making a call to posthog or your ingest endpoint


coderjoshdk
TRIAL

a year 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.


a year ago

so is your frontend even making a call to /ingest as of right now?


coderjoshdk
TRIAL

a year ago

No. It does not seem to be


coderjoshdk
TRIAL

a year ago

Hmmmm. I actually wonder something <:hmmmm:419873765732777984>
Going to have to test out something later. I will report back later


a year ago

would it make a call to /ingest locally?


coderjoshdk
TRIAL

a year 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


a year ago

sounds good!


a year ago

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


coderjoshdk
TRIAL

a year 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


a year ago

The biggest thing I can't replicate, is the private network
sure you can! [http://127.0.0.1:3000](http://127.0.0.1:3000)


Posthog provider doesn't seem to work with railway - Railway Help Station