Installing AdTarget on WordPress
This guide covers two ways to add AdTarget tracking to your WordPress site: using a plugin or manual installation.
Recommended: The manual method is fastest and doesn’t require installing any plugins.
Method 1: Manual Installation (Recommended)
The simplest way to add tracking code to WordPress.
Access Theme Editor
Log in to your WordPress admin panel, go to Appearance → Theme File Editor, and select your active theme from the dropdown.
Edit header.php
In the file list, click header.php and find the <head> section. Add the tracking code inside it:
<!-- AdTarget Tracking -->
<script
defer
data-website-id="atid_YOUR_WEBSITE_ID"
data-domain="yourdomain.com"
src="https://adtarget.io/track.js"
></script>Replace atid_YOUR_WEBSITE_ID with your actual website ID and yourdomain.com with your domain, then click Update File.
Verify Installation
Visit your site, then open your AdTarget dashboard — you should see tracking activity within a few seconds.
Method 2: Using a Plugin
If you’re not comfortable editing theme files, use a code insertion plugin.
Using “Insert Headers and Footers” Plugin
Install the Plugin
Install and activate the Insert Headers and Footers plugin.
Add the Code
Go to Settings → Insert Headers and Footers. In the Scripts in Header box, paste:
<script
defer
data-website-id="atid_YOUR_WEBSITE_ID"
data-domain="yourdomain.com"
src="https://adtarget.io/track.js"
></script>Save Changes
Replace atid_YOUR_WEBSITE_ID with your website ID and yourdomain.com with your domain, then click Save.
Using “Code Snippets” Plugin
Install the Plugin
Install and activate the Code Snippets plugin.
Create a Snippet
Go to Snippets → Add New and name it “AdTarget Tracking”. Add this PHP code:
function adtarget_tracking_code() {
echo '<script defer src="https://adtarget.io/track.js" data-website-id="atid_YOUR_WEBSITE_ID" data-domain="yourdomain.com"></script>';
}
add_action('wp_head', 'adtarget_tracking_code');Activate the Snippet
Replace YOUR_WEBSITE_ID with your website ID, set it to run on “Front-end only”, and save and activate.
Method 3: Child Theme (Advanced)
If you use a child theme, add to your functions.php:
function adtarget_enqueue_tracking() {
wp_enqueue_script(
'adtarget-tracker',
'https://adtarget.io/track.js',
array(),
null,
false // Load in head
);
}
add_action('wp_enqueue_scripts', 'adtarget_enqueue_tracking');
// Add custom attributes to the script tag
add_filter('script_loader_tag', function($tag, $handle) {
if ($handle === 'adtarget-tracker') {
return str_replace(
' src',
' defer data-website-id="atid_YOUR_WEBSITE_ID" data-domain="yourdomain.com" src',
$tag
);
}
return $tag;
}, 10, 2);Adding to Specific Pages Only
Using a Page Builder
If you use Elementor, Divi, or another page builder:
- Edit your landing page
- Add an HTML widget/module
- Paste the tracking code
- Save and publish
Using Conditional Logic
Add this to your theme’s functions.php to load only on specific pages:
function adtarget_conditional_tracking() {
// Only load on pages with ID 123 or 456
if (is_page(array(123, 456))) {
echo '<script defer src="https://adtarget.io/track.js" data-website-id="atid_YOUR_WEBSITE_ID" data-domain="yourdomain.com"></script>';
}
}
add_action('wp_head', 'adtarget_conditional_tracking');Multiple Funnels on the Same Domain
Need different Telegram channels for different sections of your site? For example, yoursite.com and yoursite.com/uk each leading to separate channels.
How it works: Create a separate site in AdTarget for each funnel. Each site gets its own tracking code and Telegram channel.
Using WPCode Plugin (Recommended)
Create Multiple Sites in AdTarget
In your AdTarget dashboard , create one site per funnel:
- Site 1:
yoursite.com→ connects to your main channel - Site 2:
yoursite.com/uk→ connects to your UK channel
Create Separate Snippets
In WordPress, go to Snippets → Add Snippet and create one snippet per funnel:
Snippet 1 (Main site):
<script defer data-website-id="atid_abc123" data-domain="yourdomain.com" src="https://adtarget.io/track.js"></script>Snippet 2 (UK funnel):
<script defer data-website-id="atid_xyz789" data-domain="yourdomain.com" src="https://adtarget.io/track.js"></script>Set Page Rules
For each snippet, use Smart Conditional Logic:
- Snippet 1: URL does not contain
/uk - Snippet 2: URL contains
/uk
Using PHP Conditional Logic
Add this to your theme’s functions.php:
function adtarget_multi_funnel_tracking() {
$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, '/uk') === 0) {
// UK funnel
$site_id = 'atid_xyz789';
} else {
// Main site
$site_id = 'atid_abc123';
}
echo '<script defer data-website-id="' . $site_id . '" data-domain="yourdomain.com" src="https://adtarget.io/track.js"></script>';
}
add_action('wp_head', 'adtarget_multi_funnel_tracking');Important: Make sure each page only loads one tracking script. Remove any global tracking code if using this method.
WordPress-Specific Tips
Caching plugins: After adding the code, clear your cache in WP Super Cache, W3 Total Cache, or your caching plugin.
Multisite installations:
- Add the code to each site separately, or
- Use a network-activated plugin for global tracking
Theme updates:
- If editing theme files directly, use a child theme
- Theme updates will overwrite your changes otherwise
Troubleshooting
Code not appearing on site?
- Clear all caches (WordPress + browser)
- Check if your theme uses a custom header structure
- Verify you’re editing the active theme
JavaScript errors in console?
- Check for conflicts with other plugins
- Try disabling optimization/minification plugins temporarily
Admin bar issues?
- The tracking code is designed to work with the admin bar
- Log out to test as a regular visitor
Need Help?
Having issues with WordPress installation? Contact support with:
- Your WordPress site URL
- Theme name
- List of active plugins
- Any error messages