Back to Documentation

Google Tag Manager Setup

Install ClickDefender in minutes using Google Tag Manager. No code changes required.

Quick Start

1

Download the GTM Template

Download our pre-configured Google Tag Manager container template.

Download GTM Template
2

Import into Google Tag Manager

In GTM, go to AdminImport Container

  1. Select the downloaded JSON file
  2. Choose your workspace (usually "Default Workspace")
  3. Select "Merge" and "Rename conflicting tags"
  4. Click "Confirm"
3

Configure Your API Key

Find the "ClickDefender API Key" variable and replace the placeholder with your actual API key.

  1. Go to Variables in GTM
  2. Click on "ClickDefender API Key"
  3. Replace YOUR_API_KEY_HERE with your API key
  4. Save the variable
4

Publish Your Container

Click Submit in the top right corner to publish your changes.

That's it! ClickDefender is now protecting your site.

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 TagsNewCustom 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

OptionTypeDefaultDescription
apiKeystring-Your ClickDefender API key (required)
blockModestring"off"off |warn |block
trackConversionsbooleantrueEnable automatic conversion tracking
debugbooleanfalseEnable console logging for debugging
onBlockfunction-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:

  1. Open your website in a new browser tab
  2. Open DevTools (F12) and go to the Console tab
  3. Type ClickDefender and press Enter
  4. You should see the ClickDefender object with its methods
  5. 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.