How to use AI to model GA4 data with OpenAI Codex and MCP servers

Product video · May 27, 2026 · 5:54

Transcript

This transcript is auto-generated. Names and product terms may be wrong.

  1. So, in this video, I want to walk you through a task. Um we have some data in Google Analytics, very common. It gets exported to Google BigQuery, and finally, we want to model it and make it available in Omni. Uh the challenges with this is that the data tends to be highly nested. Um so, we have uh hundreds of fields that are available to be modeled.

  2. We may not know exactly what they mean. Uh we have to do some uh gymnastics to get them in the right place. And uh we want them to be nicely labeled. We want them to be um available to Omni in the best way possible. Uh and then the real challenge also lies in that we want the data to be exactly the same.

  3. If somebody opens Omni and asks a query, we want that uh data to match up exactly in Google Analytics. Traditionally, this was a pretty hard task. It could take many, many hours to get everything to line up, to label everything correctly. So, with the approach that I'm going to show you, we are going to use OpenAI's Codex to connect to four different MCP servers and make this task a lot more easy and even fun.

  4. I have a source system here. It's Google Analytics. It's a super old uh personal blog that is connected to BigQuery, so it's everything I need to show you. Uh you'll see things like, okay, I had 93 users from China in um the last uh 28 days or so. Um this is exported over to BigQuery. So, the problem here is that I have a lot of fields.

  5. A lot of them are like nested, like items has like, you know, uh several levels of nesting, including key values, uh which are quite difficult to model. Um and so, if we go over to Omni, you'll see that I have a lovely topic, which has nice categories and things like that. So, if I click on geo, and I click on country.

  6. Everything has like nice labels and importantly this is filtered exactly the same way as my report. It matches. So I have 93 users from China in the same time period. So let's go into my coding tool so I can show you some details about how this works. Okay, so in my terminal I'm going to use Codex. This is the CLI tool from OpenAI.

  7. You can use any of them cursor etc. You'll see when Codex starts we have four MCP servers. We'll just open those up and walk you through them. So these are analytics MCP is Google Analytics. So it can connect directly into the analytics API not through big query. Then I have big query. This can like run queries and get data set infos and things like that.

  8. Contact 7 is my documentation and finally Omni which is directly connected to get data and pick topics. Okay, so if I want to do something like show me the number of users by country between 2025 12 03 and 2025 12 28 compare them in Omni and in Google Analytics in a single table. Right, so this should connect to both systems so you'll see it.

  9. First connecting to Omni picking a topic. It's using effectively text query to do that. Okay, perfect. We have the data. Now it is running a report in Google Analytics with the same information. Checking to make sure that there is no date discrepancies. It's being inclusive. Okay, here's the comparison. So, it looks like everything's perfect. This appears to be inclusive.

  10. Results match GA. Okay, so I did a little bit of work to match it, and then it even gave me like a link to the workbook if I want to try it out. So, that's fantastic. Now, I want to do something more interesting. I don't actually have a measure called average session duration. So, I'm going to ask it to create that.

  11. So, please look in BigQuery to figure out how to model average session duration in Omni. Don't forget to use the extends file to its place. Right, let's see what it'll do now. So, it should be connecting to BigQuery because I want it to like look and see what fields are available in the schema. It's looking to see if there's anything that exists there.

  12. Okay, it's going into BigQuery and it's going to just use one of the tables, get a table info to look at what fields are available. Actually executing some queries. This can be dangerous if you have a huge project, by the way. So, be careful. It's actually querying the documentation to see if there's anything interesting in the documentation for the export schema.

  13. So, that's amazing. Okay, and it's editing my YAML file. Awesome. Let's get those added into Omni and see how they work. Right, so back in Omni, I've added the measures that were created for me. I've added them to a query. Average session duration seems to work perfectly fine. And I'm, you know, I can show you that it it does match Google Analytics.

  14. Once I've like added this, I can of course go back and fill out that agentic loop to make sure that everything works fine. But, I found it to be so easy to be be to iterate and add things very, very quickly to what would be a very complex modeling task.