Revenue
Connect WooCommerce
WooCommerce sends order updates to a webhook signed with a secret MetricRaven generates. A small plugin stores the visitor ID on each order.
Set up the webhook
Install the MetricRaven script on your store
Install the MetricRaven WordPress plugin so checkout pages load the tracker and orders carry the visitor ID.
Open Settings → Integrations → WooCommerce
Choose Set up WooCommerce. Copy the webhook URL and the secret; the secret is shown once.
Add a webhook in WooCommerce
In WordPress, open WooCommerce → Settings → Advanced → Webhooks → Add webhook. Set Status to Active, Topic to Order updated, paste the delivery URL and secret, keep WP REST API Integration v3, and save.
Order updated fires when an order is paid and when it is refunded. Optionally add a second webhook for Order created with the same URL and secret.
Store the visitor ID on orders
The MetricRaven WordPress plugin does this for you: keep its Revenue attribution setting on. Without the plugin, save this as a must-use plugin. It keeps the visitor ID in a session cookie on checkout and stores it on the order as hidden meta _metricraven_visitor_id (classic and block checkout):
<?php
/**
* Plugin Name: MetricRaven attribution
* Save as wp-content/mu-plugins/metricraven-attribution.php
*/
// 1. On checkout, keep the MetricRaven visitor ID in a session cookie.
add_action('wp_footer', function () {
if (!function_exists('is_checkout') || !is_checkout()) return; ?>
<script>
(function () {
function save() {
var id = window.analytics && window.analytics.getVisitorId && window.analytics.getVisitorId();
if (!id) return;
document.cookie = "metricraven_visitor_id=" + id + "; Path=/; SameSite=Lax" +
(location.protocol === "https:" ? "; Secure" : "");
}
save();
window.addEventListener("analytics:visitor", save);
})();
</script>
<?php });
// 2. Store it on the order as hidden meta (classic and block checkout).
function metricraven_attribute_order($order) {
$id = isset($_COOKIE['metricraven_visitor_id']) ? (string) $_COOKIE['metricraven_visitor_id'] : '';
if (preg_match('/^(?:[0-9a-f]{24}|[0-9a-f]{32})$/', $id)) {
$order->update_meta_data('_metricraven_visitor_id', $id);
}
}
add_action('woocommerce_checkout_create_order', 'metricraven_attribute_order');
add_action('woocommerce_store_api_checkout_update_order_meta', 'metricraven_attribute_order');You can also set metricraven_user_id order meta from your own code. Signed-in customers' billing emails are matched to emails you sent to the Identify API.
MetricRaven links each payment to a visit using the first of these that is available:
- The
metricraven_visitor_idpassed through checkout. - The
metricraven_user_id(or the provider's customer external ID), matched to a visitor you linked with the Identify API. - An earlier payment from the same provider customer, so renewals keep the original attribution.
- The checkout email, matched to an email you sent to the Identify API.
- The checkout email, matched to a browser that called payment({ email }) within an hour of the payment.
Verify it works
After a delivery, the WooCommerce card in Settings → Integrations shows Connected, the number of verified events and the last event type. A live payment appears in Revenue in its own currency; with a visitor ID it is credited to that visit's source in Traffic.
If the card says a delivery was rejected, the signing secret doesn't match. Paste it again or generate a replacement.
Details
- Orders count once they are paid (status processing or completed, with a paid date). Revenue is the order total including tax and shipping, in the order currency. Refunds reduce it by the order's refund totals.
- WooCommerce Subscriptions renewal orders are counted as renewals.
- WooCommerce sends an unsigned ping when you save a webhook; MetricRaven answers it without recording anything.
- Signature:
X-WC-Webhook-Signatureis the base64 HMAC-SHA256 of the raw request body with your secret. - WooCommerce disables a webhook after repeated failed deliveries. If deliveries stop, check WooCommerce → Status → Logs and re-enable it.
- Each delivery is verified with an HMAC signature over the exact request body, compared in constant time. Unsigned or altered requests are rejected with
401and never change revenue. - Redelivered events are recognized and ignored, so provider retries never add a payment twice. Refunds reduce the original payment and never exceed it.
- The signing secret is stored encrypted, bound to this site, and never shown in reports, share links or logs. Disconnecting deletes it; imported revenue stays in your reports.
- Free trials and zero-amount orders are not revenue. A subscription cancellation is not a refund: revenue already paid stays.
- Webhooks deliver new events only. Payments from before you connected are not imported, and live MRR is currently available for Stripe only.
- Use one revenue path per purchase: don't also send the same orders through the Payments API.