Skip to content

Event Tracking

Allan Lasser edited this page Nov 18, 2016 · 2 revisions

We track events on MuckRock using the functionality provided by Google Analytics.

Here are all the places in our code where we track events. There's two different ways to track an event:

  1. Add the name of an event to track to the request session on the server. This event will be sent on the next page load. For example, see how we track request purchases.
  2. Send the event using JavaScript. Either call the ga() global method from inside a JavaScript file, or from an HTML element's event handler attribute, like onclick or onsubmit. For an example, see how we track newsletter signups.

To paraphrase the Google documentation, you can send an event by calling ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);. We use a number of categories and events already (category is the higher-order bullet, action is the lower-order bullets):

  • Requests
    • File
    • Draft
    • Submitted
    • Purchase
  • Account
    • Login
    • Registration
    • Logout
  • Newsletter
    • Subscription
  • Crowdfund
    • Donation

Usually, we use the request path (e.g. /foi/create/) as the event's label, so that we can better track where events are happening.

Sharing events

When a user clicks on a social sharing button, we track this in a similar, but distinct, way from events. When a share button is clicked, we use JavaScript to trigger the ga('send', 'social', [socialNetwork], [socialAction], [socialTarget], [fieldsObject]); method. See more about the way Google Analytics tracks social interactions in their documentation.

Clone this wiki locally