# A/B testing in Sanity Studio with PostHog

> A quick walkthrough of A/B testing a hero button with Sanity Studio and PostHog. Set up control and variant pages in Sanity, ship them to users, and read exposures, clicks per user, and winners str…

**Published:** 2026-09-22 | **Updated:** 2026-09-23 | **Categories:** Walkthroughs

Watch: https://www.youtube.com/watch?v=86lW_o3tadg

---

## Transcript

AB testing with Sanity Studio and PostHog. I'm going to show you a very cool example of a button hero that we built internally and how easily you can set your own test and check the results on PostHog.

As you can see on my screen, I've set up my test on Sanity. This is the AB testing space where I've added my control and my other one, called it blue. Essentially it's a black button. And the other thing is I have pages for black and white as well. You can set as many pages in your particular case as you want.

Now I'll show you exactly how this looks. The user will see this and what they can do is click on this button, and you can see the total clicks changing on the screen. If I refresh it, hopefully I get a different variation to show you.

There we go. So we've got the black one. Click a bunch of times. Anyway, you can do this for any use case with different variations. You can do it for form clicks, different pages, or whatever suits your needs. I'll show you how this looks on the PostHog side.

This is my particular demo. As you can see, total exposure is 125. That's 125 times this was exposed to people. I have my control and I have my blue. I called the other one blue but it's essentially a black button. I know it's a little bit confusing but bear with me.

As you can see here, on average there's eight clicks per person for the control, and on average there's nine clicks per user for blue. But the interesting thing is 30 versus 23 exposures to look at. So 23 times the blue button was exposed to the user as compared to 30 times for the control variation. But on average, nine clicks per user was recorded for the blue one. So the blue one, or the black button, is winning in our case.

You can set your metrics here, look at them, look at all the different charts. In our case, as I mentioned, the blue one is doing much better than the white one. But this is a very simple example. The whole point of this video is to show you how easy it is to record this and use it in your own use case.

The tool is completely open source. Let us know if you'd like to try it for yourself and how you found it. We love making these kinds of videos.

## Frequently asked questions

### What is AB testing in Sanity Studio?

AB testing in Sanity Studio lets you create different variations of content, like buttons with different colors, and serve them to users to see which performs better. You set up a control version and one or more test variations, then track how users interact with each one to determine which wins.

### How do you set up an AB test in Sanity?

In Sanity's AB testing space, you add your control variation and name your other variations, like we called ours blue. You can also create multiple pages for each variation if you need them. The setup is straightforward and you can customize it for whatever you want to test.

### What metrics does PostHog show for AB tests?

PostHog displays total exposures, which is how many times a variation was shown to users, and average clicks per user for each variation. You can see these metrics side by side to compare performance between your control and test versions, along with additional charts and data points.

### How can you tell which variation is winning?

Compare the average clicks per user between your variations. In our example, the blue button had nine clicks per user on average while the control had eight, making the blue variation the winner. PostHog makes it easy to see these numbers and determine which version performs better.

### What kinds of things can you AB test?

You can test button variations, form clicks, different pages, or really any use case where you want to measure user interaction. The system is flexible enough to accommodate whatever variations you want to compare across your product or site.

### Is this tool free to use?

Yes, the tool is completely open source, so you can use it without paying for a license. You can set it up for yourself and start running tests right away with no cost barriers.

### How easy is it to track test results?

Once you set up your variations in Sanity, they automatically feed into PostHog and you can see all your metrics and charts immediately. The whole process from setup to viewing results is designed to be straightforward so you can focus on what the data tells you about user behavior.