Official Google Tag Manager template for GrowthBook, the open-source feature flagging and A/B testing platform.
- 🚀 Load the GrowthBook SDK without writing code
- 📊 Automatic experiment tracking to dataLayer (GA4 compatible)
- 🔒 Support for encrypted SDK payloads
- 🏠 Works with GrowthBook Cloud and self-hosted instances
- 🪣 Optional sticky bucketing for advanced use cases
- In Google Tag Manager, go to Templates → Search Gallery
- Search for "GrowthBook"
- Click Add to workspace
- Download
template.tplfrom this repository - In GTM, go to Templates → New
- Click the three-dot menu (⋮) → Import
- Select the downloaded file
| Field | Description |
|---|---|
| Client Key | Your GrowthBook SDK client key (starts with sdk-). Find this in GrowthBook under SDK Configuration → SDK Connections. |
| Field | Description |
|---|---|
| API Host | For self-hosted GrowthBook instances. Leave blank for GrowthBook Cloud. |
| Decryption Key | Required only if you enabled encryption in your SDK Connection settings. |
| Sticky Bucketing | Advanced feature to preserve variation assignments when modifying experiments mid-flight or using multi-arm bandits. Options: Disabled, Cookie, or Local Storage. |
- Create a new tag using this template
- Enter your Client Key
- Set the trigger to All Pages (or your preferred pages)
- Save and publish
The GrowthBook SDK automatically pushes experiment_viewed events to the dataLayer:
{
"event": "experiment_viewed",
"experiment_id": "your-experiment-key",
"variation_id": "control"
}Import our pre-built configuration to automatically create the required variables, trigger, and GA4 tag:
- Download
ga4-tracking-config.jsonfrom this repository - In GTM, go to Admin → Import Container
- Select the JSON file
- Choose Merge → Rename conflicting tags, triggers, and variables
- Click Confirm
- Go to Tags and open "GA4 Event - GrowthBook Experiment Viewed"
- Replace
G-XXXXXXXXXXwith your GA4 Measurement ID - Save and publish
Note: The GrowthBook tag template must be installed separately from the Community Template Gallery — container imports cannot include custom templates.
If you prefer to set it up manually:
- Create a Data Layer Variable for
experiment_id - Create a Data Layer Variable for
variation_id - Create a Custom Event Trigger for
experiment_viewed - Create a GA4 Event Tag that fires on this trigger with the experiment parameters
See our full GTM + GA4 setup guide for detailed instructions.
To use feature flags, create a separate Custom HTML tag with your logic. The growthbook_queue ensures your code runs after the SDK loads:
<script>
window.growthbook_queue = window.growthbook_queue || [];
window.growthbook_queue.push(function(gb) {
function applyFeatureFlags() {
// Example: Add a class when feature is enabled
if (gb.isOn("show-discount")) {
var el = document.getElementById("price");
if (el) el.classList.add("show-discount");
}
// Example: Use a string feature value
var buttonColor = gb.getFeatureValue("button-color", "blue");
var btn = document.getElementById("cta");
if (btn) btn.style.backgroundColor = buttonColor;
}
// Apply on initial load
applyFeatureFlags();
// Re-apply when features update via real-time streaming (SSE)
document.addEventListener("growthbookdata", applyFeatureFlags);
});
</script>Apache 2.0