Supply user email with event tracking

Hello,

I have set up Event Tracking on our pages following the instructions on https://help.activecampaign.com/hc/en-us/articles/221870128-An-overview-of-Event-Tracking

I have set up a PHP Curl POST request which I trigger via a JavaScript onclick event. For example I have a “Download Now” button which triggers the JavaScript onclick event, which in turn calls the PHP script to send the event to Active Campaign.

This appears to be working correctly, but the event logged isn’t attributed to a user.

According to the link above, this code is where I need to supply the users email address:

"visit" => json_encode(array(
    // If you have an email address, assign it here.
    "email" => "",
)),

If I manually put an email address here, I can see the event being tracked against that user. I want to know how I can populate this field automatically with the current user. I can’t find any documentation that explains how to achieve this!

To further explain, I have a landing page with a form. Once the form is completed the user goes to a “thank you” landing page. When they click the “Download Now” button on the thank you page, I want to track this event against the user.

You can solve it one of two ways, but either way you need to store the email address someplace. Either client-side and pass to the server with the onclick event, or serverside in session or something.

Personally, I like to store it in localStorage client-side.

In addition to the help article, I would recommend checking out this blog post: https://www.activecampaign.com/blog/how-to-setup-activecampaign-event-tracking/

Three years later, and I am having this exact problem. It seems to me this information is available somewhere, and I would think the ActiveCampaign plugin would have a function to grab this information - is this not the case? After all, whenever a page view happens, the site tracking somehow records the page view or whatever to the correct user. How do I get a hold of that piece of data that’s already being used somewhere?

You will need to store the currently logged in user email address somewhere and then provide it when making the event tracking API call.