Recording application bar clicks
Before you start
- You need the Power User or Site Administrator role to edit the MasterPage JavaScript.
Note: To access the MasterPage JavaScript feature, log in as a Power User or Site Administrator and go to Control Panel > Developer Framework > Manage MasterPage JavaScript.
Overview
A common use of Advanced Analytics is to record how often links on the application bar are clicked. This gives you an idea of which app links are most commonly used across your organisation, so you can reorganise the links to make them more convenient and accessible for your users. Add the script below to the Developer Framework MasterPage JavaScript.
Add the tracking script
The snippet below records that a link was clicked from the application bar with an event of 'Application Link clicked', and adds the URL of the clicked link to the CustomField1 field. Comments on each line explain what is happening.
var populateCustomFields = function (event, person, callback) {
if (event['EventName'] == "Application Link clicked") {
// if it's an 'application link clicked' 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;
});
});
Tip: If you already capture custom fields with the
populateCustomFieldsfunction, add only theifblock to your existing function.