LifterLMS Google Analytics: GA4 Events for Enrollments and Sales
Track LifterLMS purchases, renewals, sign-ups and course completions in Google Analytics 4. Choose between a plugin and custom events, plan your…
Read articleIf 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.
| Meta Pixel | Conversions API | |
|---|---|---|
| Runs in | The visitor's browser | Your server |
| Blocked by ad blockers and browser privacy features | Often | No |
| Sees cookies, page URL and browser automatically | Yes | Only what you send it |
| Setup effort | Low | Moderate: 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.
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:
is_singular( array( 'course', 'llms_membership' ) )), so Meta can build audiences of people who viewed a course.is_llms_checkout().If cookie consent applies to your visitors, load the Pixel only after consent. More on that below.
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:
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.
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.
'test_event_code' => 'TEST12345' to the top level of the CAPI request body on staging.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.
No official one. Use custom code built on LifterLMS's order-complete redirect, or, if you sell through WooCommerce, a WooCommerce Pixel plugin.
Not strictly, but browser blocking means the Pixel alone misses sales. Sending both with matching event IDs gives Meta a fuller picture.
No. The server event is queued and sent in the background by Action Scheduler, which LifterLMS bundles.
Yes. Send a Lead or CompleteRegistration event instead of Purchase for free enrollments.
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.
Track LifterLMS purchases, renewals, sign-ups and course completions in Google Analytics 4. Choose between a plugin and custom events, plan your…
Read article
There is no official LifterLMS HubSpot add-on. Compare the three working routes, WP Fusion, Zapier and a custom API integration, see what each syncs…
Read article
Set up the LifterLMS WPForms add-on to require lesson forms and replace registration forms, understand what WPForms Lite and Pro change, and use…
Read articleSkip the trial and error. Get specialist LifterLMS help and ship faster.