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 event names, and use tested code for the purchase event and server-side renewals.

  • Add as a preferred source on Google
Illustration for “LifterLMS Google Analytics: GA4 Events for Enrollments and Sales”

LifterLMS tells you who enrolled and who finished. Google Analytics 4 tells you where they came from. Without the second half you cannot say which ad, article or email produced a sale, so you end up guessing where to spend your marketing budget.

Adding the GA4 tag to your site records page views, but not LifterLMS sales or learning events. This guide shows how to get proper LifterLMS Google Analytics tracking: a GA4 purchase event with real revenue, renewals sent from the server, and custom events for enrollments and course completions. It is written for site owners and the developers who implement tracking for them.

There are two ways to do it: a plugin that adds e-commerce tracking for LifterLMS, or a small custom plugin built on LifterLMS hooks. Both are covered, with code for the custom route.

What LifterLMS reports and what GA4 adds

QuestionWhere to answer it
How many students enrolled, completed or are stuck?LifterLMS reporting
How much revenue came in this month?LifterLMS reporting and your payment gateway
Which traffic source or campaign produced the sales?GA4, with purchase events
How many visitors reached checkout but did not buy?GA4, with checkout and purchase events
Which blog posts lead to free course sign-ups?GA4, with a sign-up or enrollment event

For the LifterLMS side, see our guide to LifterLMS reporting and student progress. This article is about the GA4 side.

Option 1: a plugin with LifterLMS e-commerce tracking

Two analytics plugins list LifterLMS support. Both are third-party and paid for the LifterLMS features.

  • MonsterInsights. Its eCommerce addon lists LifterLMS among supported platforms and requires a Pro plan or above. It adds purchase tracking and an eCommerce report inside WordPress. Our MonsterInsights and LifterLMS guide covers it in detail.
  • Analytify. Analytify Pro has a LifterLMS addon that tracks course views, enrollments, purchases, refunds and coupon use in GA4.

Choose a plugin when you want tracking working this week and are happy with the events it decides to send. Choose custom events when you need specific event names, server-side renewals, a tag manager setup, or tracking that matches other systems.

Option 2: plan your own GA4 events

Start with a short event plan. GA4 has recommended event names for common actions, and using them gets you built-in reports.

LifterLMS momentGA4 eventWhere to send it from
Visitor reaches the checkout pagebegin_checkoutBrowser, on the checkout page (is_llms_checkout())
Account createdsign_upBrowser, after lifterlms_user_registered
First payment succeedspurchaseBrowser, on the page after checkout
Renewal payment succeedspurchase (or a custom renewal)Server, Measurement Protocol
Free enrollmentCustom, e.g. course_enrollBrowser or server
Course completedCustom, e.g. course_completeServer, from lifterlms_course_completed

Mark purchase and any free sign-up event as key events in GA4 so they appear in acquisition reports.

The purchase event on the order-complete page

After a successful checkout, LifterLMS redirects the buyer. The destination is the access plan's checkout redirect if one is set, otherwise the course or membership page. LifterLMS adds the order key to that URL as ?order-complete=. That parameter is the reliable place to fire the browser-side purchase event.

The snippet below assumes the GA4 tag (gtag.js) is already on the site. It looks up the order, checks it belongs to the logged-in user, reads the amount of the most recent successful transaction, and prints the event once per order:

add_action( 'wp_footer', 'llmsx_ga4_purchase_event' );

function llmsx_ga4_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_ga4_sent', true ) ) {
		return; // Already tracked, e.g. the page was reloaded.
	}

	$txn   = $order->get_last_transaction( 'llms-txn-succeeded' );
	$value = $txn ? (float) $txn->get( 'amount' ) : 0.0;

	$data = array(
		'transaction_id' => (string) $order_id,
		'value'          => $value,
		'currency'       => $order->get( 'currency' ),
		'coupon'         => $order->get( 'coupon_code' ),
		'items'          => array(
			array(
				'item_id'      => (string) $order->get( 'product_id' ),
				'item_name'    => get_the_title( $order->get( 'product_id' ) ),
				'item_variant' => $order->get( 'plan_title' ),
				'price'        => $value,
				'quantity'     => 1,
			),
		),
	);

	update_post_meta( $order_id, '_llmsx_ga4_sent', time() );

	printf(
		'<script>window.gtag && gtag("event", "purchase", %s);</script>',
		wp_json_encode( $data )
	);
}

Notes on this approach:

  • Use the transaction amount, not the plan price. With a trial, coupon or sale, the first charge differs from the plan's list price.
  • Use the order ID as transaction_id. GA4 uses it to drop duplicates, and you can match it to the order in LifterLMS.
  • Off-site redirects. If an access plan redirects to another domain after checkout, this snippet will not run there. Track on that site, or use the server-side method for every purchase.
  • Free orders. A free plan produces a value of 0. Send a separate enrollment event for those instead of a zero-value purchase if you prefer cleaner revenue reports.

Renewals and completions from the server

Recurring payments are charged in the background by scheduled actions, with no browser involved. To get renewals into GA4, send them with the GA4 Measurement Protocol. You need a Measurement Protocol API secret, created in GA4 under Admin, Data streams, your web stream, then Measurement Protocol API secrets. Google's Measurement Protocol guide covers the request format.

