Web App analytics with Azure Application Insights and WordPress

Application Insights have been a great ally to help developers detect, diagnose and understand users behavior in applications. For those new to this platform, Application Insights is an analytics solution that monitors live applications no matter if they are the web or a stand-alone app running Windows, iOS, OS X or Android.

http://www.azurekb.com.br/wp-content/uploads/2015/10/00-sample.png

In this article, we talk about a new plugin released by Microsoft that makes very easy to integrate Azure Application Insights with WordPress.

Install

To gets started, download the plugin from this link. Alternatively, go to WordPress administration -> Plugins -> Select Add New -> Search for “Azure App Insights Plugin“.

http://www.azurekb.com.br/wp-content/uploads/2015/10/Capture.png

If you opted for installing it manually, all you have to do is:

  1. Extract the contents to the WordPress plugins directory at wp-content\plugins.
  2. Activate the plugin by navigating to WordPress Administration -> Plugins. If you don’t see the plugin on the list, refresh the page or double check step 1.

Register the Application in Azure AD

Now we have to register the plugin as an authorized Azure AD application. Sign into Azure Portal (classic) and navigate to Azure Directory. Choose the directory you would like to use and under Applications tab, click Add to register a new application.

http://www.azurekb.com.br/wp-content/uploads/2015/10/AzureAd_AddApp2.png

Choose “Add an application my organization is developing“.

http://www.azurekb.com.br/wp-content/uploads/2015/10/AzureAd_AddApp3.png

Type a familiar name for this application and select “Native Client Application”

http://www.azurekb.com.br/wp-content/uploads/2015/10/AzureAd_AddApp4.png

Enter a value for Redirect URL with the format http://mydomain.com.br/wp-admin/options-general.php, where the root of WordPress is also the root of the Web Server. If for some reason you changed the installation path, make the changes accordingly.

http://www.azurekb.com.br/wp-content/uploads/2015/10/AzureAd_AddApp5.png

You should now see your application in the applications list. Select it and navigate to Configure Tab. Scroll down to the bottom and look for “Permissions to other applications“. Click Add application and add “Windows Azure Service Management API“, make sure to also change Delegated Permissions from 0 to 1.

http://www.azurekb.com.br/wp-content/uploads/2015/10/AzureAd_AddApp6.png

A particular note, in the official documentation, they also ask you to add “Microsoft Azure Data Catalog“. The plugin worked for me without this particular permission, and in fact, I didn’t even had it on my list of Microsoft Apps to add. You are probably safe to skip this one.

Create App Insights

Now switch to preview portal and add a new Application Insights. You can read more about creating App Insights here.

http://www.azurekb.com.br/wp-content/uploads/2015/10/AppInsights1-1024x532.png

Configure the plugin

Now go back to WordPress Administration and navigate to Settings -> Application Insights Dashboard

http://www.azurekb.com.br/wp-content/uploads/2015/10/wordpress_plugin1.png

Insert your Tenant ID and Client ID then hit Authorize Plugin. You can get both IDs from the Configure Tab of your application in Azure AD.

http://www.azurekb.com.br/wp-content/uploads/2015/10/wordpress_plugin2.png

If everything goes as expected, you should see “Plugin authorization succeeded” and a few more boxes to setup. Select the subscription, component and insert your Instrumentation Key. See the image below to know how to get this key.

https://acomdpsstorage.blob.core.windows.net/dpsmedia-prod/azure.microsoft.com/en-us/documentation/articles/app-insights-javascript/20150824050023/02-monitor-web-page.png

Copy and paste the values and click Update Options.

http://www.azurekb.com.br/wp-content/uploads/2015/10/wordpress_plugin3.png

All done! Wait a couple minutes and you should see the metrics starting to appear in WordPress dashboard (or App Insights in preview portal).

http://www.azurekb.com.br/wp-content/uploads/2015/10/wordpress_plugin4-1024x725.png

References

[1] Determine your WordPress web app usage with Application Insights

[2] Visual Studio Application Insights

[3] Azure App Insights plugin

[4] Application Insights for JavaScript web apps

- See more at: http://www.azurekb.com.br/web-app-analytics-with-azure-application-insights-and-wordpress/#sthash.MXr54aZ6.dpuf