How To Do Event Tracking In ActiveCampaign on WordPress

ActiveCampaign is a very impressive marketing automation software that is going from strength to strength.

They are very active in developing new features. Often with multiple updates and additions to the software each week.

And for the most part they are one of the more user-friendly options out there.

The majority of features work straight out of the box…

…however event tracking isn’t one of them. It requires custom coding and is definitely one of their harder features to implement.

In this post I’ll show you how to implement event tracking for ActiveCampaign on WordPress (including a free custom WordPress plugin I had developed).

Free Plugin: Download the free ActiveCampaign Event Tracking plugin that is explained in this post.

What Is Event Tracking

Every good marketing automation software should allow you to track how your users are interacting with your website.

ActiveCampaign does this with a combination of site tracking and event tracking.

Site tracking is a bit of code similar to Google Analytics where you place some code on every page of your site.

This code tracks what pages people visit and once ActiveCampaign knows who someone is (because they opt-in, login, visit a link from your email etc), then it will automatically show that information in the contacts record.

It’s great to know which pages people visited. This can be useful to see what topics someone is interested in, useful for lead scoring, it can even be used to start automations for something like cart abandonment automations.

But what if you wanted to know more?

Site tracking will show you WHICH pages your contacts are visiting, but it doesn’t show you WHAT they are doing on those pages.

Sometimes there are specific actions you want to track. Often this is clicking on certain buttons or links. For example to download a resource, or click to visit a certain page off of your site.

That’s where event tracking comes in.

Event Tracking Examples

A great overview of event tracking is on the ActiveCampaign website.

Some practical examples of where you might want to use event tracking are…

Started A Form But Didn’t Finish It
Maybe you have a form where you need to capture some information (like a quiz, for a consultation, or a feedback request form). It would be useful to know if someone started the form but didn’t finish it.

With event tracking you can track if someone clicks to start the form but doesn’t make it to the end and start an automation to encourage them to finish it.

Downloaded a Resource
Or maybe you offer some sort of lead magnet as an opt-in but you want to have different paths for people that clicked to download it and those that didn’t.

After someone opts-in you send them to the download page and want to track if they actually click to download your lead-magnet. With event tracking you can.

As Part of Lead Scoring
You could also use it as part of your lead scoring setup. You could track clicks on things like share buttons as an event.

Every time someone clicks a share button you could increase their score.

How It Works

For event tracking to work we need a couple of things:

  1. Know WHO the person is
  2. Track and record WHAT specific action they take
  3. Send both the WHO and the WHAT to ActiveCampaign via their API

Step 1 – Know Who Someone Is

There are a few ways we can know who someone is. Ideally if people login to your site (such as a membership site) you can know who they are.

That’s useful if you have a membership area. But even then it doesn’t help with people that have just become leads. In this case the two main ways we can know who some is are when they:

  • Provide you with their email (like opting-in for your lead magnet)
  • Follow a link in an email you send them

Whenever we have the opportunity to verify who someone is we want to store this information in a cookie. By doing this, the next time they visit your site on the same browser we will know who they are and can use that data for event tracking.

To achieve this always append a URL with the contact’s email address when you have it (like straight after they opt-in or follow a link in your emails). For example:

[html]http://www.yoursite.com/[email protected][/html]

We then use some code to get their email from the URL and store it in a cookie:

Note – you can modify this code to use a different variable name if “email” conflicts with something you are already using.

Step 2 – Track and Record Events

There are a number of events you can track depending on your use case. For this plugin we are going to track any HTML DOM events.

We use some javascript code with the AJAX onreadystatechange event. The code to do this is in the attached plugin.

Free Plugin: Download the free ActiveCampaign Event Tracking plugin that is explained in this post.

Then all you need to do is modify the specific elements you want to track by adding the event name and “ac_event(‘Event Name’, ‘Event Value’);”. For example:

You will want to use your own event names and event values as this is what will be recorded in ActiveCampaign. Here is where it will show up:

event-tracking-activecampaign-record

Step 3 – Send The Who and The What To ActiveCampaign

The final step is to combine the event that has been tracked with the user information (their email) and send both pieces of information to ActiveCampaign.

To do this we check to see if the users email is stored in the cookie and if it is we send this along with the event data to ActiveCampaign.

This plugin makes use of the ActiveCampaign PHP wrapper and event tracking via the API.

You will need to update the activecampaign.php file in the plugin folder with your API details:

  • Login to ActiveCampaign
  • Under your name in the top right go to My Settings > Developer
  • Copy the value of the “URL” field to the AC_URL constant in the script
  • Copy the value of the “Key” field to the AC_API_KEY constant in the script
  • Go to My Settings > Tracking > Event Tracking
  • Enable event tracking with the “Status” toggle
  • Copy the value of the “Event Key” field to the AC_EVENT_KEY constant in the script
  • Create the necessary event names under “Events”
  • Under “Events”, click on the link where it says “Event Tracking API”
  • Copy the value of “actid” to the AC_ACTION_ID constant in the script

This is how it should look once you are done (these are just example values not real values):

ac-plugin-updated

How To Put This Into Action

I have included a description of how this particular event tracking implementation works. I think it is important to understand what is happening before you go and start adding random things to your site.

