Integrations

How to Add Tutor LMS Events to Google Analytics 4

Track enrollments, lesson and course completions and purchases in GA4: what Tutor LMS does not send by default, server-side events with the Measurement Protocol, and consent.

Checked against the plugin source: Tutor LMS 4.1.3, Tutor LMS Pro 4.1.3

How to Add Tutor LMS Events to Google Analytics 4

A standard GA4 tag records page views, but not the moments that matter on a course site: enrolling, finishing a lesson, completing a course or paying. Tutor LMS 4.1.3 does not send these to GA4 itself, so you add them from its hooks.

Which events to track

GA4 eventTutor LMS hook
course_enrolltutor_after_enroll / tutor_after_enrolled
lesson_completetutor_lesson_completed_after
quiz_finishedtutor_quiz_finished
course_completetutor_course_complete_after
purchasetutor_order_payment_status_changed (native eCommerce)

Mark course_enroll and purchase as key events in GA4 to use them in reports and ads.

Why server-side

Many of these happen in requests the visitor never sees as a page view: payment webhooks, AJAX completions and redirects. Sending them from the server with GA4's Measurement Protocol catches them reliably.

Example: send course completion to GA4

add_action( 'tutor_course_complete_after', 'tle_ga4_course_complete', 20, 2 );

function tle_ga4_course_complete( $course_id, $user_id ) {
	tle_ga4_send( 'course_complete', array(
		'course_id'    => (int) $course_id,
		'course_title' => get_the_title( $course_id ),
	) );
}

function tle_ga4_send( $event, array $params ) {
	if ( ! defined( 'TLE_GA4_ID' ) || ! defined( 'TLE_GA4_SECRET' ) ) {
		return;
	}
	// Reuse the visitor's GA client ID when the request comes from their browser.
	$client_id = '';
	if ( isset( $_COOKIE['_ga'] ) && preg_match( '/GA\d\.\d\.(\d+\.\d+)$/', sanitize_text_field( wp_unslash( $_COOKIE['_ga'] ) ), $m ) ) {
		$client_id = $m[1];
	}
	if ( '' === $client_id ) {
		$client_id = wp_rand() . '.' . time(); // Server-only event: a fresh ID.
	}

	wp_remote_post(
		'https://www.google-analytics.com/mp/collect?measurement_id=' . rawurlencode( TLE_GA4_ID ) . '&api_secret=' . rawurlencode( TLE_GA4_SECRET ),
		array(
			'timeout'  => 3,
			'blocking' => false,
			'body'     => wp_json_encode( array(
				'client_id' => $client_id,
				'events'    => array( array( 'name' => $event, 'params' => $params ) ),
			) ),
		)
	);
}

Create the API secret in GA4 under the data stream's Measurement Protocol settings, and define TLE_GA4_ID and TLE_GA4_SECRET in wp-config.php.

Purchases

For native eCommerce, send a purchase event when an order becomes paid, with the order ID as transaction_id, the total and currency, and the courses as items. See running code when an order is paid. For WooCommerce, use a WooCommerce GA4 integration instead, so purchases are not counted twice.

  • Where consent is required, only send events for visitors who accepted analytics.
  • Do not send names or email addresses to GA4. IDs and course titles are enough.

Check it works

Use GA4's DebugView (add debug_mode to params while testing) and complete a test course.

Need learning analytics you can act on? Our reporting and analytics team can set it up.

Save this practical guide

Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.

Vishavjeet
· Enterprise LMS Architect | WordPress & LMS Expert | WooCommerce | AI Automation

I’m Vishavjeet Choubey, an Enterprise LMS Architect with 10+ years of experience helping businesses, coaches, universities, and online academies build and scale powerful digital learning platforms. I specialize in enterprise LMS architecture, WordPress, WooCommerce, LifterLMS, LearnDash, Moodle, custom plugin development, and AI-driven automation. I build scalable LMS platforms, high-converting eCommerce solutions, and custom WordPress applications designed to improve user experiences, streamline operations, and drive measurable business growth. My approach combines deep WordPress and LMS engineering expertise with modern AI automation to reduce manual work, improve efficiency, and help organizations launch, scale, and grow faster.

Keep reading

Need a custom Tutor LMS solution?

Tell us what you are building or what is broken. A Tutor LMS developer reads every inquiry and replies with next steps and a free estimate.

Get a free Tutor LMS consultation

Tell us what you are building or fixing. A Tutor LMS developer replies with honest advice and next steps.

  • No obligation
  • Tutor LMS and Pro specialists
  • Your details stay private

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.