SDKs
WordPress
The plugin: the snippet on every page, consent, your own domain, WooCommerce goals, and its paid, cancelled and refunded orders.
The LiftCanary plugin puts the website snippet on every page of your WordPress site without editing your theme, and on a WooCommerce store reports product views, add to cart, checkout and purchases as goals, and can send every order's payment, refunds and cancellation (see Orders from WooCommerce). Everything else works as on any website: no-code and redirect tests, the visual editor, personalizations, flags and audiences. It needs WordPress 6.3 and PHP 8.1 or newer.
Install the plugin
In your WordPress admin, open Plugins → Add New, search for LiftCanary, then install and activate it. You can also download the zip from the plugin directory and add it under Plugins → Add New → Upload Plugin.
Paste your SDK key
Open Settings → LiftCanary and paste the SDK key of the environment to use (LiftCanary → Install, the key starting with
pk_), then save. The snippet is now on every page; if LiftCanary doesn't know the key, the settings page warns you.Add the goals
In LiftCanary, add goals for the WooCommerce events below (Goals → New goal, “From your code”, with the event key), then use them in experiments. A test runs on your site as soon as you start it.
Settings#
| Setting | What it does |
|---|---|
| SDK key | The environment's key, starting with pk_. Leave it empty to turn the snippet off. |
| Hide the page until tests are applied | The anti-flicker style: no flash of the original page in no-code tests. On by default; the page always shows within 1.5 s. |
| Recognize logged-in users | Logged-in users are identified as wp:<user id>, so they keep their variation on every device. On by default. |
| Cookie consent | Whether to wait for the visitor's consent, and how. See below. |
| Report product views, add to cart, checkout and purchases | The WooCommerce goals. Shown when WooCommerce is active; on by default. |
| Orders | The connection key from LiftCanary → Integrations → WooCommerce: orders are then sent from your site as they're paid, change status or are refunded. See Orders from WooCommerce. |
| Your own domain, Proxy path | Serve the snippet, flags and events from your site, under /_lc by default. Off by default; see below. |
| Snippet URL, Events URL | Only for self-hosted LiftCanary. With your own domain on, the proxy forwards to them. Orders always go to the Events URL directly. |
| Cookie domain | For example .example.com: shares the visitor's anonymous id with your subdomains, such as a landing page and an app. |
The snippet loads early in <head> (wp_head, priority 1), never on admin pages, feeds, embeds or REST and AJAX answers. It also sets these attributes for audiences: wp_logged_in, wp_role, wp_post_type (on posts, pages and post type archives) and wp_language. Open any page with ?liftcanary_debug=1 to see them, and every decision, in the browser console.
WooCommerce events#
| Event key | When | Value |
|---|---|---|
purchase | The order confirmation page is shown, once per order; never for failed or cancelled orders | Order total |
begin_checkout | The checkout page opens with items in the cart | Cart total |
add_to_cart | A product is added to the cart, with AJAX or a classic form | Price × quantity |
product_view | A product page is viewed | Displayed price |
These are the same keys as in the Shopify app (which also reports add_payment_info), so goals work the same on both. Use purchase as a conversion goal for conversion rate, and as an average-per-visitor goal for revenue per visitor. Events carry source: "woocommerce" and currency, plus product_id, quantity, items or order_id where they apply.
The snippet sends them from the visitor's browser, so they count for the visitor who saw the test and follow your consent setting. The first time an order's confirmation page is shown, the order is marked (the _liftcanary_tracked meta, HPOS-compatible), so a reload or the link in the confirmation email counts nothing. An add to cart without AJAX is handed to the next page in the 10-minute liftcanary_wc cookie.
Orders from WooCommerce#
The purchase goal counts an order when its confirmation page shows. That's all a page can see: a bank transfer that is never paid, cash on delivery refused at the door, an order cancelled the next day or refunded a week later still count as sales, and an order whose confirmation page never loads (a payment page that doesn't send the customer back, a closed tab) doesn't count at all. WooCommerce knows what happens to each order, and the plugin sends it to LiftCanary from your server once it's connected: nothing to change in the theme.
Connect WooCommerce in LiftCanary
In LiftCanary, open Integrations, and under Store, WooCommerce: choose the environment whose SDK key is in the plugin, then Connect. LiftCanary shows a connection key starting with
lcwc_, once: copy it.Paste it into the plugin
In WordPress, open Settings → LiftCanary, paste the key under WooCommerce → Orders and save. The field then says when the last order was sent, or why LiftCanary refused it.
Add the goals
In Goals, choose New goal and one under From your store, then use it in experiments like any other goal.
| Goal | Event key | Counts | Measured as |
|---|---|---|---|
| Paid order | store.order_paid | An order whose payment went through: by card at checkout, a bank transfer once it's marked Processing, cash on delivery once it's Completed | Conversion rate |
| Store revenue | store.revenue | Each paid order's total, minus what is refunded or cancelled later, in part or in full | Value per visitor |
| Cancelled or refunded order | store.order_cancelled | An order cancelled or refunded in full, paid or not; a winner lowers it | Conversion rate |
At checkout, classic or block-based, the plugin saves the visitor's LiftCanary id on the order (the _liftcanary_id meta, from the liftcanary_anon cookie), so the order counts for the variation they saw however late it's paid. Then, whenever the order is paid, changes status or is refunded, it sends the order as it is: an order counts as paid once, with its total, and later its revenue follows what's left after refunds. WooCommerce marks cash on delivery Processing at checkout, before anyone has paid, so those orders count as paid once they're Completed. Payments, refunds and returns come days after the visit, so in the dashboard Paid order starts with 7 days of late conversions, and Store revenue and Cancelled or refunded order with 14 (see Goals). Keep purchase for what happens on the page; these goals are for what happens to the order.
Orders are sent in the background with Action Scheduler, which comes with WooCommerce, so checkout never waits for LiftCanary; when LiftCanary can't be reached, the plugin tries again for about 9 hours. The WooCommerce card under Integrations shows the last 7 days for each environment: how many order events arrived, how many found their visitor, and how many came from visitors who were in an experiment. Self-hosted or on your own data plane? Orders go to the plugin's Events URL (Advanced), never through the proxy. The liftcanary_send_order filter keeps orders out, such as those from a point of sale.
Cookie consent#
| Option | What happens |
|---|---|
| Don't wait | The default: the visitor's id is stored and events are sent right away. |
| Wait for consent from the WP Consent API | For banners that support the WP Consent API (Complianz, CookieYes and others). The snippet starts storing and sending once the visitor allows statistics, and stops if they withdraw it. |
| Wait until my banner calls liftcanary.consent(true) | For any other banner: call the code below when the visitor accepts. |
<script>
var lc = window.liftcanary; lc.consent ? lc.consent(true) : lc.q.push(["consent", true]);
</script>Until the visitor agrees, nothing is stored on their device and no events are sent; tests still run for each page view. The plugin describes its cookies to the WP Consent API, so banners list liftcanary_anon (2 years) and liftcanary_wc (10 minutes). See Consent.
Serving from your own domain#
Ad and tracker blockers block well-known testing domains. With Your own domain on, your site answers these paths and forwards them to LiftCanary, so far fewer visitors fall out of your tests:
| Path | What it serves |
|---|---|
/_lc/sdk/v1/*.js | The snippet |
/_lc/datafiles/*.json | Your flags and tests |
/_lc/geo | The visitor's country, for location conditions |
/_lc/editor/sessions/… | The visual editor |
/_lc/e/v1/batch | Events, forwarded to the collector |
Nothing else is forwarded: any other path gets a 404 without a request to LiftCanary. With plain permalinks the paths start with /index.php/_lc/, and a site in a subdirectory keeps its path. The visitor's address is passed on, and their location when Cloudflare, Vercel or CloudFront is in front of your site; cookies and Authorization headers never are. The snippet and datafiles are kept in a transient for up to 5 minutes, and page caches are told to skip all of it.
Each of these requests runs WordPress, so it costs a little server time. After turning it on, open the /_lc/geo link on the settings page: it should answer with your country, not "Page not found". If your web server answers .js and .json files itself, add an exception for the proxy path, or keep the option off. Keep the path neutral: blockers look for words like track, analytics or collect, and the settings page warns about them.
Your own PHP code#
To use the same flags in your theme or plugin code, install the PHP SDK (composer require liftcanary/liftcanary) and create logged-in users with the same id as the snippet, passing the liftcanary_anon cookie, so the browser and the server agree and results count one person:
$liftcanary = new LiftCanary\Client(getenv('LIFTCANARY_SDK_KEY'));
if (is_user_logged_in()) {
$user = $liftcanary->createUser('wp:' . get_current_user_id(), anonymousId: $_COOKIE['liftcanary_anon'] ?? null);
$newCheckout = $user->isEnabled('new_checkout');
}Filters change what the plugin outputs: liftcanary_enabled, liftcanary_script_attributes (to add data-spa, data-bucketing or data-debug), liftcanary_user_id, liftcanary_attributes, liftcanary_inline_js, liftcanary_track_add_to_cart, liftcanary_proxy_headers, liftcanary_proxy_upstreams and liftcanary_proxy_cache.
Privacy#
Visitors' browsers send exposures and goals (page, device and campaign attributes, and the order total and currency for purchases) under a random anonymous id, or as wp:<user id> for logged-in users when that setting is on. Emails, names and addresses are never sent, and the liftcanary_wc cookie holds only product ids, quantities, values and the currency. With orders connected, your server sends each order's ids, status, payment method, amounts, currency and dates, and the visitor's LiftCanary id saved at checkout: never names, emails, phone numbers or addresses. WooCommerce's "Remove personal data" removes that id from an order too. Saving a new SDK key checks it on cdn.liftcanary.com. Deleting the plugin removes its settings, the proxy's cached answers, the order marks and the ids saved on orders. Delete a visitor's data in LiftCanary under Project settings → A visitor's data.