LifterLMS Facebook Pixel and Conversions API for Course Sales

Send accurate Purchase events for LifterLMS course sales to Meta: the Pixel in the browser, the Conversions API from the server, matching event IDs for deduplication, and the privacy and testing steps that keep ad data trustworthy.

  • Add as a preferred source on Google
Illustration for “LifterLMS Facebook Pixel and Conversions API for Course Sales”

If you run Facebook or Instagram ads for your courses, Meta needs to know which clicks turned into sales. Without a Purchase event, the ad platform optimises for clicks and page views, and your cost per sale goes up.

This guide is for course businesses running Meta ads and the developers who implement their tracking. It covers LifterLMS Facebook Pixel tracking end to end: the base Pixel, a Purchase event fired after a LifterLMS checkout, the Conversions API (CAPI) sending the same event from your server, and the deduplication that stops Meta counting each sale twice.

At the time of writing, the popular WordPress Pixel plugins we checked, including PixelYourSite, list WooCommerce and Easy Digital Downloads e-commerce support but not LifterLMS. If you sell through native LifterLMS checkout, plan on a small custom integration for purchase events. If you sell through the LifterLMS WooCommerce add-on, a WooCommerce Pixel plugin will see the WooCommerce order.

Pixel, Conversions API, or both

Meta PixelConversions API
Runs inThe visitor's browserYour server
Blocked by ad blockers and browser privacy featuresOftenNo
Sees cookies, page URL and browser automaticallyYesOnly what you send it
Setup effortLowModerate: an access token and server code

Meta recommends using both, with the same event ID on each copy of an event so it keeps one. That is the setup this guide builds.

Step 1: install the base Pixel

Add the Meta Pixel base code to every page, either through a header-scripts plugin, your theme's tracking field, or Google Tag Manager. That gives you PageView events and makes the fbq function available for the Purchase event below.

Two optional events are worth adding with very little effort:

  • ViewContent on course and membership sales pages (is_singular( array( 'course', 'llms_membership' ) )), so Meta can build audiences of people who viewed a course.
  • InitiateCheckout on the LifterLMS checkout page, which you can detect with is_llms_checkout().

If cookie consent applies to your visitors, load the Pixel only after consent. More on that below.

Step 2: fire Purchase after a LifterLMS checkout

When a LifterLMS checkout succeeds, the buyer is redirected to the access plan's checkout redirect, or to the course or membership page if none is set. LifterLMS adds the order key to that URL as ?order-complete=. That is where the browser Purchase event belongs, and the same request is a good moment to queue the server copy.

add_action( 'wp_footer', 'llmsx_meta_purchase_event' );

function llmsx_meta_purchase_event() {
	if ( empty( $_GET['order-complete'] ) || ! is_user_logged_in() ) {
		return;
	}

	$order = llms_get_order_by_key( sanitize_text_field( wp_unslash( $_GET['order-complete'] ) ) );
	if ( ! $order || (int) $order->get( 'user_id' ) !== get_current_user_id() ) {
		return;
	}

	$order_id = $order->get( 'id' );
	if ( get_post_meta( $order_id, '_llmsx_meta_sent', true ) ) {
		return;
	}
	update_post_meta( $order_id, '_llmsx_meta_sent', time() );

	$txn      = $order->get_last_transaction( 'llms-txn-succeeded' );
	$event_id = 'llms-order-' . $order_id;
	$custom   = array(
		'value'        => $txn ? (float) $txn->get( 'amount' ) : 0.0,
		'currency'     => $order->get( 'currency' ),
		'content_ids'  => array( (string) $order->get( 'product_id' ) ),
		'content_name' => get_the_title( $order->get( 'product_id' ) ),
		'content_type' => 'product',
	);

	// Queue the server-side copy with the browser details Meta uses for matching.
	as_enqueue_async_action(
		'llmsx_meta_capi_purchase',
		array(
			array(
				'order_id' => $order_id,
				'event_id' => $event_id,
				'custom'   => $custom,
				'url'      => get_permalink( get_queried_object_id() ),
				'ip'       => sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ?? '' ) ),
				'ua'       => sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? '' ) ),
				'fbp'      => sanitize_text_field( wp_unslash( $_COOKIE['_fbp'] ?? '' ) ),
				'fbc'      => sanitize_text_field( wp_unslash( $_COOKIE['_fbc'] ?? '' ) ),
			),
		),
		'llmsx'
	);

	printf(
		'<script>window.fbq && fbq("track", "Purchase", %s, %s);</script>',
		wp_json_encode( $custom ),
		wp_json_encode( array( 'eventID' => $event_id ) )
	);
}

Why these choices:

  • The transaction amount is what was actually charged, which differs from the plan price with trials, coupons and sales.
  • The order ID in the event ID makes it unique per sale and identical in the browser and server copies.
  • The ownership check stops anyone who obtains an order key from triggering events for someone else's order.
  • The meta flag stops a page reload from sending a second Purchase.

Step 3: send the same event with the Conversions API

Create a Conversions API access token for your Pixel in Meta Events Manager, then define LLMSX_META_PIXEL_ID and LLMSX_META_TOKEN in wp-config.php. The background job below sends the event to the Graph API /events endpoint for your Pixel:

add_action( 'llmsx_meta_capi_purchase', 'llmsx_meta_capi_send_purchase', 10, 1 );

