Simple Feedback for Usage Analytics

Like my previous posts on Usage Analytics this topic appears regularly in my work. In the previous posts I described setting up App Insights for use in Office development and how to attach Custom Events to actions in SharePoint site elements so that we can easily take measurements (think Lean Startup) as we develop stories.

Sometimes though we do not have the benefit of a user action to confirm that a story was useful. For example, when we display information like today’s Special in the Cantina or the next public holiday. For these cases we can employ a simple feedback mechanism using the same back-end service. All that we need is a little HTML to display buttons but I have added a helper function to send event properties so that we can have more measurements in one instance and still tell the results apart.

Was this helpful?
YES NO
Yes, but not perfect.

You can style the table however you want- this one is much too large for most uses. The table code, without special Style, looks like this:

<table style="width:100%;border:1px solid black;" bgcolor="#D3D3D3">
  <tr>
  <td colspan="2">Was this helpful?</td>
  </tr>
  <tr >
    <td style="width:50%;border:1px solid #999999;" onclick="UsageEvent({NewPanel:'yes'}); this.style.backgroundColor = '#cce5cc';">YES</td> 
    <td style="width:50%;border:1px solid #999999;" onclick="UsageEvent({NewPanel:'no'}); this.style.backgroundColor = '#cce5cc';">NO</td>
  <tr>
    <td colspan="2" onclick="UsageEvent({NewPanel:'other'}); this.style.backgroundColor = '#cce5cc';">Yes, but not perfect.</td>
  </tr>
</table>

Note that the onclick action is a function. The input is a JSON containing a property name and value.  The UsageEvent function looks like this:

function UsageEvent (eventProperties) {
appInsights.trackEvent("Feedback",eventProperties);
}

For this example I moved away from the simple “Your Event Here” model as previously described because I might want to track lots of different events, some “Feedback” events and others that are various types of Actions. The “properties” model allows me have a handful of top-level entries, like “Feedback” which can be sorted or charted separately in the App Insights console based on their properties.