Google Tag Manager Setup
Install ClickDefender in minutes using Google Tag Manager. No code changes required.
Quick Start
Download the GTM Template
Download our pre-configured Google Tag Manager container template.
Download GTM TemplateImport into Google Tag Manager
In GTM, go to Admin → Import Container
- Select the downloaded JSON file
- Choose your workspace (usually "Default Workspace")
- Select "Merge" and "Rename conflicting tags"
- Click "Confirm"
Configure Your API Key
Find the "ClickDefender API Key" variable and replace the placeholder with your actual API key.
- Go to Variables in GTM
- Click on "ClickDefender API Key"
- Replace
YOUR_API_KEY_HEREwith your API key - Save the variable
Publish Your Container
Click Submit in the top right corner to publish your changes.
Manual Setup (Alternative)
If you prefer to set up the tag manually instead of importing the template:
1. Create a Custom HTML Tag
Go to Tags → New → Custom HTML
<script src="https://www.clickdefender.app/defender.js"></script>
<script>
ClickDefender.init({
apiKey: 'YOUR_API_KEY_HERE',
endpoint: 'https://www.clickdefender.app',
blockMode: 'warn',
trackConversions: true
});
</script>2. Set the Trigger
Add the trigger All Pages - Page View to fire on every page.
3. Configure Advanced Settings
Under Tag firing options, select Once per page.
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | - | Your ClickDefender API key (required) |
blockMode | string | "off" | off |warn |block |
trackConversions | boolean | true | Enable automatic conversion tracking |
debug | boolean | false | Enable console logging for debugging |
onBlock | function | - | Callback when a visitor is blocked |
Conversion Tracking
Track conversions to understand which blocked clicks would have converted and calculate your ROI.
Using Data Layer (Recommended)
Push conversion data to the data layer, then configure the GTM variable:
// On your thank-you page
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'ORDER123',
value: 99.99,
currency: 'USD'
}
});Using JavaScript API
Or call the ClickDefender API directly:
ClickDefender.trackConversion({
type: 'purchase',
value: 99.99,
orderId: 'ORDER123'
});Troubleshooting
Tag Not Firing
Use GTM Preview mode to verify the tag fires. Check that the trigger is set to "All Pages" and the tag isn't paused.
API Key Invalid
Ensure you've copied the complete API key from your ClickDefender dashboard. The key should start with cd_.
No Events in Dashboard
Events may take up to 5 minutes to appear. Check your browser console for errors and verify the domain is registered in your property settings.
Verify Installation
After publishing your GTM container, verify ClickDefender is working:
- Open your website in a new browser tab
- Open DevTools (F12) and go to the Console tab
- Type
ClickDefenderand press Enter - You should see the ClickDefender object with its methods
- Check your ClickDefender dashboard - events should appear within 5 minutes
Need Help?
Our support team is here to help you get ClickDefender set up correctly.