do_api_benchmark

📅 Published on

📝 Last updated

Documentation

»

Functions

»

do_api_benchmark

Triggers any funnel API Benchmark step that is listening for the given call name. This is the primary way to fire Groundhogg funnel triggers from your own plugin code — when a user completes a course, makes a purchase, or any other custom event. Any funnel with an API Benchmark step set to the matching call name will advance the contact automatically.

Parameters

ParameterTypeDescription
$call_namestringThe benchmark call name to trigger. Must match the value configured in the funnel’s API Benchmark step.
$id_or_emailstring|intThe contact’s email address or ID.
$by_user_idboolWhen true, treats $id_or_email as a WordPress user ID. Default false.

Return value

void —

Usage

// By email
\Groundhogg\do_api_benchmark( 'course_completed', 'jane@example.com' );

// By WordPress user ID
\Groundhogg\do_api_benchmark( 'course_completed', get_current_user_id(), true );

Example

Here’s a pseudo code example for a hypothetical LMS course completion integration.

add_action( 'my_lms_course_completed', 'my_plugin_trigger_course_benchmark', 10, 2 );

/**
 * Fire a Groundhogg API benchmark when a course is completed.
 *
 * @param int $user_id
 * @param int $course_id
 *
 * @return void
 */
function my_plugin_trigger_course_benchmark( $user_id, $course_id ) {

    // Call name must match the API Benchmark step in the Groundhogg funnel builder
    \Groundhogg\do_api_benchmark( 'course_completed_' . $course_id, $user_id, true );
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.