It's easy to get Google Analytics set up on your website. For a Drupal site, it's as simple as installing a popular contrib module. Oftentimes, though, your site features on-page interactions that do not register by default to GA, but that you still want to track.

The way to track stuff that happens on pages (without going to a new page) like expanding/collapsing a menu, toggling a slideshow, or opening a modal window is with Events. Google Analytics provides an easy API method for tracking just about any event you'd like.

If the on-page interactions are built using Views or are otherwise not custom-written JavaScript, you may want to investigate a contrib module like Google Analytics Event Tracking. If you've got some scripts and a working knowledge of JavaScript, the following strategy will be useful for structuring your analytics code.

Planning Out Your Events

Events are tracked via four main properties (passed to the method):

Category (string)

Action (string)

Label (string, optional)

Value (integer, optional)

It's up to you how exactly you implement these properties. At Commercial Progression we're sticklers for good semantics, so we start from the following guidelines:

Category : The region, block, or logical section name containing the event

: The region, block, or logical section name containing the event Action : The JavaScript event name An accurate description of what happens when the event fires (expand, collapse, etc.) A verb acting on a sub-section of the Category container

: Label : The inner text of the Action's element A shared piece of text from the Category (when the Category has multiple Actions)

: Value: A numerical index associated with the Action, when applicable (ex. The time when a video is paused)

The picture at the top of the post shows the typical planning process for implementing events. We whiteboard out a table and fill in the values. Seeing all the events in one place allows us to optimize the Categories, Actions, and Labels. If a particular element on the page has a bunch of actions, it's often useful in GA for all those actions to have the same label.

Create an Abstraction

The GA Event method is straightforward: