Tag Archives: sitecore experience profile

Sitecore 8 – how to update contact through FXM API

This post will talk through how to setup a custom actions to be executed to update Sitecore contact through FXM API. If you don’t know about FXM you can read a brief overview about it in the Sitecore site and the doc site

If you’ve played around with FXM and it’s javascript API then you would know that you can trigger client side call to send information back to Sitecore regarding the current visitor browsing behaviour. But what does one do if we want to update the Contact information instead? say the current visitor email address if they fill out a newsletter subscription form? or their unique user id if they have logged in through the external application?

Looking at the available javascript FXM API there’s these three methods available:

  1. SCBeacon.trackEvent
  2. SCBeacon.trackGoal
  3. SCBeacon.trackOutcome

and there’s no such things as SCBeacon.updateContact which we sought after. After some investigation there’s a couple of ways to do this.

1. A custom web service call to the Sitecore server

Setup a custom web service in Sitecore server and pass in the current visitor contact id for custom processing. Doable but I’m looking for something that can be done through the same javascript API if possible as it would mean greater coverage – can be reused by other external site. By doing it through FXM javascript API we don’t have to setup web service call in each external sites.

2. Modify the beacon script to include our custom function 

Modify the beacon script and include the custom SCBeacon.updateContact function. Figured that this won’t be ideal as we would muck around with the bundled javascript and won’t be compatible in Sitecore future upgrades.

3. Hook into one of the available methods to do some custom processing

This seems like the best place to start. Out of the available methods I choose to override the trackEvent tracking implementation because the action that I want to captured falls to “system” type action, doesn’t relate to conversion (Goal) or has monetary value (Outcome). Plus if I use page events then by default the events triggered will not show in the Experience Profile which might confused the marketers.

OK, let’s do this.

This is done with the latest Sitecore version at the time of writing which is 8.1 update 3.

First let’s open the Sitecore.FXM.config in /website/app_config/include/fxm folder

I opened up Sitecore.FXM.Pipelines.Tracking.TriggerPageEvent.RunRegisterPageEventProcessor using dotPeak to find out that it will run the tracking.registerpageevent pipeline

When I take a look at Sitecore.FXM.Pipelines.Tracking.RegisterPageEvent.RegisterPageEventProcessor and what it does it seems this would be the best place to put my custom logic

We can override the TriggerPageEvent method and implement our custom processing.

The next step is for us to create our custom Processor class which extends from Sitecore’s default RegisterPageEventProcessor

After that we need to register our custom processor class in the config file. For best practice use Sitecore config file patching to do.

In our custom config file we override the default processor class to process the triggered page events with our custom processor class. Put the file in /website/app_config/include/zzz.POC/ folder

Now that we have our custom processor class and have registered it through the custom config file, we need to create the actual page event items in Sitecore.

Here’s what the created page event items looks like in my setup.

registered-custom-page-events

And now to test it out, browse to the external site  and open the developer console to run these javascripts

We can check the end result in MongoDB after the session has timeout

updated-contact-through-FXM

And in the Experience Profile

updated-contact-through-FXM-xFile

That’s it folks.