How to get powerful user data with Raygun Real User Monitoring

| 3 min. (552 words)

One of the key aspects of a great real user monitoring solution is, perhaps unsurprisingly, great user data. When this is available, you can see your customer’s true experiences in real time as they navigate your web site or app, alongside the list of errors they’ve had and most crucially, their contact details. If a valuable customer has a bad experience, you can reach out and let them know you’re working on it immediately. It’s also invaluable for helping with the triage of vague customer support tickets by tracing the sequence of page loads during a user session, allowing you to construct a precise picture of what happened.

If you haven’t already seen how to get started with Real User Monitoring, check this introductory blog post first.

In this blog post I’ll show how easy it is to get great user data into your RUM dashboard, as well as some examples for popular templating DSLs. Let’s crack into it.

Basic implementation

This is what the resulting JS script should contain once you’ve provided your user data, as it would appear in the static HTML file requested from the server:

rg4js('setUser', {
  identifier: 'users_email_address_or_unique_id@domain.com',
  isAnonymous: false,
  email: 'users_email_address@domain.com',
  firstName: 'Firstname',
  fullName: 'Firstname Lastname'
});

If you wish to record an anonymous user, for instance on your login page pre-authentication, you should set isAnonymous to true and optionally provide an identifier (we’ll assign a random UUID if none one isn’t set).

Naturally, you won’t want to hard-code those values, so let’s get the above snippet data-driven using some popular serverside frameworks. You want to paste these snippets into an appropriate view that is common to all the pages you want to see in RUM. For instance, in MVC frameworks like ASP.NET MVC and Ruby on Rails, you might want to place it in a shared main layout view file, or a partial that includes only the Raygun4JS configuration.

Razor (ASP.NET MVC 3+)

Inside a .cshtml view, assuming there is a ViewModel with the following property names attached:

<script type="text/javascript">
  rg4js('setUser', {
    identifier: '@Model.EmailAddress',
    isAnonymous: false,
    email: '@Model.EmailAddress',
    firstName: '@Model.FirstName',
    fullName: '@Model.FullName'
  });
</script>

.ASPX in WebForms and MVC 1/2

<script type="text/javascript">
  rg4js('setUser', {
    identifier: '<%= Model.EmailAddress %>',
    isAnonymous: false,
    email: '<%= Model.EmailAddress %>',
    firstName: '<%= Model.FirstName %>',
    fullName: '<%= Model.FullName %>'
  });
</script>

.ERB in Rails

Assuming that the user data is available on an ‘user’ instance variable, populated from current_user and the DB:

<script type="text/javascript">
  rg4js('setUser', {
    identifier: '<%= @user.emailAddress %>',
    isAnonymous: false,
    email: '<%= @user.emailAddress %>',
    firstName: '<%= @user.firstName %>',
    fullName: '<%= @user.fullName %>'
  });
</script>

Handlebars

As sometimes used in Node.JS frameworks like Express, Koa et la, and also applies of course to Mustache templates also:

<script type="text/javascript">
  rg4js('setUser', {
    identifier: '{{user.emailAddress}}',
    isAnonymous: false,
    email: '{{user.emailAddress}}',
    firstName: '{{user.firstName}}',
    fullName: '{{user.fullName}}'
  });
</script>

Get started with Real User Monitoring now

As you can see, they’re all pretty minimal! There’s a million view engines out there so if this post has missed your favorite hopefully you can get the gist from the above examples. If you haven’t yet got your free Real User Monitoring trial, you can start here – free for 14 days and no credit card required. Any questions let us know in the comments below!

** UPDATE **

Real User Monitoring for Mobile Applications is here!  See the update here