Application Insights for Sitecore (or, where have my logfiles gone?)

So with Sitecore’s new Azure PaaS offering, you might’ve noticed in your Azure resource group that there’s an Application Insights resource there.

Application Insights can be used to monitor the live web applications and helps with diagnosing issues and figuring out what users are doing with your app. More information here. Application Insights is quite a big and powerful tool, and I won’t be able to cover everything juts quite yet. I will however run through some of the cool features.


Even by itself that’s a pretty cool (and useful) tool to have. But the Application Insights have actually also been integrated with Sitecore.

In the Application Insights overview blade we can get some additional information by clicking the Search button. We can filters the results there as well, by type (such as trace, request or page view) or property. For Sitecore’s log entries we are interested in the Trace filter.


To query the log files in more depth, we can actually hit the Analytics button in that same overview blade. This will open a new window, where we can begin writing queries to find issues logged in our Sitecore logs.


Any of the properties you see in the bottom right we can filter on – you can find those properties on the left hand side as well, in the Schema. There’s also some very useful documentation on writing queries.

In the Performance blade, I can also create my own charts based on Sitecore statistics, as well as see how my application is performing.


We can also do things like set up alerts when there’s over 5 server exceptions in the application (see image below), and if this happens send an email to the administrators.


This type of reactive analytics isn’t the only thing you can do with Application Insights though – we can use some more advanced, proactive features. In the linked document, it states “For example, if your app loads slowly on some OS versions, or has slower responses in particular geographical location, you’ll get an email about it. Proactive Detection uses machine learning and data mining to help you find issues that would be hard to detect – and are often only discovered when customers complain.”

For more information about this type of diagnostics, see this Microsoft documentation.

Lastly, there’s also the Application Map, which allows you to see a diagram of your setup, showing the dependencies of your components.


By clicking through on the various components, we can see which parts of our setup are working correctly and which have issues. As you can see in the image above, there seems to be something wrong with my search. I can then click through on that to see some detailed information.


By clicking through on in the chart, I can also see even more detail (in the below image, I clicked the ‘Dependency Failures’ chart)


From there I can then even create a new Work Item, either in Visual Studio Team Services or in GitHub, making sure the Work Items have all relevant data embedded.

I’ve covered only a small portion of what Application Insights can do for us, but I do hope I’ve shown its power and its usefulness. I’m pretty excited, in any case 🙂

Sitecore – Retrieve data from MongoDB

As we all know, Sitecore’s xDB collects a TON of data. So if we want to pull some of that data from the MongoDBs, how do we go about that? I had never worked with Mongo before, so in case you haven’t either I hope this is of use to you.

Initially, to view the documents in the Mongo collections I used the free edition of MongoVue. It is great for things like viewing how many contacts you have in your Contacts collection, or digging into the details of the Interactions.

Mongo Collections Overview

Now, if I want to see some of the Interactions, that’s completely possible as well. For instance, I can either use the View option on the Contacts collection, or I can write a query.


Contact details

Writing a query:

Sample query in MongoVue

Of course, you can do the same thing in the Mongo shell as well, if you prefer.

I’ve found that I keep re-using a couple of different queries, so here are a couple of the ones I found useful:

Finding interactions with a certain amount of Engagement Value points:

{ "Value" : { $gt : 10 } }

This will get all interactions with more than 10 Engagement Value points. Instead of $gt (greater than), you can also use other operators such as $lt (less than), $lte (less than or equal to) or $gte (greater than or equal to).

For more query operators, view the Mongo Docs page.

In case you’re using the Mongo shell, you might want to add a limit to the results as well, and format the documents. In the Mongo shell, your query might look like this (assuming you’ve set the db to be your Mongo Analytics database):

    { "Value" : { $gt : 10 } } 

Limit here is pretty obvious, it will only result the first result in our case. Pretty will format the document, in a similar way to CTRL+K, CTRL+D in Visual Studio. Another thing you might want to add in the query for the Mongo shell is a projection of the fields you’d like to be displayed or hidden. Projections can be used as follows:

        "Value" : { $gt: 10 } 
    { "ContactId" : 1 } 

In this case, we’ll only be displaying the ContactId field. To exclude a field, you can set it to 0 instead. For more information on Projection in Mongo, I again refer you to the Mongo Docs page.

Another query I tend to use is to figure out how many contacts I have from various countries. From MongoVue:

{ "GeoData.Country" : "United Kingdom" }

I have to admit that I’m not sure how to count the number of records in MongoVue.

From the Mongo shell:

db.Interactions.find( { "GeoData.Country" : "United Kingdom" } ).count()

Lastly, finding interactions with (for instance) 2 page events:

Again, in MongoVue:

{ “Pages.PageEvents” : { $size: 2 } }

In the Mongo shell:

db.Interactions.find( { “Pages.PageEvents” : { $size: 2 } } ).pretty()

On a last note, it’s important to realize the fieldnames are case sensitive.

On the very last note, for some more (beginners) details on MongoDB, not only writing queries but also architectural information, I would very highly recommend the Introduction to MongoDB course on PluralSight.

I hope this will be of some use 🙂

Hidden settings: MinimalProfileScoreCount

I was running through the Sitecore Experience Editor the other day, where I wanted to check whether my various patterns would be showed the correct personalized content. The easiest thing to use is the Experience Explorer, which you can get to through the Other button in the Mode chunk.

Opening the Experience Explorer

This will open the Experience Explorer on the left-hand side of the website with the Experience Viewer on the right-hand side. In the Onsite Behavior tab I set the proper scores to match a particular pattern card. After clicking ‘Apply’ I didn’t see any difference until I checked the Onsite Behavior tab in the Experience Viewer.

Experience Viewer

Easily managed by just clicking ‘Apply’ 2 more times, but a bit annoying. Turns out, there’s a way of going around this: The Analytics.Patterns.MinimalProfileScoreCount setting. By default it won’t show up in your settings so you’ll have to manually add it. After applying this setting the profile personalization will be applied directly after setting the value of Analytics.Patterns.MinimalProfileScoreCount to 1.

Before you change it though, keep in mind that this will not only affect the Experience Explorer, but also the ‘normal’ website – and as such might have adverse effects.