function llmsx_meta_capi_send_purchase( $args ) {
	$order = llms_get_post( absint( $args['order_id'] ) );
	if ( ! $order || ! defined( 'LLMSX_META_PIXEL_ID' ) || ! defined( 'LLMSX_META_TOKEN' ) ) {
		return;
	}

	$user_data = array(
		'em'                => array( hash( 'sha256', strtolower( trim( $order->get( 'billing_email' ) ) ) ) ),
		'external_id'       => array( hash( 'sha256', (string) $order->get( 'user_id' ) ) ),
		'client_ip_address' => $args['ip'],
		'client_user_agent' => $args['ua'],
	);
	if ( $args['fbp'] ) {
		$user_data['fbp'] = $args['fbp'];
	}
	if ( $args['fbc'] ) {
		$user_data['fbc'] = $args['fbc'];
	}

	$body = array(
		'data'         => array(
			array(
				'event_name'       => 'Purchase',
				'event_time'       => time(),
				'event_id'         => $args['event_id'],
				'event_source_url' => $args['url'],
				'action_source'    => 'website',
				'user_data'        => $user_data,
				'custom_data'      => $args['custom'],
			),
		),
		'access_token' => LLMSX_META_TOKEN,
	);

	$response = wp_remote_post(
		'https://graph.facebook.com/v25.0/' . rawurlencode( LLMSX_META_PIXEL_ID ) . '/events',
		array(
			'timeout' => 15,
			'headers' => array( 'Content-Type' => 'application/json' ),
			'body'    => wp_json_encode( $body ),
		)
	);

	$code = wp_remote_retrieve_response_code( $response );
	if ( is_wp_error( $response ) || 200 !== $code ) {
		throw new Exception( 'Meta CAPI failed for order ' . $args['order_id'] );
	}
}

Meta updates the Graph API version regularly. Check the current version in the Conversions API documentation and update the URL when you maintain the site. A failed send throws an exception, so it shows as failed under LifterLMS > Status > Scheduled Actions instead of disappearing silently.

How deduplication works

Meta keeps one event when a browser event and a server event arrive with the same event name and the same ID. In the Pixel the parameter is eventID; in the Conversions API it is event_id. Meta deduplicates within 48 hours of receiving the first event with that ID. The details are in Meta's guide to handling duplicate Pixel and Conversions API events.

If you see roughly twice as many purchases in Events Manager as in LifterLMS, the IDs do not match. Check both copies show the same llms-order- value.

Testing before you trust it

  1. In Events Manager, open your Pixel's Test Events tab and copy the test code.
  2. Temporarily add 'test_event_code' => 'TEST12345' to the top level of the CAPI request body on staging.
  3. Make a purchase with a 100% coupon or your gateway's test mode, then confirm a browser and a server Purchase appear and are marked as deduplicated.
  4. Remove the test code before going live.

Keep staging from sending live data to Meta. A cloned site with production tokens will report fake sales. Our guide to LifterLMS staging sites covers what else to switch off on a copy.

  • Consent first. Where cookie consent is required, do not load the Pixel or send server events for visitors who have not agreed to marketing tracking. Server-side sending is not a way around consent rules.
  • Hash identifiers. Email addresses and external IDs must be normalised and SHA-256 hashed before sending, as in the code above.
  • Send only what you need. Course purchases can reveal sensitive interests, for example health or religion courses. Consider sending a generic content name for those.
  • Update your privacy notice to name Meta as a recipient. Our LifterLMS GDPR guide covers the rest.

Common mistakes

  • Purchase on the checkout page. Firing on page load of checkout counts every visit as a sale. Fire only on the order-complete redirect.
  • Plan price instead of amount charged. Trials and coupons make that wrong. Use the transaction amount.
  • Plan redirects to another domain. The snippet only runs on your WordPress site. If the access plan sends buyers elsewhere, move tracking there or keep the redirect on-site.
  • Renewals as new purchases. Meta optimises for acquisition. Leave renewals out of Purchase unless you have a reason to include them.
  • Page cache on the redirect page. Logged-in users must bypass page cache, or the event will not print.

Frequently asked questions

Is there a LifterLMS Facebook Pixel add-on?

No official one. Use custom code built on LifterLMS's order-complete redirect, or, if you sell through WooCommerce, a WooCommerce Pixel plugin.

Do I need the Conversions API if I have the Pixel?

Not strictly, but browser blocking means the Pixel alone misses sales. Sending both with matching event IDs gives Meta a fuller picture.

Will this slow down checkout?

No. The server event is queued and sent in the background by Action Scheduler, which LifterLMS bundles.

Can I track free course sign-ups for ads?

Yes. Send a Lead or CompleteRegistration event instead of Purchase for free enrollments.

What to do next

Install the base Pixel, add the Purchase event on the order-complete redirect, and test it with Test Events. Add the Conversions API copy once the browser event is right. Then compare Meta's purchase count with LifterLMS orders for a week. Some difference is normal; a large one points to a setup problem. Our GA4 tracking guide uses the same approach if you want Google Analytics to match.

If you want this implemented, tested and kept working through Meta's API changes, our LifterLMS integrations service can handle it. Tell us which ad platforms you use and we will scope the tracking.

Add LifterLMS Expert to your preferred sources

Add lifterlmsexpert.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

  • Add as a preferred source on Google
Free consultation

Prefer expert help over DIY?

Skip the trial and error. Get specialist LifterLMS help and ship faster.

Talk to a LifterLMS Expert Explore our services

Replies within one business day