Created
November 6, 2025 11:13
-
-
Save mredodos/b7cec831372a4d7e0af6fe49c8bbd7b6 to your computer and use it in GitHub Desktop.
Track email link click via custom event tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Plugin Name: TP – Track Email Link Clicks (FluentCRM) | |
| */ | |
| add_action('fluent_crm/email_url_clicked', function ($campaignEmail, $urlObject) { | |
| // Prendi i riferimenti del contatto | |
| $subscriber_id = (int)($campaignEmail->subscriber_id ?? 0); | |
| $email = $campaignEmail->email ?? ''; | |
| // Dati utili sul click | |
| $clicked_url = is_object($urlObject) && isset($urlObject->url) ? (string)$urlObject->url : ''; | |
| $campaign_id = (int)($campaignEmail->campaign_id ?? 0); | |
| $email_id = (int)($campaignEmail->id ?? 0); | |
| // Titolo unico per URL (così NON viene solo incrementato il counter) | |
| $title = 'Email link clicked: ' . $clicked_url; | |
| // Puoi serializzare altri metadati nel "value" | |
| $value = wp_json_encode([ | |
| 'url' => $clicked_url, | |
| 'campaign_id' => $campaign_id, | |
| 'email_id' => $email_id, | |
| 'timestamp' => current_time('mysql') | |
| ], JSON_UNESCAPED_SLASHES); | |
| // Prepara il payload per l’Event Tracker | |
| $payload = [ | |
| 'event_key' => 'email_link_clicked', // chiave evento | |
| 'title' => $title, // titolo leggibile | |
| 'value' => $value, // metadati aggiuntivi | |
| 'provider' => 'fluentcrm' | |
| ]; | |
| // Identifica il contatto (priorità a subscriber_id) | |
| if ($subscriber_id) { | |
| $payload['subscriber_id'] = $subscriber_id; | |
| } elseif ($email) { | |
| $payload['email'] = $email; | |
| } | |
| // Crea l'evento (true = crea contact se necessario) | |
| do_action('fluent_crm/track_event_activity', $payload, true); | |
| }, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment