WordPress & WooCommerce
Install the Lapis pixel in your theme or a snippets plugin, persist the click ID to WooCommerce orders, and send events from a hook.
On WordPress, the pixel goes in the theme footer (or a code-snippets plugin), and WooCommerce gives you clean server-side hooks for order conversions.
1. Install the pixel
Option A, snippets plugin (recommended): with WPCode or Code Snippets, add a site-wide footer HTML snippet:
<script
src="https://cdn.trylapis.com/pixel/v1/lapis-pixel.js"
data-key="pk_YOUR_PIXEL_KEY"
></script>
Option B, child theme: add it to footer.php before </body>, or via a hook in functions.php:
add_action('wp_footer', function () {
echo '<script src="https://cdn.trylapis.com/pixel/v1/lapis-pixel.js" data-key="pk_YOUR_PIXEL_KEY"></script>';
});
2. WooCommerce: persist the click ID to the order
Capture the cookie’s sid into the WooCommerce session, then copy it onto the order at checkout:
// functions.php or a small plugin
// Capture on every page load (cookie is first-party, set by the pixel)
add_action('init', function () {
if (isset($_COOKIE['lapis_sid']) && function_exists('WC') && WC()->session) {
$decoded = json_decode(urldecode($_COOKIE['lapis_sid']), true);
if (!empty($decoded['sid'])) {
WC()->session->set('lapis_click_id', sanitize_text_field($decoded['sid']));
}
}
});
// Copy onto the order when it is created
add_action('woocommerce_checkout_create_order', function ($order) {
if (function_exists('WC') && WC()->session) {
$click_id = WC()->session->get('lapis_click_id');
if ($click_id) {
$order->update_meta_data('_lapis_click_id', $click_id);
}
}
});
3. Send the conversion server-side
Fire on payment completion:
add_action('woocommerce_payment_complete', function ($order_id) {
$order = wc_get_order($order_id);
$click_id = $order->get_meta('_lapis_click_id');
if (!$click_id) return; // organic order, so skip
wp_remote_post('https://api.trylapis.com/api/v1/pixel/server-events', [
'headers' => [
'Authorization' => 'Bearer ' . LAPIS_SERVER_EVENT_KEY, // define in wp-config.php
'Content-Type' => 'application/json',
],
'body' => wp_json_encode([
'event_id' => 'order_created:' . $order_id,
'event_type' => 'order_created',
'lapis_click_id' => $click_id,
'value' => (float) $order->get_total(),
'currency' => $order->get_currency(),
'properties' => ['order_number' => $order->get_order_number()],
]),
'timeout' => 10,
]);
});
Define the key in wp-config.php, never in the theme:
define('LAPIS_SERVER_EVENT_KEY', 'sk_live_...');
WordPress-specific notes
- Caching plugins (WP Rocket, W3TC) do not interfere, because the pixel is a static script tag and the cookie logic runs client-side. If you use their “delay JavaScript” features, exclude
lapis-pixel.jsfrom the delay so the landing session is created immediately. - Lead-gen WordPress (Contact Form 7, Gravity Forms, WPForms): use the hidden-field pattern from the Webflow guide. All three plugins support hidden fields with dynamically populated values. Send
lead_createdfrom the form’s submission hook. - Event IDs keyed to
$order_idmake WooCommerce’s occasional double-fired hooks harmless.