<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=259446424624044&amp;ev=PageView&amp;noscript=1">

Fullscope Blog

A real-world look at digital transformation.

How to: CRM Portal Web Page Tracking

By James Trobaugh | June 3, 2019

There are often times when a customer will want to know what records a Contact is viewing in the CRM Dynamics Portal. Historically, this capability was available out of the box with the Tracking feature included in the Portal solution but due to performance issues, the Web Page Tracking feature was deprecated and is no longer an option. However, with a little creativity and some custom coding, that particular information can be captured and stored within Dynamics CRM. 

This is a multi-step process where a Web Page’s JavaScript will make a call to another Web Page within the same Portal, and that Tracking Web Page will include some Liquid code that will make a Fetch Query to CRM. The Fetch Query will trigger a Plug-In that will in turn extract information from the query and create a new Tracking Record in CRM. 

Fetch Query will trigger a Plug-In Microsoft Dynamics 365

It may sound complicated but it’s not. I will break it down into some simple steps.

First there needs to be a custom Entity in CRM, this is the entity that our Fetch XML will query against and will trigger our Plug-in

creating a custom Entity in CRM Microsoft Dynamics 365

I have created an entity called Custom Portal Action and it contains two string attributes, Action and Parameters (I will explain how these attributes are used later)

Also created another entity called Portal Incident Tracking with two lookup attributes, one for Contact and one for the Incident since I’m going to be tracking Portal User’s accessing Case records via the Portal. Of course this entity could be setup to track other entities or even some other information regarding the Portal page that is be viewed. For this example I’m just going to track the Contact and the Case record that was viewed.

Secondly there needs to be a new Web Template that will contain the Liquid code to query the Custom Portal Action. I’ll include all the code samples at the end of this article for simple cut and pasting.

new Web Template that will contain the Liquid code to query the Custom Portal Action

What will happen is this query will trigger a Plug-In in CRM, the Plug-In code will pull the Parameters value from the Query and extract the Contact Id and Case Id that will be stored in the Portal Incident Tracking record. Note that there is a value called cacheString, this will be a random value created by the JavaScript and passed to the Fetch Query. The reason for this is because the CRM Portal likes to cache values and if the Fetch Query is the same as a previous Query then it will draw from its cache and not make the call to CRM, thus never triggering our Plug-In. Stay with me, this will all make sense soon.

Now create the Page Template that will use this Web Template


 create the Page Template that will use this Web Template Microsoft Dynamics 365 CRM

 

And then create a Web Page that will use this Page Template



create a Web Page that will use this Page Template microsoft dynamics 365 crm

Now for the third part I will add some JavaScript functions to the Web Page that I want to track, for this example I am wanting to track the Case Details page, so on the Advanced tab of the Web Page Content for the Case Details page I will add my JavaScript

customer service case details microsft dynamics 365 crm JavaScript functions to the Web Page

On the loading of the Web Page the JavaScript will call my Track() function, this function is going to make a Get call to the Custom Portal Actions Web Page that we created prior and will pass the User Id, the Case Id and the random string value that will be used to make our query unique. The full code is available at the bottom of this article

Now for the final part, a plug-in will be needed to capture the Fetch Query and create our tracked record. Using the C# code below in the Plug-In Class will capture the FetchXML Query and extract the Parameter value, in this instance it’s the User Id and Case Id delimited with commas. The code will parse the string and break it into a string array, then assign those values to the new Portal Incident Tracking record.


 a plug-in will be needed to capture the Fetch Query and create our tracked record

Once you have the Plug-In created and deployed to your CRM instance you simply need to connect it to the correct message for the Custom Portal Action entity. It will need to be setup for the RetrieveMultiple Message



microsoft dynamics 365 crm connect plug-in created to the correct message for the Custom Portal Action entity

Even though there are a lot of moving parts to this, once it’s in place it works very well and smoothly. The client is now able to run reports and see which Contacts have been viewing particular Case records. Other information could be collected as well, you would simply need to capture it via the JavaScript and pass it along with the parameters in the Query for the Plug-In to process.

Here is the Web Template Liquid code


Web Template Liquid code microsoft dynamics 365 crm portal tracking

The Web Page JavaScript


The Web Page JavaScript microsoft dynamics 365 crm portal tracking

 

 Questions?

Contact Us

Comments

Latest Posts