Preview and Share Experiment¶
How to Create a Preview URL for A/B Tests in Google Tag Manager¶
Sometimes, you want to show a test variation to your team or clients before going live. This helps everyone see what the changes look like and approve them. Using a URL parameter is a quick and easy way to do this.
Step-by-Step Guide¶
1. Create a URL Variable in GTM:¶
- Create a URL Variable in GTM
- Go to Variables in your Google Tag Manager.
- Under User-Defined Variables, click New.
- Choose Variable Type: URL.
- Under Component Type, choose Query.
- Name your parameter, for example: view.
- Save the variable.
Now, whenever someone visits a page with ?view=variant in the URL, this variable will store the value variant.
2. Make a Trigger That Checks This Variable¶
- Go to Triggers and click New.
- Choose Trigger Type: Page View (you can also use DOM Ready or Window Loaded).
- Add a condition: Your Variable (e.g. view) equals variant.
- Save the trigger.
3. Attach the Trigger to Your Variant Tag¶
- Open the Tags section.
- Create or edit your tag that loads the variant code.
- Add the new trigger to this tag.
- Save and publish.
4. Test in Preview Mode¶
- Enter Preview Mode in GTM.
- Load your site with the URL parameter, like this:
- Check that your variant tag fires in the preview panel.
- Publish your container when ready.
With this simple trick, you can let your team and stakeholders review your A/B test changes before going live. It only takes a few minutes to set up. Once done, anyone with the preview URL can see the variant. This helps you catch errors early and share ideas more easily.
Last update: February 20, 2025