Measurement Protocol events need a client_id, which should match the browser's GA client ID so the renewal joins the same user. Store it at purchase time from the _ga cookie, then reuse it for renewals:

// Save the GA client ID when a plan is purchased in the browser.
add_action( 'lifterlms_access_plan_purchased', 'llmsx_ga4_store_client_id', 10, 1 );

function llmsx_ga4_store_client_id( $user_id ) {
	if ( empty( $_COOKIE['_ga'] ) ) {
		return;
	}
	$parts = explode( '.', sanitize_text_field( wp_unslash( $_COOKIE['_ga'] ) ) );
	if ( count( $parts ) >= 4 ) {
		update_user_meta( $user_id, 'llmsx_ga_client_id', $parts[2] . '.' . $parts[3] );
	}
}

// Send renewals (second and later successful payments) to GA4.
add_action( 'lifterlms_transaction_status_succeeded', 'llmsx_ga4_track_renewal', 10, 1 );

function llmsx_ga4_track_renewal( $txn ) {
	$order = $txn->get_order();
	if ( ! $order || ! defined( 'LLMSX_GA4_ID' ) || ! defined( 'LLMSX_GA4_SECRET' ) ) {
		return;
	}

	$paid = $order->get_transactions( array( 'status' => 'llms-txn-succeeded', 'per_page' => 1 ) );
	if ( $paid['total'] < 2 ) {
		return; // First payment: tracked in the browser.
	}

	$user_id   = (int) $order->get( 'user_id' );
	$client_id = get_user_meta( $user_id, 'llmsx_ga_client_id', true );
	$client_id = $client_id ? $client_id : 'llms.' . $user_id;

	$body = array(
		'client_id' => $client_id,
		'user_id'   => (string) $user_id,
		'events'    => array(
			array(
				'name'   => 'purchase',
				'params' => array(
					'transaction_id' => $order->get( 'id' ) . '-' . $txn->get( 'id' ),
					'value'          => (float) $txn->get( 'amount' ),
					'currency'       => $txn->get( 'currency' ),
					'renewal'        => 'yes',
				),
			),
		),
	);

	wp_remote_post(
		add_query_arg(
			array(
				'measurement_id' => LLMSX_GA4_ID,
				'api_secret'     => LLMSX_GA4_SECRET,
			),
			'https://www.google-analytics.com/mp/collect'
		),
		array(
			'timeout'  => 5,
			'blocking' => false,
			'headers'  => array( 'Content-Type' => 'application/json' ),
			'body'     => wp_json_encode( $body ),
		)
	);
}

Define LLMSX_GA4_ID (your G- measurement ID) and LLMSX_GA4_SECRET in wp-config.php. Keep the secret on the server; anyone who has it can send data to your property. Only send a user_id if your privacy notice covers it.

The same pattern sends a course_complete event from lifterlms_course_completed, which passes the student ID and course ID. Our LifterLMS hooks and filters guide lists the other learning events you can use.

  • Consent. In the UK and EU, analytics cookies usually need consent. If you use Google consent mode, browser events respect it. Server-side events do not check consent by themselves, so only send them for users whose consent you have recorded. See LifterLMS and GDPR.
  • Ad blockers. Some browsers block GA entirely, so GA4 revenue will be lower than LifterLMS revenue. Treat GA4 for attribution and LifterLMS for the true totals.
  • Refunds. GA4 has a refund event. If refunds are common, send one from lifterlms_transaction_status_refunded with the same transaction_id.
  • Currency. Always send currency with value, or GA4 ignores the revenue.

Troubleshooting

  • No purchase events at all. Check the redirect URL after a test purchase includes order-complete=. If the plan redirects off-site, the browser event cannot fire on your site.
  • Purchases counted twice. A plugin and custom code are both sending them. Pick one.
  • Events in DebugView but not in reports. Standard reports can take a day or more to update. Use DebugView and Realtime for testing.
  • Renewals with no source. The client ID was not captured at purchase, so GA4 sees a new user. Check the _ga cookie exists when checkout completes.
  • Cached pages. If your page cache serves the post-checkout page, the event may not print. Logged-in users should bypass page cache.

Frequently asked questions

Does LifterLMS integrate with Google Analytics by itself?

No. LifterLMS has no built-in GA4 integration. Add the GA4 tag, then send events with a plugin such as MonsterInsights or Analytify, or with custom code.

Can I use Google Tag Manager instead of gtag?

Yes. Push the same data to the dataLayer instead of calling gtag, and build the GA4 event tag in Tag Manager.

Why does GA4 show less revenue than LifterLMS?

Ad blockers, missing consent, refunds and renewals that are not sent all lower the GA4 figure. LifterLMS and your gateway remain the source of truth for revenue.

Should course completions go to GA4?

If you want to compare traffic sources by learner success, yes. Send a custom event and register any parameters you report on as custom dimensions.

What to do next

Write your event plan first, then decide between a plugin and custom events. If attribution of course sales is the main goal, the purchase event on the order-complete page gets you most of the value in an afternoon. Add renewals and completions once that is trusted.

If you want tracking built properly, with server-side events, consent handling and checks that it keeps working, our LifterLMS integrations service can implement and test it. Tell us what you need to measure and we will propose an event plan.

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