Post Dog, the company with a ridiculously cute little mascot and what I would probably say is the probably the best website in the world. I mean, I personally love it. I mean, just look at this. Who said that modern website design is dead? Hey, anyways, I love them and everything they do. Whether that's making sense of gobs of analytics data or recording your log traffic or managing feature flags or even collecting survey traffic for you, they do it with such class and userfriendly cuteness that it's hard not to love them. Well, my love is about to turn into stalkerish adoration because they just dropped a convex component to go along with their logream and error reporting integration. So, in this video, we're going to do a deep dive and have a look and see whether my wife has got anything to be concerned about or not. So, make sure you grab yourself a lovely cup of tea, drop me a like and sub, and we're going to get into it. So, firstly, there are two main ways to integrate Convex into post hog depending upon what you're trying to do really. So, if you want like a highlevel overview of your convex infrastructure, what you what functions being run and like how long they're going to take to run and what kind of errors you're getting, etc., What you want is the logream and error reporting integration. If you want a more detailed product level event uh like a user clicked on a thing or you know a user just bought something then what you're going to want is the post hog convex component. But as the uh log stream and error reporting integration doesn't take any code to get started. Let's uh let's take a look at that one first. So before we get started, the first thing you need to know is that to be able to use log streaming, which is what we call a convex integration. Then you need to have a paid plan of some sort. You don't need a paid plan for the post hog component. So just stick around if you want that. But uh for this part, you're going to need a convex paid plan. Okay. So for this demo, this project I've built here is a basic canban style to-do app. You can create cards and move them around these different statuses like this. Um, you can click one and add a description or you can add comments. It's pretty basic stuff, but that's okay because the app doesn't really matter for this demo. But what does matter is let's open up the Convex dashboard. Uh, my favorite way to do this is with npx convex dash. And from there we can go to the settings and integration section. And then we can press the little plus icon here to enable the log streaming integration for Post Hog. Now it's this pop-up says it's going to want a project token. So we need to get that from the Post Hog dashboard. Side note, man, I wish this was all doable via agent. You know, I think maybe I'm getting spoiled with agents, but I wish I could just say just hook these two things together, please, and and it would just make it work. But anyway, it's for now we can't do that, unfortunately. But anyways, we can grab the token manually from the post hog dashboard here and then pop it into the field uh in the comics dashboard here. And while we're at it, we might as well enable the post error tracking here as well by pasting in the same uh project token here. There we go. Okay. And now if we return back to our app and we do some stuff like move some cards around, um add a comment here. Uh maybe we type something in this and obviously an error. Um, yep, we get an error. Now, when we pop back to the post dashboard, we should see some logs. And huzzah, we do. And we can click one of the logs here. And we can see that the topic is function executed, and the path was comments list by card. Now, there's a heap of other interesting information here. And I guess you could go ahead and create dashboards or you could chat to the Post Hog AI and make dashboards for you if you'd like. Oh, but we should probably just go and have a look and make sure that the errors are coming through as well. So, let's go to the apps and then error tracking feature. And then bam, there we go. We can see our is error hedgehogs are great called from the convex/ comments.ts line 35, which is very nice. All right, so now that we have our logs and errors streaming into Post Hog, what else can these lovely little hogs offer us? All right. Well, to take our relationship to the next level, we're going to need the brand new post hog convex component. This component is going to let us capture events from within our convex functions rather than just from the high level outside of it. Um, and it's going to allow us to, you know, capture things like it shows here the user created event or allows us to use feature flags, which is a post hog feature, uh, like this discount campaign flag right here. Okay. Can you add the convex post component to this project please? And then can you sprinkle in some um event capturing in our mutations and can you add the feature flag as well so that I can add that add a feature from the post hog dashboard. And while you're doing all this I will set up the environment variables. So, while my agent is hacking away on that, let's open up a terminal and type uh npx convex env set post hog API key and press enter. And then we enter our post hog token from before. And then we might as well set the host as well, which I think will default to us anyway, but whatever. All right. Now, we're just going to wait for the agent to finish. A few minutes later. Okay, it's done. So if we open up the code here, we can see that it's added our post hog component here, which is nice. And it's gone ahead and sprinkled some of these post hog. Calls in our mutations also, which is very nice. So let's give this a shot. So if I open up the app and then I add a card. Okay. And then I add some comments in here. It doesn't really matter what they are. And then I'll hop back over to the Post Hog dash. And we open up the product analytics feature. Cool. Oh, there we go. We can see our new events are here on the right hand side. And if I click it, I get a bunch more info as you might expect. Um, and I guess I could create the dashboards from here as well, um, and whatnot, which is very nice. Okay, now if we go back to the code a sec, I saw that the agent also created this feature flags.ts file in the comics directory, which is an action that calls the post component again to check whether a feature flag has been enabled or not. And if we just trace where it's being used on the front end, we can see if it's being used in this use feature flag react hook um which is then being also in turn used from the board list component which shows um a welcome banner if the welcome banner feature is set. So let's go open up the feature flag section in Post Hog and create a new feature flag called welcome banner and set it to enabled. And then let's open up the app to the board view and refresh it. And bam, there we go. we get a nice little welcome banner at the top here. And just to make sure that this is definitely working, let's open up the feature flag again. And then let's set it back to false. And then we'll go back to the app. And oh, oh yeah, cuz it's an action, we have to refresh the page. And that there we go. It uh disappears. Nice. Now, I would like to have seen this as a query rather than an action because then I wouldn't have to have refreshed the page because of convex, you know, just automatically syncs. Uh maybe that's something that Postto can work on in a future version of the component. Hi, Mike from the future here. So after I got filming, I realized I've missed something out. I missed out a very important new feature of Convex plus Post Hog, and it is this Post Hog AI analytics. So what we can do with this is uh we can actually get some analytics uh back from what the LLM is doing or the agent is doing inside of our app which is obviously incredibly valuable information. So the way we get started with this is we just install a few dependencies here. here the postto AI AI SDK and some open telemetry bits and pieces and then we can set our Postto environment variables if we haven't done that already from uh various other Postto integration bits and pieces but our post API key and uh we also obviously will need to set an AI API key of some sort and then to get started we just pull in a we create a provider which is just a a basically a provider from the open telemetry um SDK which if you've done any open open telemetry stuff in the past before this should be familiar clear to you and then we create a span processor and a post hog trace exporter passing in our API key and our host and then we just um set it as a global trace provider and then when we come to actually use the AI SDK the generate text part we set this experimental telemetry section and we just set it to be enabled and a couple of other bits and pieces and then that's all it is and then basically information I'll just tra get sent to uh post hog and we can see traces latency token usage cost etc. which is obviously incredibly useful information. Now, if you are an absolute uh badass and using the convex agent component instead of the raw AI SDK stuff, there is a handy dandy little tutorial here um using the convex agent which is basically the same thing. We set up the provider. We set up the the global trace provider. And then uh instead of uh the experimental section being in the raw generate text, it's now on the thread generate text and we have this experimental telemetry section because basically the convex agent is using the AI SDK under underneath the hood. So it's kind of similar. And that's about all there is to it. I think this is just a really excellent product and I'm really happy to see this. So uh make sure you uh think about this one next time you build an agent on Convex. Right. Well, that's just a short one for me for today. I have got to say I'm super impressed with Post Hog as always and really happy to see them integrated with Convex like this. I'm excited to see them flesh out the component a little bit more. Maybe add more capabilities and features given the large and ever expanding feature footprint of Post Hog. It'd be nice to see that component fleshed out a bit more as well. But for now, I'm just going to leave it here, I think. I hope you enjoyed this video. And if you did, don't forget to drop me a like and sub down below. And maybe even drop a little cheeky hedgehog related comment for the post crew. But until next time, thanks for watching. Cheerio.
If you're building on Convex and want to understand how your app behaves in production, a PostHog Convex integration gives you two complementary ways to get there. One path captures infrastructure-level signals like which functions ran and what broke, while the other captures product-level events like a user clicking a button or completing a purchase. This guide walks through both, plus a bonus path for tracking AI and LLM analytics, so you can wire PostHog into your Convex backend with a clear sense of which method fits your needs.
I've set both up, and the honest takeaway is that they solve different problems. Once you see the fork clearly, the rest of the setup is mostly mechanical. Neither path is hard on its own, but choosing the wrong one first wastes an afternoon, so the most valuable thing I can do here is help you pick correctly before you touch anything.
PostHog logs page
The Two Ways to Integrate PostHog With Convex
There are two distinct ways to connect PostHog to Convex:
Log streaming and error reporting integration: An infrastructure-level integration that reports which functions run, how long they take, and what errors occur.
The PostHog Convex component: A code-level Convex component that captures product-level events from inside your functions and gives you access to feature flags.
Which one you reach for depends entirely on what you're trying to see. If you want observability into your backend's health and behavior, the log streaming integration answers that. If you want to know what your users are doing, the PostHog component is the right tool. Establishing this fork up front saves you from setting up the wrong path and wondering why the data looks different from what you expected.
These two aren't mutually exclusive, and most production apps end up running both. The point of separating them here is not to make you choose one forever, but to make sure you understand which problem each one solves before you wire it in. When the log stream tells you a function is throwing errors, that's a different signal from the component telling you that users stopped completing a checkout flow, and you want both signals reaching PostHog so you can correlate them.
One practical constraint shapes this decision. Log streaming requires a paid Convex plan, whereas the PostHog Convex component doesn't. So if you're on a free plan and want to start capturing product events today, the component is your entry point. That single constraint often decides the order of operations for new projects, because there's no reason to wait on a paid plan when the component can start recording meaningful events from inside your mutations immediately.
Setting Up PostHog Log Streaming and Error Reporting
You set up PostHog log streaming and error reporting entirely from the Convex dashboard, with no code required. You enable the integration, paste in a PostHog project token, and then verify that logs and errors arrive in your PostHog database. This is the fastest win because you can validate it works before touching your codebase, which means you get a confidence boost early without committing any changes to your functions.
This path appeals as a starting point because it asks nothing of your application logic. You're not adding capture calls, reasoning about which events matter, or refactoring mutations. You're flipping a switch in a dashboard and watching data flow, so the feedback loop is tight and the risk is close to zero.
Enabling the Integration in the Convex Dashboard
Open your dashboard by running npx convex dashboard in your terminal.
Navigate to Settings, then Integrations.
Look for the plus icon to enable PostHog log streaming.
When prompted, enter a PostHog project token to complete the connection.
This is the entire interface for the infrastructure-level path, which is a deliberate design choice. Because the integration lives in the dashboard rather than in your code, you can enable, disable, or reconfigure it without redeploying anything, so iterating on what you stream costs nothing in deployment time.
Adding Your PostHog Project Token
Grab the project token from your PostHog dashboard and paste it into the Convex integration field. The same token enables error tracking, so you don't need a second credential for that. Once the token is saved, the connection is live.
This single-token arrangement is convenient because error reporting and log streaming are often treated as separate setups in other stacks, each demanding its own configuration. Here they share one credential, which means enabling logs automatically lets you catch errors without any extra wiring, and that reduces the number of places a misconfiguration can hide.
Verifying Logs and Errors Arrive
Trigger some activity in your app to generate function executions. In PostHog, confirm that the function executed topic appears with the function path attached, which tells you the log stream is flowing. To verify error tracking, throw an error and check that it surfaces in PostHog with the originating file and line number, so you can trace exactly where a failure happened.
That file and line number is the detail worth dwelling on. An error report that only tells you something broke is mildly useful, whereas one that points you to the exact file and line turns a debugging session into a direct lookup. I rely on this more than I expected to, because it collapses the gap between noticing a failure in production and locating its source in the codebase.
Installing the PostHog Convex Component
The PostHog Convex component lets you capture events from inside your Convex functions rather than only from the client, and it gives you access to feature flags. You install it, set two environment variables, and then add capture calls inside your mutations, all of which PostHog's Convex library docs walk through in detail. This is the granular, product-level path that most analytics use cases need.
Capturing events server-side rather than client-side matters more than it first appears. Client-side analytics can be blocked, dropped, or skipped when a browser tab closes before the event fires, whereas a capture call running inside a mutation executes as part of the transaction your backend already committed to. That gives you a more reliable record of what happened, which is exactly what you want when the events feed product decisions.
Setting Environment Variables
Set your PostHog API key and host using npx convex env set. You can manage these the same way you handle any other Convex environment variables, keeping the credentials out of your code and available to your functions at runtime. With the key and host in place, the component can talk to PostHog.
Keeping the key and host as environment variables rather than hardcoded values is the right default for a credential that differs between your development and production deployments. Because Convex scopes environment variables per deployment, you can point your local environment at one PostHog project and production at another without changing a line of code, which keeps test events from polluting your production analytics.
Capturing Events Inside Mutations
Add a PostHog capture call inside a mutation where a meaningful action happens, such as a user creating a record or completing a step. Run the mutation, then open PostHog's product analytics view and confirm the event landed in your PostHog database. Because the capture runs server-side from inside the mutation, you get a reliable record of what happened in your backend rather than depending on the client to report it.
The judgment call here is which actions count as meaningful, and that's worth thinking about before you scatter capture calls everywhere. A capture call on every mutation produces noise that buries the signal, whereas a capture call on the handful of actions that map to real product outcomes gives you a dashboard you can reason about. I start narrow and add events as questions come up, since it's easier to add instrumentation than to clean up an event stream that records everything.
Using PostHog Feature Flags in Convex
You use PostHog feature flags in a Convex app by writing a featureFlags.ts action that calls the component to check whether a flag is enabled, then consuming that result through a useFeatureFlag React hook. The hook feeds a component that conditionally renders something, such as a welcome banner. You create and toggle the flag in the PostHog dashboard and watch the UI respond.
The flow is straightforward:
Create a flag in PostHog.
Wire the action to check it.
Surface the result through the hook.
Gate your UI on the returned value.
Flip the flag in the PostHog dashboard and the banner appears or disappears. The value of this pattern is that it moves the decision about who sees a feature out of your code and into a dashboard, so you can roll a feature out gradually or kill it instantly without shipping a new deploy.
There's one current trade-off worth being honest about. Because the flag check is implemented as an action rather than a query, the page has to be refreshed to reflect a change. A query would let Convex's reactive query model sync the UI automatically as the flag value changes, without a manual refresh. This is a current limitation of the component pattern rather than a flaw, and I expect it will improve in future versions, so for now plan on a refresh when you toggle a flag during testing.
It's worth being precise about where this matters and where it doesn't. During development and QA, the refresh is a mild annoyance that you'll notice every time you flip a flag to test both states. In production it matters far less, because a user who lands on the page after you've rolled out a flag sees the correct state on load, and the absence of live reactivity rarely changes their experience. So weigh the limitation against your testing workflow rather than against your end users, since that's where it lands.
Tracking AI and LLM Analytics With PostHog
You can track AI and LLM analytics in Convex with PostHog by installing the PostHog AI SDK alongside OpenTelemetry dependencies, then routing your model traces through PostHog. You create a provider, a span processor, and a PostHog trace exporter, register a global trace provider, and enable experimental_telemetry on the AI SDK's text generation call. This captures traces, latency, token usage, and cost.
The setup follows a clear sequence:
Install the PostHog AI SDK and OpenTelemetry packages.
Create the provider and span processor.
Build the PostHog trace exporter.
Register the global trace provider.
Enable telemetry on the generation call.
Once that's wired, every text generation request flows its telemetry into your PostHog database, which means the data starts accumulating the moment your next request runs.
This path takes more setup than the other two, and it's worth being candid about that. You're installing several packages and assembling a small chain of OpenTelemetry primitives rather than flipping a dashboard switch or adding a single capture call. The payoff is that token usage and cost are exactly the numbers that quietly grow until someone notices the bill, so instrumenting them early gives you a running view of spend before it becomes a surprise rather than after.
If you're using the Convex Agent component, the approach is parallel but the attachment point shifts. Because the Convex Agent uses the AI SDK under the hood, you attach telemetry to the thread's text generation rather than to the raw SDK call. Either way, you end up with traces, latency, token usage, and cost in PostHog, which gives teams building AI features a direct view into model behavior and spend that's easy to miss otherwise.
The attachment point matters because the Agent component manages the generation call for you, so there's no raw SDK call sitting in your code to decorate with telemetry. You hook into the thread's generation step instead, and the telemetry chain you built behaves identically from PostHog's perspective. That consistency is useful, because it means the dashboards you set up for raw SDK calls keep working when you migrate a feature onto the Agent component.
Frequently Asked Questions
Q: Does PostHog log streaming require a paid Convex plan?
A: Yes. Log streaming and error reporting require a paid Convex plan. The PostHog Convex component doesn't, so if you're on a free plan you can still capture product events and use feature flags through the component. This is the single constraint most likely to decide which path you start with, because a free-plan project that wants analytics today has to begin with the component regardless of what its backend observability needs eventually become.
Q: What's the difference between the log streaming integration and the PostHog component?
A: The log streaming integration is infrastructure-level observability, reporting which functions ran, how long they took, and what errors occurred. The PostHog component is product-level event capture, recording what users do from inside your Convex functions. Use log streaming for backend health, and use the component for product analytics. Most production apps run both, since the function-level signals and the user-level events answer different questions and you usually want to correlate the two.
Q: How do you use PostHog feature flags in a Convex app?
A: You write an action that calls the PostHog component to check whether a flag is enabled, then surface the result through a useFeatureFlag React hook that gates your UI. Because the check runs as an action rather than a query, you currently need to refresh the page to see a toggled flag take effect. That refresh is a testing-workflow annoyance more than a production concern, since end users land on the page and see the correct flag state on load.
Q: Can you track LLM/AI usage in Convex with PostHog?
A: Yes. You install the PostHog AI SDK and OpenTelemetry, create a provider and trace exporter, register a global trace provider, and enable experimental_telemetry on your text generation call. This captures traces, latency, token usage, and cost, with a parallel setup available for the Convex Agent component. The setup takes more effort than the other two integrations, but token and cost data are the signals that go unmeasured most often, so the extra work pays off as soon as your AI usage starts to scale.
Choosing Your Starting Point With the PostHog Convex Integration
A complete PostHog Convex integration is really two integrations that work together: dashboard-level log streaming for backend observability, and the PostHog Convex component for product events, feature flags, and AI analytics. If you're on a paid plan and want infrastructure visibility fast, start with log streaming since it needs no code. If you want to track what users do or experiment with feature flags, install the component and capture events from inside your mutations. The AI analytics path is worth the extra setup for any team running LLM features on Convex, because traces, latency, tokens, and cost are exactly the signals that go unmeasured otherwise.
Reduced to one rule, the advice is to start with whichever path answers the question you're actually asking right now, because both are quick to add and you'll almost certainly end up with both. A free-plan project asking what users do starts with the component. A paid-plan team asking why the backend is slow starts with log streaming. A team shipping an AI feature adds the telemetry chain the moment cost becomes a question worth tracking. None of these choices locks you out of the others, so the worst outcome of picking wrong is a short detour rather than a rebuild.
Convex is the backend platform with everything you need to build your full-stack AI project. Cloud functions, a database, file storage, scheduling, workflow, vector search, and realtime updates fit together seamlessly.