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

  1. In WordPress Admin, go to Appearance → Theme Editor
  2. Find header.php in the right sidebar
  3. Locate </head> tag
  4. 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(); ?>
  1. 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

  1. Go to Plugins → Add New
  2. Search for “Insert Headers and Footers”
  3. Install and activate the plugin by WPBeginner

Add the snippet

  1. Go to Settings → Insert Headers and Footers
  2. Paste your snippet in the Scripts in Header box
  3. Click Save

Method 3: WPCode

For loading the tracker only on some pages, and other options.

Install WPCode

  1. Plugins → Add New
  2. Search for “WPCode”
  3. Install and activate

Create a snippet

  1. Go to Code Snippets → Add Snippet
  2. Click Add Your Custom Code
  3. Title: “Anacoic Tracking”
  4. Code Type: HTML Snippet
  5. Paste your snippet
  6. Location: Site Wide Header
  7. Toggle Active → ON
  8. 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:

  1. Exclude edge.anacoic.com from caching.
  2. Don’t minify the tracker script.
  3. 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:

  1. Wordfence → All Options
  2. Under the allowed URLs, add edge.anacoic.com

If you use a consent plugin (CookieYes, Complianz):

  1. Put Anacoic in the “Analytics” or “Marketing” category.
  2. 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:

  1. network-activate the tracking code, or
  2. 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

  1. Connect Meta’s Conversions API.
  2. Add a custom domain, so events go to your own subdomain.
  3. 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.
  4. See what Anacoic connects for WooCommerce, and connect WooCommerce to Watch to check your orders against Meta.

Troubleshooting

Events not showing

  1. Check the browser console for errors.
  2. Check the gateway ID.
  3. Check whether a security plugin is blocking requests.
  4. Test with caching turned off.

Low Event Match Quality in Meta

  1. Make sure user.email is sent with each purchase.
  2. Format phone numbers as E.164.
  3. Check that the customer is signed in (for external_id).

Need more help? Write to support.