Loading...

Get insights about Power Apps usage with Microsoft Clarity PCF code component

Get insights about Power Apps usage with Microsoft Clarity PCF code component

Getting insights on user behavior in Power Apps canvas apps can be in various ways - for instance, you can analyze app telemetry with Azure Application Insights and trace events. If you are more interested in visual heatmaps and session recordings, you might already have had a look at Microsoft Clarity, which exactly provides that:

What is Microsoft Clarity and how do I connect it to a Power Apps canvas app?

Clarity is a user behavior analytics tool that helps you understand how users are interacting with a website through features such as session replays and heatmaps. It is installed by adding a tracking code into the <head> section of the website.

As a Power Apps canvas app running in the browser is also still just a website, we only need to find a way on how to inject the Clarity JavaScript script into the head of our canvas app.

Unfortunately, there is no connector for Microsoft Clarity, but we can leverage the Power Apps component framework for that.

Power Apps component framework to the rescue

With Power Apps component framework we can create code components for Power Apps. I created a code component for Microsoft Clarity, so that we can use Clarity in our canvas apps.

High level overview

To give you an idea on how to create this, here is high level overview- it’s not meant to replace extensive learning with very detailed step-by-step instructions though. I will link to resources though if this is your first code component - it was my first :-)

  • Sign up for a free Clarity account
  • Set up your project

new Clarity project

  • Use Power Platform CLI to create the code component
  • In the scaffolded project, locate ControlManifest.Input.xml and index.ts
  • Update the ControlManifest.Input.xml file to
<?xml version="1.0" encoding="utf-8" ?>
<manifest>
<control namespace="ClarityNameSpace" constructor="ClarityCodeSnippet" version="1.0.0" display-name-key="ClarityLovesPowerApps" description-key="Clarity Code Component to analyze user behavior" control-type="standard" >
<property name="YourClarityProjectID" display-name-key="<your-clarity-project-id>" description-key="description" of-type="SingleLine.Text" usage="bound" required="true" />
<external-service-usage enabled="false">
</external-service-usage>
<resources>
<code path="index.ts" order="1"/>
</resources>
</control>
</manifest>
  • In the index.ts file, we first need a private _Container: HTMLDivElement; above the constructor
  • then add the following code to the init method
 public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container:HTMLDivElement): void
{
const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script');
script.innerHTML = '(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);})(window, document, "clarity", "script", "<your clarity project id>");'
head.insertBefore(script, head.firstChild);
const textDiv = "<div>We are tracking this app with Microsoft clarity, have a lovely day!</div>"
this._Container = document.createElement("div");
this._Container.id = "ClarityDivID";
this._Container.innerHTML = textDiv;
container.appendChild(this._Container);
}

When you now use the app, you can open Edge Dev tools on the Network tab and see the work Clarity is doing:

Clarity in Edge Dev tools

How does this now look like in our Canvas app?

In your Canvas app, you can either style your code component or you can set the Visible property to false to hide it.

Clarity properties

It takes a decent while (I guess about 90 minutes) for data to arrive for the first time in Clarity, but after that it runs smoothly - here is how the dashboard then looks like:

Clarity dashboard

If we now want get more into the details of users are interacting with our apps (sometimes easier than asking them), we can watch a replay of the session recordings:

Clarity recording

This gives us information on where users click, scroll and type.

Heatmaps are a valuable feature to determine which parts of an app are most selected:

Clarity heatmap

Where to find the component

You can find this component on my GitHub - Let me know if you have questions! If you found this blog post useful, please also subscribe to my newsletter - news coming about every 2 months, I promise to not spam you!

Published on:

Learn more
Luise Freese: Consultant & MVP
Luise Freese: Consultant & MVP

Recent content on Luise Freese: Consultant & MVP

Share post:

Related posts

Canvas App: Gallery Search Using the ‘DelayOutput’ Text Property

In this informative article, you'll learn how to enhance the search process for gallery items by using the DelayOutput text property. The Dela...

9 hours ago

Mastering Power Fx Formulas with Copilot in Power Apps

Are you ready to harness the power of AI in your Power Apps? With Power Fx formulas and Copilot, you can streamline your app building process ...

10 hours ago

Microsoft Power App Environments Retention Period

If you are wondering how long different environment types within the Microsoft Power Platform retain your backup data, this article is for you...

3 days ago

Increment and Decrement in Power Apps Dataverse Workflow | Tutorial

This is a video tutorial about incrementing and decrementing values in Workflow Power Apps Dataverse. With the help of this tutorial, you will...

4 days ago

Power Apps April 2024 Feature Update: What's New for Makers, Admins and Users | Power Apps Blog

If you're a Power Apps user, you'll be glad to know that the platform has some exciting new features in store for you. In this monthly feature...

5 days ago

Customer Managed Encryption Keys for Power Apps Now Available!

Microsoft has announced the General Availability of Customer Managed encryption keys (CMK) for Power Apps data in your environments. This upda...

5 days ago

Building Power Apps Business Process Flows & Documentation

Get ready to dive into the world of Power Apps with this informative tutorial that covers building a business process flow for your model-driv...

6 days ago

How to Create Multi-Step Forms in Power Apps | Step-by-Step Tutorial

If you're looking to streamline your form creation process, this tutorial on creating multi-step forms in Power Apps is the perfect starting p...

7 days ago

How to Add AI Prompts to Your Power Apps | Step-by-Step Guide

In this video tutorial, you'll learn how to incorporate custom AI prompts into your Power Apps canvas app using Power Virtual Agents. The tuto...

7 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy