ActiveCampaign Forum

Can event tracking utilize contact hash instead of email?

I want to use the contact hash in emails url’s instead of their email address for privacy. Like discussed here: Include hash in e-mails

But I want event tracking to function as well. In the API documentation for track_event_add ( it doesn’t state whether or not you can pass the contact’s hash to associate the event with the contact. The example shows using the email.

The log function in Tracking.class.php in github ( seems to use the email only too.

I am only a amateur programmer, so I hired a programmer to change my plugin to use hash instead of email, but they are running into problems so I thought I’d better ask here. It’s possible I don’t really understand what’s going on at all and am confusing different things.

If it is possible to use the contact hash with tracking, how?


(Or, maybe we need to use email and lookup the email from the hash? But that would cause an additional api call I would think?)

Hey @dean,

The first email you referenced is a bit different use case. We use the email address as a special type key field, to look up the contact.

Unfortunately this means that using the hash with event tracking directly is not possible at this time, however you could create some sort of key-value pair on your server, to prevent email address from being exposed server-side.

So for example, your project might have a user-id that you can use. So you could write your own javascript method for the client, POST that to your server/app --> have the server/app find the email address for the user-id received --> call the event tracking method. This has the added benefit of keeping your AC event tracking keys off of the client.

OR you could use a tool like or Segment to handle client-side event tracking for you. They have already handled much of this abstraction away for you.

OK, that’s good information.

What my programmer is testing is to lookup the email address from the hash, then log the event using the email.

Like so:

if (isset($_COOKIE['hash'])) {
  $ac->track_hash = $_COOKIE['hash'];
  $hash_response = $ac->api('contact/view', array(
    'hash' => $ac->track_hash
  $ac->track_email = $hash_response->email;
} else if (isset($_COOKIE['email'])) {
  $ac->track_email = $_COOKIE['email'];

(we are storing the hash as a cookie, and the email cookie is there for backwards compatibility)

Unfortunately this code isn’t quite working though.

Hey @dean,

You are on the right track, I think you are looking for the contact_view_hash api call -

Yes, I think you’re right! I’ll let him know. Thanks for the pointer

1 Like

Got it finally!

For anyone else who’s interested (not a complete file, just the stuff where we actually post the event):

function ac_event() {
// load ac
$ac = new ActiveCampaignEvent(AC_URL, AC_API_KEY);
if (!(int)$ac->credentials_test()) {
	echo 'Access denied: Invalid credentials (URL and/or API key).';

// track event
$ac->track_actid = AC_ACTION_ID;
$ac->track_key = AC_EVENT_KEY;
if (isset($_COOKIE['hash'])) {
	$hash = $_COOKIE['hash'];
    $hash_response = $ac->api("contact/view?hash=$hash");  //this is where we get the email from the hash
	$ac->track_email = $hash_response->email;
} elseif (isset($_COOKIE['email'])) {
    $ac->track_email = $_COOKIE['email'];
$response = $ac->api('tracking/log', array(
    'event' => $_REQUEST['event'],
    'eventdata' => $_REQUEST['eventdata'],

// send response
echo json_encode($response);