2

I have created a Sitecore 9 form with a custom button as shown below: Sitecore 9 form with custom button

On click of this "Subscribe" button I am saving the email of the contact in Xdb (Experience profile). enter image description here

Also, I have created a custom tab ("Consent") and field ("Newsletter Consent") in Experience profile which will be visible to all users with the help of the following post https://community.sitecore.net/technical_blogs/b/getting_to_know_sitecore/posts/using-custom-contact-data-part-1-experience-profile : enter image description here

Now my question is, how do I add the value to this custom field. For now, all those users who enter their email and click subscribe, this "Newsletter consent" value should be true and should be visible against it's label in experience profile. I am unable to set it's value like I have done for email on custom button click.

 private static void SetEmail(string email, Contact contact, IXdbContext client)
    {
        if (string.IsNullOrEmpty(email))
        {
            return;
        }
        EmailAddressList emailFacet = contact.Emails();
        if (emailFacet == null)
        {
            emailFacet = new EmailAddressList(new EmailAddress(email, false), "Preferred");
        }
        else
        {
            if (emailFacet.PreferredEmail?.SmtpAddress == email)
            {
                return;
            }

            emailFacet.PreferredEmail = new EmailAddress(email, false);
        }
        client.SetEmails(contact, emailFacet);       
    }

Any help would be highly appreciated :).

1

You have two ways to achieve this:

Option 1. Create a custom facet to store newsletter consent for the contact and save its value (true/false) on the click of Subscribe button, the same way you're doing to set email facet value. After values are stored in XDB, you can call this custom facet in experience profile code and store its value in DataTable.

Option 2. If you don't want to create a custom facet to store consent, you can use the validated attribute of EmailAddress Facet. So while saving the value of EmailAdress on click of subscribe button, you can set the validated as true.

    emailFacet = new EmailAddressList(new EmailAddress(email, true), "Preferred");

Now, you can fetch the value of this attribute in the custom profile tab.

PS. I would recommend using the EPExpressTab module to create a custom tab in the Sitecore Experience Profile. Using this you can easily load your facet values and manipulate the logic as you want. You can refer to this post to see how to implement a custom tab in Sitecore Experience Profile.

0

The other OOTB way is to fire a goal on click of Subscribe button and enroll user to Sitecore Marketing Automation plan which will move user to specific Contact list and then send EXM Campaign. With EXM Campaign and Contact list you can identify enrolled users. In near future you can utilize Contact list to send email directly. Also while sending initial email if you have OOTB links like Unsubscribe and manage preference link in EXM Campaign then from there you can provide flexibility to opt-in/opt-out https://camao.one/blog/sitecore-9-1-marketing-category-subscription-part-4-custom-marketing-preference/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.