WHAT IS FACET

A facet is part of information that a contact or interaction can have. Sitecore xDB provide lots of out of the box facet that can be used to store user information inside the xDB database. For example: PersonalInformaiton, EmailAddress, ProfileScores, EngagementMeasures and many more...

You can see the complete list by using ILSpy tool by opening the assembly Sitecore.XConnect.Collection.Model.dll.

Sometimes out of the box facets are not sufficient to store all require user information. So you may have to create custom Facet to store customer/user details.

HOW TO CREATE CUSTOM FACET

Following are the steps to create your own facet:

  1. Create custom facet class
  2. Create a model class
  3. Deploy model

Create Custom Facet Class

I would suggest to use a new class library project for all your custom facet. Keep following things in your mind while createing custom facet class:

  • Class must inherits from Sitecore.xConnect.Facet class
  • Must be serializable
  • Provide a facet key

http://www.tekkishare.com

DefaultFacetKey is your facet name. Sitecore store custom facet value against this FacetKey. Later I would tell you where you can varrify this.

Create a Model Class

It register your custom facet. This class should be static.

Deploy Model

To deploy custom facet, you need to serialize your model in JSON format and save the JSON content in a file. To serialize the model, its recommended to create a console base application which will generate the JSON file.

Run this console application. It will generate JSON file. Deploy this JSON file at the following places:

  • <Instance_Name>.xconnect\App_data\Models
  • <Instance_Name>.xconnect\App_data\jobs\continuous\IndexWorker\App_data\Models

Now deploy your Custom facet class project dll at the following places:

  • <Instance_Name>.xconnect\App_data\jobs\continuous\AutomationEngine\
  • <Instance_Name>.xconnect\App_data\jobs\continuous\IndexWorker\
  • <Instance_Name>.xconnect\bin
  • <Instance_Name>.sc\bin

If you are doing deployment on the scaled environment, you must have to deploy the custom model to all the core Sitecore instances:

  • Content delivery
  • Content management
  • Processing
  • Reporting

One last thing is left. Patch file to tell the Sitecore about your custom facet.

http://www.tekkishare.com

Placed this configuration patch file at: <Instance_Name>.sc\App_Config\Sitecore\XConnect.Client.Configuration. You are free to choose any file name.

Now your Custom facet is ready for use.

How to use custom facet

Refer my earlier blog: xConnect - Saving User Profile information using xConnect

Just need to use below code before client.Submit(); statement.

  • //custom facet
  • CustomerFacets customerFacets = new CustomerFacets();
  • {
  • CustomerId = "10001",
  • AreaOfInterest = "Playing Football"
  • };
  • client.SetFacet(contact, customerFacets);

How to verify custom facets values

Connect your database <Instance_Name>_Xdb.Collection.Shard0 and execute the below query:

select * from [xdb_collection].ContactFacets order by LastModified desc

You will find record whose value of the column FacetKey is 'CustomerInterest'.

http://www.tekkishare.com

You can check your value in the JSON saved against the column FacetData.


Thanks for your time. Happy learning & sharing.