\Groundhogg\Event

📅 Published on

📝 Last updated

Documentation

»

Classes

»

\Groundhogg\Event

extends Base_Object

Represents a single scheduled event in the Groundhogg event queue. Every time a contact moves through a funnel step, an event record is created to track it. Events have a status lifecycle: waiting → in_progress → complete (or failedskippedcancelledpaused).

Methods

MethodReturnsDescription
get_id()intReturns the event ID.
get_contact_id()intReturns the contact ID this event is for.
get_contact()ContactReturns the Contact object.
get_step_id()intReturns the step ID associated with this event.
get_step()StepReturns the Step object.
get_funnel_id()intReturns the funnel ID, or 0 for standalone events.
get_funnel()Funnel|falseReturns the Funnel object, or false for standalone events.
get_email()Email|falseReturns the Email object if this is an email event.
get_time()intReturns the scheduled Unix timestamp.
get_status()stringReturns the current status string.
get_failure_reason()stringReturns the human-readable failure reason if the event failed.
get_error_code()stringReturns the error code if the event failed.
get_error_message()stringReturns the error message if the event failed.
is_waiting()boolReturns true if the event is waiting to be processed.
is_complete()boolReturns true if the event completed successfully.
is_time()boolReturns true if the scheduled time has passed and the event is ready to run.
is_funnel_event()boolReturns true if this event is part of a funnel.
is_broadcast_event()boolReturns true if this event is part of a broadcast.
run()bool|WP_ErrorExecutes the event immediately. Returns true on success.
queue()boolSets the event status to waiting.
cancel()boolCancels the event.
skip( $args = [] )boolMarks the event as skipped and advances the contact.
fail()boolMarks the event as failed.
complete()boolMarks the event as complete.
pause()boolPauses the event.
in_progress()boolMarks the event as in-progress.
get_arg( string $arg, $default = false )mixedReturns a named arg attached to this event (see add_event_args()).
set_args( array $args )boolSets all args on this event at once.

Usage

Here’s a pseudo code example for a hypothetical event monitoring integration.

<?php

add_action( 'groundhogg/event/failed', 'my_plugin_handle_failed_event' );

/**
 * Alert the funnel owner when an event fails.
 *
 * @param \Groundhogg\Event $event
 *
 * @return void
 */
function my_plugin_handle_failed_event( $event ) {

    $contact = $event->get_contact();
    $step    = $event->get_step();

    if ( ! $contact || ! $step ) {
        return;
    }

    $funnel = $step->get_funnel();
    $owner  = \Groundhogg\get_primary_owner();

    if ( ! $owner ) {
        return;
    }

    \Groundhogg\gh_mail(
        $owner->user_email,
        'Funnel event failed',
        sprintf(
            'Event for %s failed at step "%s" in funnel "%s". Reason: %s',
            $contact->get_email(),
            $step->get_title(),
            $funnel ? $funnel->get_title() : 'unknown',
            $event->get_failure_reason()
        )
    );
}

Was this helpful?

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