Platform guides Doc #4 Reviewed Nov 28, 2026
WordPress and WooCommerce: gateway setup
Add the Anacoic gateway to a WordPress site or WooCommerce store, send purchases from your server, and check each delivery.
This guide adds the Anacoic gateway (Fix) to a WordPress site, with extra steps for WooCommerce stores.
Want to check your WooCommerce orders against what Meta recorded? That’s Watch, in early access: see Watch: connect a WooCommerce store.
What you need
- A WordPress site (self-hosted or WordPress.com Business)
- For WooCommerce: the plugin installed and active
- An Anacoic account with a gateway
Method 1: theme header (simplest)
Add the tracker to your theme’s header file.
Step 1: copy your snippet
Sign in to the app, open Fix, open your gateway, then the Setup tab, and copy the snippet under Install the tracking code:
<script src="https://edge.anacoic.com/v1/ana.js"
data-gateway="YOUR_GATEWAY_ID"
data-emq="optimize"></script>
Step 2: edit the 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 tracker -->
<script src="https://edge.anacoic.com/v1/ana.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: the Insert Headers and Footers plugin
No code editing needed.
Install the plugin
- Go to Plugins → Add New
- Search for “Insert Headers and Footers”
- Install and activate the plugin by WPBeginner
Add the snippet
- Go to Settings → Insert Headers and Footers
- Paste your snippet in the Scripts in Header box
- Click Save
Method 3: WPCode
For loading the tracker only on some pages, and other options.
Install WPCode
- Plugins → Add New
- Search for “WPCode”
- Install and activate
Create a snippet
- Go to Code Snippets → Add Snippet
- Click Add Your Custom Code
- Title: “Anacoic Tracking”
- Code Type: HTML Snippet
- Paste your snippet
- Location: Site Wide Header
- Toggle Active → ON
- Click Save Snippet
WooCommerce purchases
To send purchases, pass the order’s data.
Purchase event on the thank-you page
This sends Purchase from the browser. To also send each paid order from your server, which still works when the buyer never reaches this page, see WooCommerce server-side tracking without GTM.
Add to Appearance → Theme Editor → functions.php:
// Anacoic: send Purchase
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: 'order_<?php echo $order_id; ?>', // one stable ID per order, the same on the server
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
// 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
}
Sending match keys
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
}
});
Phone number format
WooCommerce stores phone numbers in local format. Convert them 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 issues
Caching plugins
If you use WP Rocket, W3 Total Cache or similar:
- Exclude
edge.anacoic.comfrom caching. - Don’t minify the tracker script.
- Clear the cache after adding the 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 outside scripts.
Allow it in Wordfence:
- Wordfence → All Options
- Under the allowed URLs, add
edge.anacoic.com
Consent plugins
If you use a consent plugin (CookieYes, Complianz):
- Put Anacoic in the “Analytics” or “Marketing” category.
- Load it only after consent:
// With CookieYes
document.addEventListener('cookieyes_consent_update', function(eventData) {
const data = eventData.detail;
if (data.accepted.includes('analytics')) {
// Load Anacoic
loadAnacoic();
}
});
Multisite networks
For WordPress Multisite, either:
- network-activate the tracking code, or
- use a gateway for each 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
- Connect Meta’s Conversions API.
- Add a custom domain, so events go to your own subdomain.
- Send each paid order from your server too, with the same event ID: WooCommerce server-side tracking without GTM has the order hook and the checks.
- See what Anacoic connects for WooCommerce, and connect WooCommerce to Watch to check your orders against Meta.
Troubleshooting
Events not showing
- Check the browser console for errors.
- Check the gateway ID.
- Check whether a security plugin is blocking requests.
- Test with caching turned off.
Low Event Match Quality in Meta
- Make sure
user.emailis sent with each purchase. - Format phone numbers as E.164.
- Check that the customer is signed in (for
external_id).
Need more help? Write to support.