Developer forum

Forum » Development » Dataprocessing.GiveConsent question

Dataprocessing.GiveConsent question

Jan Sangill
Reply

Hi, I am trying to give consent to a user.  I have a problem with the requestInfo part. How would that look?

serviceDataProcessing.GiveConsent(activityId, userId, "User", requestInfo);

Can you provide a complete example of how this function with data would look?

//jan


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Jan

Yes, not the easiest to use - we are releasing an "Easy to use" API very soon.

Until then, please find code example below:

public string ConsentExample()
        {
            string currentVisitorId = Dynamicweb.Context.Current.Request.Cookies["Dynamicweb"]?.Values.Get("VisitorID");
            ActivityService activityService = new ActivityService();
            Activity activity = activityService.GetActivityById("Activity1");
            ConsentService consentService = new ConsentService();
            Consent consent = consentService.GetConsentById(activity.Id, currentVisitorId, "Visitor");
            if ((consent.Status == ConsentStatus.Given))
            {
                // Visitor has given consent - track or whatever.
                return "<script>trackingscript();</script>";
            }
            else
            {
                // Visitor has not given consent - display a "Give consent button" or record that the user has given us a consent

                if (Dynamicweb.Core.Converter.ToBoolean(Context.Current.Request.GetString("GiveConsentForTracking")))
                {
                    consentService.GiveConsent(activity.Id, currentVisitorId, "Visitor", ConsentRequestInfo.FromRequest(Context.Current.Request));
                    return "Thank you!";
                }
                else
                {
                    return "<a href=\"Default.aspx?ID=123&GiveConsentForTracking=True\">Yes, please track me</a>";
                }

            }
        }

        public string RegisterConsent()
        {
            //Give consent
            //?GiveEmailConsent=True&cemail=np@dynamicweb.com
            //Withdraw consent
            //?GiveEmailConsent=False&cemail=np@dynamicweb.com

            //?GiveEmailConsent=True&RecipientId={{EmailMessaging:Recipient.Id}}&RecipientSecret={{EmailMessaging:Recipient.Secret}}

            //Dynamicweb.Context.Current.Request.QueryString["cemail"];
            if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["GiveEmailConsent"]))
            {
                Int32 recipientId = Dynamicweb.Core.Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString[Dynamicweb.EmailMarketing.Constants.UnsubscribeRecipientIdRequestName]);
                string recipientSecret = Dynamicweb.Context.Current.Request.QueryString[Dynamicweb.EmailMarketing.Constants.UnsubscribeRecipientSecretRequestName];

                Dynamicweb.Mailing.Recipient recipient = Dynamicweb.Mailing.Recipient.GetRecipientById(recipientId);

                if (recipient == null || recipient.IsNew || String.IsNullOrEmpty(recipientSecret) || !recipient.Secret.Equals(recipientSecret))
                {
                    return "Secret does not match";
                }

                string emailAddress = recipient.EmailAddress;

                Dynamicweb.DataProcessing.ActivityService activityService = new Dynamicweb.DataProcessing.ActivityService();
                Dynamicweb.DataProcessing.Activity activity = activityService.GetActivityById("d723363c-2b56-4349-8abc-54bc8154d4d4");
                Dynamicweb.DataProcessing.ConsentService consentService = new Dynamicweb.DataProcessing.ConsentService();


                Dynamicweb.DataProcessing.Consent consent = consentService.GetConsentById(activity.Id, emailAddress, "Email");
                if (consent != null && consent.Status == Dynamicweb.DataProcessing.ConsentStatus.Given)
                {
                    if (Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Request.QueryString["GiveEmailConsent"]))
                    {
                        // Visitor has given consent.
                        return "Thanks, you already gave us your consent";
                    }
                    else
                    {
                        consentService.WithdrawConsent(activity.Id, emailAddress, "Email", Dynamicweb.DataProcessing.ConsentRequestInfo.FromRequest(Dynamicweb.Context.Current.Request));
                        return "Thank you - your consent has been withdrawn!";
                    }
                }
                else
                {
                    // Visitor has not given consent - display a "Give consent button" or record that the user has given us a consent
                    if (Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Request.QueryString["GiveEmailConsent"]))
                    {
                        Dynamicweb.DataProcessing.Consent givenConsent = consentService.GiveConsent(activity.Id, emailAddress, "Email", Dynamicweb.DataProcessing.ConsentRequestInfo.FromRequest(Dynamicweb.Context.Current.Request));
                        return "Thank you - your consent has been registered! (" + givenConsent.SubjectId + ")";
                    }
                }
            }
            return string.Empty;
        }
Votes for this answer: 1
 
Jan Sangill
Reply

Perfekt. Tak for dette

 
Ivan Marijanović
Ivan Marijanović
Reply

Hi Nicolai

How can I impelement this on a page. I have cart page where I am offering customer to login or proceed as guest with ability to enter email and subscribe for newsletter.

This means that after the customer fill in email field and click on a button it should give consent and be registeed to receieve newsletter and go to next step in cart!

 

Thank you in advance!

Ivan

 
Nicolai Pedersen
Reply

Currently you cannot get hold of a consent as part of the checkout flow using the app. The reason is, that consent is not needed if it is a customer - but we have it on the to-do since many request that.

You can add a checkbox as a custom order field for "consent" and then in your receip template or in a notification subscriber (CheckoutDoneOrderIsComplete) use the code above - or the simple version found here: https://doc.dynamicweb.com/template-tags/introduction/helper-tags/consent-manager

 

You must be logged in to post in the forum