0 Comments

Requirement

Newsletter subscription is a common requirement for most for website. Never really think about this function properly, until now client wants to send a scheduled newsletters to all subscribed users.  It sounds simple, isn’t it?  However, when you started to think about a bit in deep, you will probably start to ask questions like below:

  • Who are these users? 

The user must be contacts.  A contact represents an individual who interacts with or may potentially interact with the website.

  • How do I know whether or not the contact subscribed newsletter?

Then you started to realize you need a attributes on contact profile, which means you will most likely need to create a custom contact facet.

  • How to create a dynamic contact list?

Once a contact subscribed newsletter on the website, the contact need to be automatically added into your newsletter subscription contact list.  The answer is simply to use segment list.  Then you realized “damn, I need to create a custom rule”  for segmenting contacts based on the custom facets.

 

Solution

To interoperate the requirements into technical requirements, I drew a  kind data flow diagram, and highlighted custom functions we need to achieve the above requirement.

  1. custom contact facet
  2. programmatically update contact in xDB
  3. Add custom contact facet into contact index.
  4. custom rule condition

 

 

image

 

Implementation

In this section, I will demo the implementation. The demo code is supported Sitecore 8.1 (upgrade-3 or above).

custom contact facet

Sitecore well documented how to create a custom contact facet.   Based on the document I created SubscriptionInfo facet.

Here is the example:

  • Create an Interface

image

  • Create a Facet class

image

  • Register in Analytic Model

image

 

programmatically update contact

Once you’ve create custom facet, next step is to update contact.

Here is the example:

image

Submitting a newsletter subscription, then you can verify the data in xDB

image

 

Add custom contact facet into contact index

In order to use the segment condition, you will need to add the custom facet into index.  Luckily, Sitecore provide a good guide about how to index these custom contact facets during aggregation process.  All you will need to do is to extend the contactindexable.loadfields pipeline.

Here is the example:

image

custom rule condition

Last thing left is to create a custom segment condition, which allows you to check whether or not the contact subscribe the newsletter.

image

 

Once you completed all above, you can now go to List manager and create your segment

image

 

Contacts will be dynamically added into your contact list, which allows newsletters to be sent to the segmented contacts easily.

image\

image

Conclusion

It’s not complicate right?  Hopefully, you will enjoy creating your own facets and rock and roll =P.

References

  1. https://doc.sitecore.net/sitecore_experience_platform/setting_up__maintaining/xdb/contacts/index_custom_contact_facets
  2. https://doc.sitecore.net/sitecore_experience_platform/setting_up__maintaining/xdb/contacts/contacts
  3. https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/the_list_manager/creating_lists/create_a_contact_list_or_a_segmented_list