Wednesday, February 1, 2012

The Customer Engagement Series: A quick connect to Facebook

I am really excited about the huge growth in socially-connected Sitecore sites we’re going to see this year.  With the Sitecore Rules Engine, it just makes a lot of sense—make recommendations based on your visitor’s Likes, birthday, location…just about anything.  I like demonstrating the many ways Sitecore has made the mechanics of this--grabbing some profile information from Facebook and changing the page experience because of it--natural and simple.  The story gets even better when we consider how easy it is to introduce our own custom logic altogether—but for today, let’s stick to a use case and solution that doesn’t involve any coding.

First, Sitecore has introduced a free module called Sitecore Social Connected.  In about 20 minutes with the documentation, you can have this module installed and working.  Most of the time involves getting familiar with setting up a Facebook App if you’re not already.  Nothing that requires a developer here.

The Social Connected feature contains lots of cool features—prebuilt Like and Tweet controls that you can use as is, login controls and functionality for Facebook, Twitter, LinkedIn and Google+.

What I’d like to concentrate on in this quick article is the ability to allow your visitor to login using his Facebook credentials to customize his experience.  Remember that the Sitecore Rules Engine is a simple way to tie a Condition (does it exist, yes/no) to an Action (what should my control do differently as a result of the condition evaluation….show some different HTML, invoke a different control, message an external system).

In Sitecore 6.5, there’s even a prebuilt condition that can allow a content editor / marketer to look for a specific profile value.  My use of the word profile here means a persistent attribute for a logged in user (the Sitecore .NET Profile table, a CRM via a connection, some external system—in this case Facebook).

Here’s my Condition that looks in the “Movies” area of the logged in Facebook user profile for the word “Drive”:

SNAGHTML5807847

The Social Connected module comes preconfigured with mappings to lots of Facebook profile fields…through configuration you can extend these properties.

Here’s the full fb_movies profile field for someone who has included the movie Drive in his list of Movies He Likes:

fb_movies
= data => name => Drive category => Movie id => 105687816178274 created_time => 2012-02-01T13:55:03+0000 name => The Town category => Movie id => 92320479952 created_time => 2012-01-04T16:34:30+0000 paging => next => https://graph.facebook.com/me/movies?

As you can see, we could have gotten a lot more fancy with our parsing of this or any other Facebook profile field, but the simple “Contains” operator from Sitecore does the trick here.

Now, as a simple control (like the Sidebar control in the Sitecore Starter Kit site) can show a different content item / HTML block as a result of this conditional. 

If Drive isn’t found in his movie Likes, use the default message and opportunity to ask him to sign up:

image

If he’s already logged in and Likes Drive, ask him to watch it again:

image

 

That’s all there is to it!  A simple Hack to write out all Facebook profile properties is helpful as you start to investigate what’s there for you to use:

Sitecore.Security.Accounts.User user = Sitecore.Context.User; 
Sitecore.Security.UserProfile profile = user.Profile;
litOutput.Text = "";

foreach (string attributeKey in profile.GetCustomPropertyNames())
{
string attributeValue = profile.GetCustomProperty(attributeKey);
litOutput.Text += "<h3>" + attributeKey + "</h3> =" + attributeValue + "<br />";

}