No Speak Experience Profile Tab

For a client i was asked to collect some extra data and put it in Xdb and use it to personalize content.  The approach was simple create a facet like Pete Navarra outlines here.  Then build some custom rules like i outlined here.  Finally it was asked to add the collected data to the Experience profile.  That’s when the pain came.

Adam Conn has outlined how to do it in the official Sitecore way here.  As you can see the process involves building a Speak component for the tab, this is a long process and very tedious.  This lead me to report it as a large task, and the client wasn’t willing to take the extra time needed to get it all set up properly and the request was abandoned.

This lead me to think that there must be a better way, which i have found!

Enter the Experience Profile Express Tab

You can find the Nuget package here.  and the source code and developer documentation here.

This Module automates the construction of a speak component and wraps it around a proper MVC structure where you build a controller class to generate a model poco generated from the contact and pass it to a view.

For my first application of this module I built a tab to show Demandbase data collected by the Sitecore Demandbase module (which you can contact your Demandbase sales rep to acquire).

demandbasetab

This tab can be accomplished with a single C# class. First we take the data from the Demandbase facet which is a json object. We deserialize this to dictionary and dump it out to HTML.

	public class DemandbaseTab : EPExpressTab.Data.EpExpressModel
	{
		public override string RenderToString(Contact contact)
		{
			dynamic o = JsonConvert.DeserializeObject<ExpandoObject>(
				contact.GetFacet<IXdbFacetDemandbaseData>("Demandbase Data").DemandBaseData ?? "");
			StringBuilder sb = new StringBuilder();
			if (o == null)
				return "<div>Demandbase information not available.</div>";
			IDictionary<string, object> tst = (IDictionary<string, object>) o;
			bool even = false;
			foreach (string attr in tst.Keys)
			{
				if (tst[attr] is string)
				{
					sb.Append(
						$"
<div style='background-color:{(even ? "#fff" : "#eee")}'><span style='width:200px;display:inline-block;font-weight:bold;font-size:medium;'>{UppercaseWords(attr)}</span>{tst[attr]}</div>
");
					even = !even;
				}
			}
			return sb.ToString();
		}

		public override string Heading => "Demandbase Attributes";
		public override string TabLabel => "Demandbase";
		private string UppercaseWords(string value)
		{
			char[] array = value.ToCharArray();
			// Handle the first letter in the string.
			if (array.Length >= 1)
			{
				if (char.IsLower(array[0]))
				{
					array[0] = char.ToUpper(array[0]);
				}
			}
			// Scan through the letters, checking for spaces.
			// ... Uppercase the lowercase letters following spaces.
			for (int i = 1; i < array.Length; i++)
			{
				if (array[i - 1] == ' ')
				{
					if (char.IsLower(array[i]))
					{
						array[i] = char.ToUpper(array[i]);
					}
				}
				if (array[i] == '_')
				{
					array[i] = ' ';
				}
			}
			return new string(array);
		}
	}