Wonach suchst du?

Sitecore Marketing Category Subscription: Part 5 – The "Magical" Subscription Form

Sitecore Marketing Categories Subscription

The Custom Field to identify Contacts was the final step in order to create an awesome subscription form!

It looks something like this:

Subscription form

You will get that form as a template if you install the package. ;)

So, I just put a section around my form fields which should not be displayed if the contact is known.

Then I add a condition to that section:


And we are done!

Recap: Initially you can subscribe to marketing categories. Only if you confirm the confirmation message you will be added to the global contact list. If you are a know contact and visit the subscription page again, the form fields will be hidden and you just can change your preferences. That's the same behavior like the preference center! Yay!

The preferences are saved to the contacts "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 on their ExmKeyBehaviorCache-facet. Next, you should definitely read Part 6 - Segmented Lists to learn what awesome things we can do with them!

Happy form filling!

The author

Dirk Schäfauer
Dirk Schäfauer
Dirk Schäfauer