With Google Analytics connected to your digital workplace, you can set up event tracking to track how users interact with components of your page. You can find these events in Google Analytics under Behavior > Events location. You can then measure these metrics against the desired goal. For more information, check out Google's video about how to set up event tracking.
Sections in this article:
Considerations and caveats
Experience with JavaScript
Setting up event tracking requires some experience with JavaScript.
Google Tag Manager
Google Tag Manager gives you an alternative method of tracking events in your digital workplace. To track events this way, you will need to add Google Tag Manager to your workplace and then set up tracking via triggers and tags.
How to track events with Google Analytics
Google's developer API defines the basic functions that Google Analytics uses to record events. However, for event tracking to work, you must attach these functions to the HTML elements on a page. You can track the clicking of an element with the following code snippet (Note: Your digital workplace uses the legacy ga.js code by default)
(function($) { $(function() { $('{identifier}').click(function(evt) { _gaq.push([ '_trackEvent', '{Category}', '{action}', '{label}', {value} ]); }); }); })(jQuery);
Modifying this script:
- Replace {identifier} with a selector that returns the HTML element that you want to track. This identifier can be as simple as referencing the id of an element (ex. #myidentifer) but may require investigating the DOM and creating a more complex selector depending on the element.
- Replace {category}, {action}, {label}, {value} with the terms you are using.
- You do not need to include {label}and {value} parameters. If you remove them, be sure to remove the trailing comma of {action}.
- You can replace .click with other event types, such as .hover.
Where you place this script depends on what HTML element you want to track. If the element only exists on specific pages, place your script in the JavaScript section of those page's Advanced Page. If you are tracking an element that occurs on every page of your workplace, you should place your script in the header of your digital workplace.
Connecting events to goals
After creating events, you can then connect them to goals within Google Analytics (Admin > View Column: Goals).