Sitecore Marketing Subscription Category Part 5 – The “Magic” Subscription Form

Reading time: 1 min

The custom contact identification field was the final step in creating a great signup form!

It looks something like this:

Subscription form
You will receive this form as a template when you install the package. 😉

I simply put a section around my form fields that should not be displayed if the contact is known.

Then I add a condition to this section:


And we are ready!

Summary: First, you can sign up for marketing categories. Only if you confirm the confirmation message, you will be added to the global contact list. If you are a known contact and visit the login page again, the form fields will be hidden and you will only be able to change your settings. This is the same behavior as the settings center! Yay!

The settings are stored in the contacts of the“ExmBehaviorCache” facet:

public List<MarketingPreference> SavePreferences(
    Sitecore.XConnect.Contact contact,
    List<MarketingPreference> preferences)
    Condition.Requires(contact, nameof(contact)).IsNotNull();
    Condition.Requires(preferences, nameof(preferences)).IsNotNull();
    var facet = contact.ExmKeyBehaviorCache();
    if (facet == null)
        facet = new ExmKeyBehaviorCache
            MarketingPreferences = new List<MarketingPreference>()
        facet.MarketingPreferences = facet.MarketingPreferences ?? new List<MarketingPreference>();

    facet.MarketingPreferences = Merge(facet.MarketingPreferences, preferences);
        client =>
            client.SetExmKeyBehaviorCache(contact, facet);
    return facet.MarketingPreferences;

We now have contacts with marketing preferences in their ExmKeyBehaviorCache facet. Next, be sure to read Part 6 – Segmented Lists to learn what we can do with them!

Have fun filling it out!

Do you need Sitecore support? – No problem for our Sitecore experts!

The author