I hope you’ll be able to help me on this one:
I’m trying to trigger a GA event for every email sent via a WordPress site.
My idea was to add the following code to my child theme’s functions.php file:
add_action("wp_mail", "trigger_contact_event");
function trigger_contact_event(){
include "include/Galvanize.php"; //Galvanize is a php class able to trigger GA events server-side
$GA = new Galvanize('UA-XXXXXXX-XX');
$GA->trackEvent("Contact", "info request");
}
But unfortunately, this doesn’t trigger anything.
Would anyone have a solution? Even another way to trigger a GA event, as long as it is hooked to any email sent via the wordpress website.
Thanks in advance!
I would use
phpmailer_init
(unless you’re using a plugin that overrideswp_mail
):