Official Google Tag Manager template for ConfigCat.
ConfigCat is a feature flag and configuration management service that lets you separate releases from deployments. You can turn your features ON/OFF using ConfigCat Dashboard even after they are deployed. ConfigCat lets you target specific groups of users based on region, email or any other custom user attribute.
- Open Google Tag Manager
- Go to Templates -> Search Gallery
- Search for "ConfigCat"
- Click Add to workspace
- Download
template.tplfrom this GitHub repository - Open Google Tag Manager
- Go to Templates -> New
- Click the three-dot menu (⋮) -> Import
- Select the downloaded template file
| Field | Description |
|---|---|
| SDK Key | Your ConfigCat SDK Key. Get it from ConfigCat Dashboard. |
| Field | Description |
|---|---|
| Polling mode | The polling mode to use to fetch the config data from the ConfigCat CDN. More about polling modes. Default is Auto polling |
| Data governance | Describes the location of your feature flag and setting data within the ConfigCat CDN. This parameter needs to be in sync with your Data Governance preferences. More about Data Governance. Default is Global |
| Base URL | Sets the CDN base url (forward proxy, dedicated subscription) from where the SDK will download the config JSON. |
- Create a new tag using the ConfigCat GTM template
- Enter your SDK Key
- Set the trigger to All Pages (or your preferred pages)
- Save and publish
To use feature flags, first create a Custom Event called "ConfigCatLoaded".
- In Google Tag Manager, go to Triggers -> New -> Trigger Configuration.
- Select Custom Event.
- Enter "ConfigCatLoaded" as the event name. The ConfigCat tag will push this event to the data layer when it has loaded.
- Name the Custom Event trigger "ConfigCatLoaded".
Now you can create a separate Custom HTML tag with your logic and tigger it with the "ConfigCatLoaded" Custom Event you just created.
<script>
(function () {
var initParams = window.configcatInitParams;
if (!window.configcat || !initParams) {
console.warn('[ConfigCat] SDK not loaded');
return;
}
if (!window.configcatClient) {
window.configcatClient = window.configcat.getClient(
initParams.sdkKey,
initParams.PollingMode,
init.options
);
}
var client = window.configcatClient;
// Waiting for the feature flag configuration is downloaded and ready to use
client.waitForReady().then(function () {
return client.getValueAsync('ShowBlackFridayDiscount', false);
}).then(function (value) {
// Example: Add a class when feature is enabled
var element = document.getElementById("pricing");
if (value && element) {
element.classList.add("black-friday-discount");
}
});
})();
</script>Apache 2.0