Adding custom properties to Social Connected users profile

Social Connected module gives the ability for website users to register through their social networks, like Facebook, Twitter, Linkedin and Google+, the module does a good job of mapping users data from these networks and add them to user profile in sitecore.

Recently, we needed to add our own custom properties into users registered through Social networks, i was able to do this by using [social:connector:user:created] event.

The following code grabs the user object from event parameters, and update the profile with our own custom property:

namespace Sitecore.SharedSource.Events.Social
{
    public class UserCreated
    {
        protected void UpdateUserProfile(object sender,  EventArgs args)
        {
            var user = Sitecore.Events.Event.ExtractParameter(args, 0) as Sitecore.Security.Accounts.User;
            if(user!=null)
            {
                user.Profile.SetCustomProperty("CustomPropertyName", "CustomPropertyValue");
                
                user.Profile.Save();

            }
        }
    }
}

You need to add the following configurations in your include folder

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="social:connector:user:created">
        <handler type="Sitecore.SharedSource.Events.Social.UserCreated, Sitecore.SharedSource" method="UpdateUserProfile"/>
      </event>
    </events>
  </sitecore>
</configuration>

Hope this helps!

Comments

Popular posts from this blog

Attaching a file on WFFM Send email action

Solr with Sitecore Checklist

Set Workflow using Item Buckets Search Operations