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

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 event | Tutor LMS hook |
|---|---|
course_enroll | tutor_after_enroll / tutor_after_enrolled |
lesson_complete | tutor_lesson_completed_after |
quiz_finished | tutor_quiz_finished |
course_complete | tutor_course_complete_after |
purchase | tutor_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.
Consent and privacy
- 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.
