Fluentcrm event tracking

From Lonsdale201/wp-agent-skills · View interactive version

Fluentcrm event tracking is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Track and consume FluentCRM 3.x contact events from companion plugins. Covers the experimental event_tracking flag, the track method of FluentCrmApi('event_tracker'), fc_event_tracking, repeatable counter semantics, subscriber resolution by subscriber/email/user/current contact, fluent_crm/event_tra

How to use this skill

Skill file

FluentCRM: event tracking

Use this skill when a plugin wants to record product usage, LMS actions, purchase milestones, profile events, or any other contact activity into FluentCRM's event timeline and Pro automation conditions.

Guard the feature

Event tracking is core FluentCRM code, but it is disabled by default behind the experimental setting:

use FluentCrm\App\Services\Helper;

if (!function_exists('FluentCrmApi') || !Helper::isExperimentalEnabled('event_tracking')) {
    return;
}

FluentCrmApi('event_tracker')->track() returns WP_Error('not_enabled', ...) when the flag is off. Always handle WP_Error.

Track an event

The API key is event_tracker:

$event = FluentCrmApi('event_tracker')->track([
    'subscriber_id' => (int) $contactId,       // preferred when known
    'provider'      => 'my-plugin',
    'event_key'     => 'course_completed',
    'title'         => 'Course completed',
    'value'         => (string) $courseId,
], true);

if (is_wp_error($event)) {
    return;
}

Subscriber resolution order in Tracker::track():

Required fields are event_key and title. Both are truncated to 192 characters and sanitized. provider defaults to custom; value is sanitized as textarea text.

Repeatable vs append-only

Second argument controls storage behavior:

FluentCrmApi('event_tracker')->track($data, true);  // repeatable/default
FluentCrmApi('event_tracker')->track($data, false); // append a new row every time

With $repeatable = true, FluentCRM looks up an existing row by (subscriber_id, event_key, title), updates value, increments counter, saves, and fires fluent_crm/event_tracked.

With $repeatable = false, it creates a new fc_event_tracking row every time and fires the same action.

There is no unique DB key for the repeatable lookup in 3.1.13; the counter is application-level, not an atomic financial counter. Use it for automation/activity state, not exact billing/accounting.

Action bridge

EventTrackingHandler also registers:

do_action('fluent_crm/track_event_activity', $data, $repeatable);

That delegates to FluentCrmApi('event_tracker')->track(), but do_action() discards the return value. Use the API method directly when you need the created EventTracker or WP_Error.

Event hook

Every successful track fires:

add_action('fluent_crm/event_tracked', function ($event, $subscriber) {
    // $event is FluentCrm\App\Models\EventTracker
    // $subscriber is FluentCrm\App\Models\Subscriber
}, 10, 2);

FluentCampaign Pro's "Tracking Event Recorded" trigger listens to this exact hook with actionArgNum = 2.

Pro automation trigger and action

Pro trigger: FluentCampaign\App\Services\Funnel\Triggers\TrackingEventRecordedTrigger

Pro action: FluentCampaign\App\Services\Funnel\Actions\AddEventTrackerAction

If you build a custom trigger/action around event tracking, still follow fluentcrm-funnel-trigger and fluentcrm-funnel-action for lifecycle and status rules.

Contact filters and option source

EventTrackingHandler registers the advanced contact filter provider:

fluentcrm_contacts_filter_event_tracking

Supported filter properties in 3.1.13:

The built-in option key for selectors is event_tracking_keys. It returns unique event_key values from fc_event_tracking as [{id, title}].

Do not register your own fluentcrm_ajax_options_event_tracking_keys filter unless you intentionally override/extend the built-in source. The core handler registers it with one accepted argument, while custom option filters usually use the 3-argument pattern described in fluentcrm-rest-options.

Privacy and safety

Event values are visible in the contact timeline widget and can feed automation conditions. Do not store access tokens, personal secrets, raw request bodies, or unbounded JSON blobs in value.

Good event shape:

[
    'provider'  => 'lw-lms',
    'event_key' => 'lesson_completed',
    'title'     => 'Lesson completed',
    'value'     => (string) $lessonId,
]

Bad event shape:

[
    'event_key' => 'webhook_payload',
    'title'     => 'Webhook payload',
    'value'     => wp_json_encode($_POST), // too large, may contain secrets
]

Common mistakes

Cross-references

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.