Records a custom activity event for a contact. Activities appear in the contact’s activity log, can trigger activity-based benchmarks in funnels, and feed into Groundhogg’s reporting system. The $type is a slug you define — use a consistent, descriptive name like 'webinar_attended'. The $args array maps to database columns on the activity record; $details are stored as activity meta.
Parameters
| Parameter | Type | Description |
|---|---|---|
$contact | Contact|int|string | The contact to log activity for — accepts an object, ID, or email. |
$type | string | A slug identifying the activity type (e.g. 'webinar_attended'). |
$args | array | Additional database columns to save with the activity record (e.g. timestamp, value). |
$details | array | Arbitrary key/value pairs stored as activity meta. |
Return value
Activity|false — The created Activity object, or false on failure.
Usage
\Groundhogg\track_activity( $contact, 'webinar_attended' );
// With extra details
\Groundhogg\track_activity(
$contact,
'support_ticket_opened',
[ 'value' => 1 ],
[ 'ticket_id' => 1234 ]
);
Example
Here’s a pseudo code example for a hypothetical support helpdesk integration.
add_action( 'my_helpdesk_ticket_created', 'my_plugin_log_ticket_activity', 10, 2 );
/**
* Log a support ticket as contact activity in Groundhogg.
*
* @param int $ticket_id
* @param string $email
*
* @return void
*/
function my_plugin_log_ticket_activity( $ticket_id, $email ) {
$contact = \Groundhogg\get_contactdata( $email );
if ( ! $contact ) {
return;
}
\Groundhogg\track_activity(
$contact,
'support_ticket_opened',
[ 'value' => 1 ],
[
'ticket_id' => $ticket_id,
'ticket_url' => my_helpdesk_get_ticket_url( $ticket_id ),
]
);
}
Was this helpful?
Let us know if this document answered your question. That’s the only way we can improve.
