Send Custom Metadata with Search, Click, or Custom Events
It can be useful to modify the standard usage analytics events logged by the Coveo JavaScript Search Framework Analytics
component. You can do so by using a changeAnalyticsCustomData
event handler.
-
Add a
userRole
metadata to all search events (seemetaObject
)./** * Gets the role of the currently authenticated user. * * @returns {string} The user role (e.g., "admin"). */ getUserRole = function() { // Implementation ... }; var root = document.body; Coveo.$$(root).on('changeAnalyticsCustomData', function(e, args) { if (args.type == 'SearchEvent'){ currentUserRole = getUserRole(); args.metaObject['userRole'] = currentUserRole; } })
-
Change the origin level 3 value on all standard usage analytics events (see
originLevel3
)./** * Gets the current `originLevel3`. * * @returns {string} The current `originLevel3` (e.g., "https://docs.coveo.com/en/2004"). */ getOriginLevel3 = function() { // Implementation ... }; var root = document.body; Coveo.$$(root).on('changeAnalyticsCustomData', function(e, args) { currentOriginLevel3 = getOriginLevel3(); args.originLevel3 = currentOriginLevel3; })
What’s Next?
If custom usage analytics events are being logged from your search interface, you may want to ensure that this data is actually usable (see Review User Visits With the Visit Browser).
Recommended Articles