WordPress & WooCommerce
Install Anacoic on WordPress or WooCommerce sites
WordPress & WooCommerce Integration
This guide covers installing Anacoic on WordPress sites, with special attention to WooCommerce stores.
Prerequisites
- WordPress site (self-hosted or WordPress.com Business)
- For WooCommerce: Plugin installed and activated
- Anacoic account with gateway created
Method 1: Theme Header (Simplest)
Add the tracker to your theme’s header file.
Step 1: Get Your Snippet
From your Anacoic Dashboard → Gateway → Installation tab, copy the One-Line snippet:
<script src="https://edge.anacoic.com/v1/tracker.js"
data-gateway="YOUR_GATEWAY_ID"
data-emq="optimize"></script>
Step 2: Edit Theme Header
- In WordPress Admin, go to Appearance → Theme Editor
- Find
header.phpin the right sidebar - Locate
</head>tag - Paste your snippet right before it:
<!-- Anacoic Tracking -->
<script src="https://edge.anacoic.com/v1/tracker.js"
data-gateway="YOUR_GATEWAY_ID"
data-emq="optimize"></script>
<?php wp_head(); ?>
- Click Update File
Note: Use a child theme to prevent updates from overwriting your changes.
Method 2: Insert Headers and Footers Plugin
No code editing required.
Install Plugin
- Go to Plugins → Add New
- Search for “Insert Headers and Footers”
- Install and activate the plugin by WPBeginner
Add Anacoic Code
- Go to Settings → Insert Headers and Footers
- Paste your snippet in the Scripts in Header box
- Click Save
Method 3: WPCode (Advanced)
For conditional loading and advanced features.
Install WPCode
- Plugins → Add New
- Search for “WPCode”
- Install and activate
Create Snippet
- Go to Code Snippets → Add Snippet
- Click Add Your Custom Code
- Title: “Anacoic Tracking”
- Code Type: HTML Snippet
- Paste your One-Line snippet
- Location: Site Wide Header
- Toggle Active → ON
- Click Save Snippet
WooCommerce Integration
For e-commerce tracking, you need to pass order data.
Purchase Event in Thank You Page
Add to Appearance → Theme Editor → functions.php:
// Anacoic Purchase Tracking
add_action('woocommerce_thankyou', 'anacoic_purchase_tracking', 10, 1);
function anacoic_purchase_tracking($order_id) {
$order = wc_get_order($order_id);
if (!$order) return;
$total = $order->get_total();
$currency = $order->get_currency();
$email = $order->get_billing_email();
$phone = $order->get_billing_phone();
?>
<script>
if (window.anacoic) {
window.anacoic.track({
event_name: 'Purchase',
event_id: '<?php echo $order_id; ?>_' + Date.now(),
user: {
email: '<?php echo esc_js($email); ?>',
phone: '<?php echo esc_js($phone); ?>'
},
custom_data: {
value: <?php echo $total; ?>,
currency: '<?php echo $currency; ?>',
transaction_id: '<?php echo $order_id; ?>'
}
});
}
</script>
<?php
}
Add to Cart Tracking
// Track Add to Cart
add_action('wp_footer', 'anacoic_add_to_cart_tracking');
function anacoic_add_to_cart_tracking() {
if (!is_product()) return;
global $product;
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
var addButton = document.querySelector('.single_add_to_cart_button');
if (addButton) {
addButton.addEventListener('click', function() {
if (window.anacoic) {
window.anacoic.track({
event_name: 'AddToCart',
custom_data: {
content_name: '<?php echo esc_js($product->get_name()); ?>',
content_type: 'product',
value: <?php echo $product->get_price(); ?>,
currency: '<?php echo get_woocommerce_currency(); ?>'
}
});
}
});
}
});
</script>
<?php
}
Achieving High EMQ Scores
For WooCommerce Orders
Pass all available customer data:
anacoic.track({
event_name: 'Purchase',
user: {
email: customerEmail, // From order
phone: customerPhone, // From order (E.164 format)
external_id: userId // WordPress user ID if logged in
},
custom_data: {
value: orderTotal,
currency: orderCurrency
}
});
// Expected EMQ: 7.5-9.0
Phone Number Formatting
WooCommerce stores phone in local format. Convert to E.164:
function format_phone_e164($phone, $country) {
$phone = preg_replace('/[^0-9]/', '', $phone);
// Add country code if missing
$country_codes = [
'US' => '1',
'GB' => '44',
'DE' => '49',
'FR' => '33',
// Add more as needed
];
if (isset($country_codes[$country]) && strlen($phone) <= 10) {
$phone = $country_codes[$country] . $phone;
}
return '+' . $phone;
}
WordPress-Specific Issues
Caching Plugins
If using WP Rocket, W3 Total Cache, etc.:
- Exclude
edge.anacoic.comfrom caching - Don’t minify the tracker script
- Clear cache after adding snippet
WP Rocket Settings:
- File Optimization → Excluded JavaScript Files: Add
edge.anacoic.com - File Optimization → Excluded Inline JavaScript: Add
anacoic
Security Plugins
Plugins like Wordfence may block external scripts.
Whitelist in Wordfence:
- Wordfence → All Options
- Whitelisted URLs: Add
edge.anacoic.com
GDPR Compliance
If using GDPR plugins (CookieYes, Complianz):
- Categorize Anacoic as “Analytics” or “Marketing”
- Only load after consent:
// With CookieYes
document.addEventListener('cookieyes_consent_update', function(eventData) {
const data = eventData.detail;
if (data.accepted.includes('analytics')) {
// Load Anacoic
loadAnacoic();
}
});
Multi-Site Network
For WordPress Multisite:
- Network activate the tracking code, OR
- Use different gateways per site:
// In wp-config.php or mu-plugin
$site_gateways = [
1 => 'gateway_site_1',
2 => 'gateway_site_2',
];
$current_gateway = $site_gateways[get_current_blog_id()] ?? 'default_gateway';
Next Steps
- Configure Meta CAPI for Facebook tracking
- Add custom domain for reliability
- Set up Agent Gateway for AI discoverability
Troubleshooting
Events Not Showing
- Check browser console for errors
- Verify gateway ID is correct
- Check if security plugin is blocking requests
- Test with caching disabled
Low EMQ Scores
- Ensure
user.emailis passed on purchase - Add phone number formatting
- Check that customer is logged in (for
external_id)
Need more help? Contact support