Integrate Azure Application Insights With Power Apps

Below are the components used in this document:
  1. Power Apps
  2. Azure Application Insight

Introduction

 
Many times we get a requirement where a user has to track user activities like how many users visited the screen or which user clicked on a particular button on the Power App Form. This can be made possible using Azure Application Insights. You can check the link on how to create an Azure Application Service by clicking on MS Doc link. Below is the step by step description to achieve the same.
 

Get Application Insight Instrumentation Key

  1. Open Azure Portal and browse to your Application Insight

    https://www.c-sharpcorner.com/Publish/CreateArticle.aspx?ArticleID=ccf33ae6-0b8b-4ba0-990c-9abf68f25c22&PagePath=/article/integrate-azure-application-insights-with-power-apps/default.aspx

  2. Copy the Instrumentation Key mentioned on the screen.

    https://www.c-sharpcorner.com/Publish/CreateArticle.aspx?ArticleID=ccf33ae6-0b8b-4ba0-990c-9abf68f25c22&PagePath=/article/integrate-azure-application-insights-with-power-apps/default.aspx

Add Azure Application Insight to Power Apps

  1. Open your Power Apps form and click on the App on the left menu bar

    https://www.c-sharpcorner.com/Publish/CreateArticle.aspx?ArticleID=ccf33ae6-0b8b-4ba0-990c-9abf68f25c22&PagePath=/article/integrate-azure-application-insights-with-power-apps/default.aspx
  1. Paste the Instrumentation Key copied from the Azure portal in the below highlighted section

    https://www.c-sharpcorner.com/Publish/CreateArticle.aspx?ArticleID=ccf33ae6-0b8b-4ba0-990c-9abf68f25c22&PagePath=/article/integrate-azure-application-insights-with-power-apps/default.aspx
  1. Now your Power App form is integrated with Azure Application Insight, but how to write the information to insight? That can be done using Trace(). For example: log information of the current user to Insights.

    https://www.c-sharpcorner.com/Publish/CreateArticle.aspx?ArticleID=ccf33ae6-0b8b-4ba0-990c-9abf68f25c22&PagePath=/article/integrate-azure-application-insights-with-power-apps/default.aspx

    Here in the above example, I am tracing user login, the type of trace is just simple information (since it is not a warning or error to be logged) and lastly I am sending some custom details like User Name, UserEmail and Screen Name to be logged in Insights.
  1. Similarly we can log the button clicks as well to Insights.

    https://www.c-sharpcorner.com/Publish/CreateArticle.aspx?ArticleID=ccf33ae6-0b8b-4ba0-990c-9abf68f25c22&PagePath=/article/integrate-azure-application-insights-with-power-apps/default.aspx
Here in the above example I am logging User Name, User Email, Screen, Event, and some other metadata from the form.
 
Now play the power app form and you can browse to the screens and click on the button where you are tracing the information to Insight. Then you can browse to Azure Portal to view the Information logged in the Insight you created.
 
https://www.c-sharpcorner.com/Publish/CreateArticle.aspx?ArticleID=ccf33ae6-0b8b-4ba0-990c-9abf68f25c22&PagePath=/article/integrate-azure-application-insights-with-power-apps/default.aspx 
 
That is it. I hope you have learned something new from this article and will utilize this in your work.


Similar Articles