Sending Custom Metadata with Search, Click, or Custom Events

Sometimes, 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.

    /**
     * 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 originLevel3 value on all standard usage analytics events.

    /**
     * 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 Reviewing User Visits With the Visit Browser).