With that said, here is a summary of steps to implement it for your site:

  1. Download the ActiveCampaign Event Tracking Plugin
  2. Modify the activecampaign.php file as per the details above
  3. Upload the plugin to your WordPress site and activate it
  4. Add or update any HTML DOM events you wish to track using this format:
    [html]domevent=”ac_event(‘Event Name’,’Event Value’);”[/html]

Testing

To make sure everything is working, first check that an email is being stored in a cookie.

Visit your website and append a test email that is already in ActiveCampaign.

Next view the cookie information stored in your browser (see details here).

You should see the test email stored. Here is a screenshot from Chrome:

chrome-cookie

And a screenshot from Firefox:

firefox-cookie

Next make sure you have something set with your DOM event (for testing I find a link to be easiest).

Now in the same browser where you just set the test email address in the cookie visit the page with your updated link (or other event), click on the link (or whatever action you setup).

The first check is to make sure you get a message in the Console of your browser. To access the console, right-click on your webpage and select “Inspect” or “Inspect Element” and then click on the “Console” tab. You should see a message like this in Chrome:

event-tracking-console-response

And this in Firefox:

firefox-console

If that all checks out okay then go ahead and check in ActiveCampaign under the test contact’s record. You should see the event is recorded in the “Site and Event Tracking” section. See the screenshot below for an example:

event-tracking-activecampaign-record

You can now use this in automations and for segmentation.

Important Note

I want to be clear that I paid to have this plugin developed for my own personal use, my private clients and members of my community.

I am providing a version here for free. However no guarantees it is the latest version.

If you want to make sure you get the latest version plus on-going support (and a WHOLE lot more) you can do that here.

Click here to download the plugin

EventTrackingPlugin

Almost there! Please complete this form and click the button below to gain instant access.

Enter your name and email below and I’ll send you the link to the Event Tracking Plugin:

Your privacy is important to us and we will not spam you.
  • http://www.learningtitanium.com Sharry

    Thanks for sharing Todd

    • //functionalfunnels.com/ Todd Molloy

      No problem. Let me know how you go setting it up and using it in AC

  • http://auspiciousincubator.com.au/ Craig Lambie

    Thanks for sharing Todd. Very useful 🙂
    I made a change, to make it work for me. On activecampaign.php line 30 I changed the enque scripts to false for the infooter option, as my scripts are on the page, so where failing without an “onready” function, which I didn’t want to add.

    I also use Henry Reiths http://henryreith.co/ Split Testing AC plugin, which has Admin menu item, and put the API info into the Db via WP_Options, if I had 5 minutes to spare, I would fork your project and add that, or use it/ check for it first.
    Since I don’t have time, I will call it a feature request/ suggestion for improvement.

    Thanks for implementing such a neat set of code, I will get a great deal of use from it, so next time I am in Perth, let me buy you a beer.

    Cheers

    • //functionalfunnels.com/ Todd Molloy

      Great to hear you have it working and good suggestions. The plugin is pretty basic but it get’s the job done. Feel free to buy me a beer any time 🙂

  • http://auspiciousincubator.com.au/ Craig Lambie

    Further to my last comment, I have added this to your plugin, that makes sure if a user logs in, the cookie is set with the email address of the currently logged in user, not relying on us sending them there with the URL parameter, helpful for Actions like looking at membership sites or similar locked down content.

    add_action( 'init', 'set_ac_email_cookie' );

    function set_ac_email_cookie() {
    if ( is_user_logged_in() ) {
    global $current_user;
    get_currentuserinfo();

    setcookie( 'email', $current_user->user_email, 30 * DAYS_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
    }
    }

    • //functionalfunnels.com Todd Molloy

      Good idea Craig. I’ve added this to the plugin so it will work with both methods.

  • Mark H

    This is awesome Todd! Thanks so much for sharing.
    Only thing though, the account doesn’t have an Action ID shown anywhere except in the Site Tracking code. You might want to update the welcome email to mention that as it would have saved me some time looking for it lol

    Thanks again!

    • //functionalfunnels.com Todd Molloy

      Thanks for the comment Mark. I’ve updated the email explaining where to find the info.

  • Adam

    Hi, I am trying to utilize your plugin to capture events from a WordPress site to ActiveCampaign. I installed the plugin and made the changes for my ActiveCampaign site. I am new to WordPress and am trying to figure out how to add Step 4 (Add or update any HTML DOM events you wish to track using this format: [html]domevent=”ac_event(‘Event Name’,’Event Value’);”[/html]). I am not sure where to add it and there isn’t any place to add the function call directly to an onSubmit event. Any help you could provide would be greatly appreciated.

    Thanks in advance for your help.

    • //functionalfunnels.com Todd Molloy

      Hi Adam, for an onSubmit event what are you trying to track? Is this a form submission? If so what are you using for your form?

    • //functionalfunnels.com Todd Molloy

      The plugin will track individual events. A click on 1 specific button or 1 specific link. You will need to modify the code for EACH button/link/whatever you want to track.

      For example you might have a blog post and you want to track when someone clicks on a link or button. In that case you would modify the code for that specific link/button.

      Normally a link would look like this:
      <a href="http://somelink.com">Some link</a>

      To track when this link is clicked you would change it to this:

      <a href="http://somelink.com&quot; onclick="ac_event(‘Event Name’, ‘Event Value’);">Some link</a>

      In this case, your ‘Event Name’ might be ‘Link Click’ and the ‘Event Value’ might be ‘Some Link’

  • Marissa

    is this still working?

    • http://functionalfunnels.com Todd Molloy

      Yes it is still working