Displaying Custom Facets in the Contact Profile

Sitecore Hints & Tips

In our previous post, we explained how to create custom facets and store them in xDB. In this post, we're going to show you how to display custom facets in experience profile.

Experience profile lets you monitor the behaviour of contacts that have interacted with the website. It allows you to search a specific contact, either via a name or email.

If you click on the contact, then you will be able to view the contact profile as shown in the image below. This is cool right?! However, you may find that it is not exactly perfect as Sitecore does not automatically display custom facets.

Sitecore Contact profile

In order to to achieve this, custom code is required. Therefore, we're going to show you how to create a custom tab in the contact profile and display custom facets step by step.


Step 1 - Create custom facets

In our previous post, we had created a newsletter subscriptions facet and stored it in Sitecore xDB.

Sitecore Newsletter subscription facet

If you want to learn how to create custom facets, you can refer to our previous post here.


Step 2 - Create Web API for Retrieving the Facets by Contact ID

This is much like any other WebAPI that you will have created, and we would recommend applying access restrictions to the API for security reasons, you can apply Sitecore's existing security filter called AuthorizedReportingUserFilteruse, which is defined in Sitecore.Cintel.dll.

Once you have completed the implementation of your API, the next step is to register the API in route.

Sitecore Virtual fields

Step 3 - Create SPEAK Script

The SPEAK script will call our API, so firstly, we're going to create a folder called "Subscriptions" under /sitecore/shell/client/Applications/ExperienceProfile/Contact/Subsriptions.

Next, we then add subscriptionsTab.js and subscriptionsTab.css under the folder (as shown as below).

Sitecore Daterange field

Associate the created CSS in the core database.

You will need to add style item in core database and point at the css file. The defined css will be loaded automatically when the contact profile page is loading.

Sitecore Daterange field

Associate the created JavaScript in core database.

In this step, we've created a new custom tab, called "SubscriptionPanel" and PageCodeScriptFileName is where you should associate with the JavaScript that we have just created above.

Sitecore Daterange field

In order to verify that what you've done so far is correct, check that the new custom tab "Subscription" exists, and that both subscriptionsTab.js and subscriptionsTab.css are loaded after contact profile page is loaded.

Sitecore Daterange field

The next step is to write a script for retrieving the data via the custom API you created above. Sitecore use SPEAK as a framework for developing Sitecore application with a consistent interface. The syntax is very simple to follow and extend.


Step 4 - Binding JSON Object to the Controller on the Custom Tab

The last step is to display the Json data on the custom tab.

In the code snippet, you will find this code cintelUtil.setText($that.WhatsOnValue, jsondata.WhatsOn, true);. This sets TextBox "WhatsOnValue" within the controller, so it contains the JSON value. Then, the next question is how to define the "WhatsOnValue" textbox in Sitecore? Don't fret, we will show you how this can be done!

Add text rendering (Note: because we're using SPEAK 1.1 framework, we will have to select the text rendering under SPEAK 1-1).

Sitecore Daterange field

Set the ID to "WhatsOnValue", this is the ID where the cintelUtil.setTextto function is referring.

Sitecore Daterange field

Congratulations!! You've done all the code and configuration. Now let's check out the result, rhe "subscriptions" tab should display in the contact profile page as well as the custom facets associating with the contact.

Sitecore Daterange Field

We hope that you found this post is useful and enjoyed the article.

— Zhen Yuan - June 2017

Want more?

Back to the Blog

Switch have been awarded a Sitecore Experience Award for Best in Connecting the Experience.
Read more
Sitecore Experience Award Winner 2022

Switch acknowledges the Traditional Custodians of the lands where we live, learn, and work and we pay our respects to their Elders past and present.

Sydney
Level 4
109 Pitt Street
Sydney NSW 2000
Phone +61 02 8188 5959
Melbourne
Level 22
120 Spencer St
Melbourne VIC 3000
Phone +61 03 8566 8819
New Zealand
11-19 Customs Street West
Auckland 1010

Phone +64 9 887 0338
Singapore
8 Cross Street
Singapore, 048424

Phone +65 3106 4217
ABN 15 120 572 750   ·   © 2023 Switch

Subscribe Now

Sign up to our newsletter to gain access to this page.

No thanks