Recording Application Bar clicks

A fairly common use of Advanced Analytics is to record how often links on the application bar are clicked. This allows you to get an idea of which app links are most commonly used across your organisation and perhaps reorganise the links to make it more convenient and accessible to your users. The script below can be added to the developer framework, masterpage javascript as usual.

📘

To access the MasterPage Javascript feature of interact, simply login as a power user or site admin, and navigate to - Application Settings -> Control Panel -> Developer Framework -> Manage MasterPage Javascript

The snippet below will record that a link was clicked from the application bar with an event of 'Application Link clicked', and add to the CustomField1 field the URL of the link that was clicked. We've also added comments to each line to explain what is happening.

var populateCustomFields = function (event, person, callback) {
  if (event['EventName'] == "Application Link clicked") {
    // if its an 'application link cicked' event, then add the URL that was clicked to custom field 1
    event.CustomField1 = linkClicked;
    linkClicked = '';
  }
 
  return callback(event);
}
 
var linkClicked = '';
 
$(document).ready(function () {
  // Only track links within the application ribbon
  $('#app-ribbon').on('click', 'a[href]', function (e) {
    var href = $(this).attr('href');
      e.preventDefault(); // Prevent the default link behavior to ensure we process AA event first
      linkClicked = href; // capture which link was clicked
      TrackerNew.logEvent('Application Link clicked'); // log the event with advanced analytics
 
      // Use window.location to navigate after the event is logged
      window.location.href = href;
  });
});
 

📘

Remember that if you're already capturing custom fields with the populateCustomFields function, then just add the if block to your existing function.