Setting up event tracking with Google Analytics

This is a summarized version of a great post by North Studio about setting up event tracking. For more information read the original article.

Google Analytics allows you to track metrics like sessions, page-views and bounce rates without any special set up. Event tracking gives you greater insight into how readers are interacting with your website by tracking events like downloads or link clicks.

Setting up event tracking requires three steps:

  1. Decide what you want to track
  2. Add a tracking code to your website
  3. Set up a goal in Google Analytics
Once you've decided on what to track, you need to add a tracking code to the link for that action. For example, if you want to track PDF downloads, you need to add a tracking code to the download PDF.

The code you use will depend on which version of Google Analytics you are using. To determine the version you have installed, go to the "Page Source" for your site, CTRL+F to search for "analytics.js" (Universal Analytics) and "ga.js" (Classic Analytics), whichever appears is the version of Google Analytics installed.

For Classic Analytics (ga.js) your code will follow this format:

onClick="_gaq.push(['_trackEvent', 'category', ‘action', 'opt_label', opt_value, ‘opt_nonInteraction’]);"

For Universal Analytics (analytics.js) your code will follow this format:

onClick="ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, value, {‘NonInteraction’: 1});"

These are the variables you need to consider:
  • Category (required) - This variable specifies the type of object that was interacted with.
  • Action (required) - The specific action a user took to trigger an event.
  • Label (optional) - Allows you to provide more context about the interaction.
  • Value (optional) - The numerical-value of the event.
  • NonInteraction (optional) - A boolean that when set to ‘true’ (or “1” for Universal Analytics) excludes the event from affecting metrics like Bounce Rate.*
*By default, Google Analytics considers events as an “interaction”, which in turn affects your bounce rate.

Continuing with the PDF download example, your download link might look like this:
<a href=""> Article 1 PDF </a>

And your variables would be as follows:
  • Category = PDF Downloads (because you're tracking PDF downloads across your site)
  • Action = Click (because that's the action the reader needs to take to access the PDF)
  • Label = Article 1 (because that's the name of our PDF)
  • Value = (none)
  • NonInteraction = false

    With Classic Analytics Tracking (ga.js) your code would look like this:
    <a href="" onClick="_gaq.push(['_trackEvent', ' PDF Downloads', ‘Click', 'Article 1');"> Article 1 PDF </a>

    With Universal Analytics Tracking (analytics.js) it would look like this:
    <a href="" onClick="ga(‘send’, ‘event’, ‘ PDF Downloads’, ‘Click’, 'Article 1');"> Article 1 PDF </a>

    Finally, you need to set up Google Analytics to track it.
    1. Log in to your Google Analytics account.
    2. Go To “Admin”
    3. Under the “View” column, click on “Goals”.
    4. Click on “New Goal”.
    5. Under “Template”, click on “Custom”.
    6. Choose a name for your goal and then under “Type”, select “Event”.
    7. Enter your category and action. Verify your goal and then click “Create Goal”

    To make sure everything is set up correctly, do a quick test.
    In Google Analytics, go to the "Reporting" click on "Real-Time" then click on "Events".
    In a separate window, go to your page and click on the event you're tracking (ie. the Article 1 PDF link).
    The action should show up in your Google Analytics: confirm that it has the correct Category, Action, and Label and you're all set!

Why is there a difference between TrendMD reporting and Google Analytics?

Discrepancies between TrendMD reporting and Google Analytics reports are normal because of differences in reporting methodologies. That said, both should follow similar trends. The following campaign example indicates some discrepancy between Google Analytics and TrendMD reporting, but the overall trend is similar. Let's explore some of the reasons for those discrepancies:

  1. Google Analytics site implementation
    • A common reason is not implementing Google Analytics properly on all article pages across the site, especially on newly added sections, leading to some of the TrendMD traffic not getting tracked by Google Analytics.

  2. Partial page load
    • Visitors may navigate away from the site before the page is fully loaded and Google Analytics tracking code executes, recording the TrendMD traffic.

  3. User browser preferences
    • Visitors may have set their browser privacy preferences to disable cookies, images, or JavaScript making them non-trackable by Google Analytics. The same goes for users that have installed Google's own opt-out add-on.

  4. Google Analytics sessions vs. TrendMD clicks
    • There is a distinction between Clicks recorded by TrendMD and Visits/Sessions recorded by Google Analytics. While TrendMD records a Click anytime a user clicks a content recommendation on a publisher site, Google Analytics records a single Session/Visit for all user interactions within a given time frame (which expires after 30 minutes of inactivity). For example, if a user reached the marketer's site through TrendMD twice within that time frame, he or she will be recorded as just one Session/Visit.

  5. Google Analytics sampling preferences
    • Unlike TrendMD, Google Analytics data is generally based on a sampling of all visits to the site, rather than the whole incoming traffic. Google Analytics uses sampling in order to generate reports on very large data sets (over 1m visits).

  6. Time zone differences
    • TrendMD reporting is currently still based on US Eastern Time (UTC -5 hours) for all global markets. If Google Analytics is using a different time zone, the daily reporting might have some differences.

  7. TrendMD UTM tag implementation
    • Marketers can get a more accurate view of their TrendMD traffic by implementing a UTM tag for their TrendMD campaigns. They can then see their campaign-specific traffic in Google Analytics under "Campaigns" rather than under the more limited "All traffic sources" (showing traffic from
For any questions regarding your campaign data in Google Analytics, feel free to reach out to our support team for further assistance.

Tracking visitors from 2016 and earlier using Google Analytics.

We updated the way we add tracking slugs to publisher sites over the course of 2016 - all publishers have been moved to the new system as of the end of January 2017. Here is how to track visitors as of January 2017.

To track visitors acquired before the switch, use the following steps:

'All pages'.

In the search box on the right hand side of the table, search using 'trendmd'.

Search trendmd-shared=0 for tracking TrendMD traffic within your sites.

Search trendmd-shared=1 for tracking TrendMD traffic referred to your sites from third-party sites.

To make it easier to visualize all the of the tracked content, go to the bottom of the stats table and change the number of rows.