For a while now I’ve been writing about collecting and displaying data unique to a client in Sitecore’s Experience Profile. What went hand in hand with that is the use of Sitecore Goals and Outcomes – giving a business value, sometimes monetary, to actions performed on the site. The Experience Profile currently shows the goals for each Contact.
However, beyond the goal being registered we don’t know the context in which the goal was met. Wouldn’t it be great if we knew WHAT was added to the basket when the ‘Add to Basket’ goal was registered?
For example, a directory listing for a business’ employees. A goal is registered when the User clicks the ‘Call Now’ or ‘Email Now’ button to communicate with that member of staff. We will register the ‘Called Employee’ or ‘Emailed Employee’ goal but we can also include which employee contacted and the phone number or email address used.
But the Experience Profile doesn’t show this valuable contextual information even though its in xDB. So let’s do something about that.
Extending the Goals ExperienceProfileContactViews Pipeline
Back to the old ExperienceProfileContactViews Pipeline Groups. This time, we’re going to extend the Goals section to include two new pipelines. First, a pipeline to add an additional column to the DataTable to hold the Goal’s Context. Secondly, a pipeline to fill that column with data retrieved from xDB via a new DataSourceQuery, which we’ll get to shortly.
With me so far? Good.
Adding the column is as simple as below but needs to occur once the GoalsDataTable has been constructed by the appropriate pipeline.
Entering the context of the goal into that column is a little more work. Pulling apart the data in the QueryResult to get the goal context and entering it into our new column. This needs to occur after the existing pipeline which populates the goals with data from xDB.
The schema which files both reference is as follows
Retrieving Goal information from xDB
As you may know, the Goal Type is a PageEvent. PageEvents are stored in xDB against a Contact’s Interaction, not the Contact themselves. Which makes sense architecturally speaking. A Contact interacts with the site, that interaction includes a number of page views, a page view may result in a page event.
When registering a goal I use the Description property to hold the context of the goal. In this example, it would be the name of the Employee the user chose to contact and medium of the contact; phone number or email address. This is done by the following;
This Goal Description ends up in the Data property on the PageEventData type which is written to xDB (so we don’t have to worry about writing something custom there). So in order to retrieve it for our new column we need to query xDB. To do that we need to replace the existing Sitecore.Cintel.Reporting.ReportingServerDatasource.Goals.GetGoals type with our own.
Similar to the existing GetGoals type we are replacing, we are querying the Interactions Collection in xDB for entries matching the Contact’s Id we are currently viewing in the Experience Profile. We are asserting that at least one PageEvent exists in the Page.PageEvents property so we don’t get null PageEvents. Our query requests which Fields we want from the entry specifying the Pages_PageEvents_Data property which holds our goal context.
The Experience Profile being built with SPEAK means to finish this off we need to do a bit. Fortunately, it is a very small bit. We simply need to add a new Item based on the ColumnField template in the Goals ListControl so that our new column displays in the list of Goals. Create this item under the path /sitecore/client/Applications/ExperienceProfile/Contact/PageSettings/Tabs/Activity/Activity Subtabs/Goals/GoalsPanel/Goals entering a sensible HeaderText and a DataField value that matches our schema name.
The result of our hard work;
And that’s it!
A good effective improvement to the Goals area of the Sitecore Experience Profile. Give your Content Editors the what, why and how for when the User achieved the goal.
If you like this but don’t fancy doing work I’ll be submitting this as a Sitecore Marketplace Module shortly so you can just take it from there. I will update this post soon as its available for all!