Developer forum

Forum » Ecommerce - Standard features » Adding Consent to SignIn Page

Adding Consent to SignIn Page

Michael Sedlock
Reply

Hello DW Community,

We would like to add ability to track User Conset at Login. Ideally like to add a Checkbox on the Signin page for user to "Consent" to the Website Terms and Use policy. 
Tracking the Consent is an integral part. 

What is the best way to accomplish this? Ideally without custom coding

Thank you in advance,
Michael.


Replies

 
Nicolai Pedersen
Reply

Hi Michael

We do not have built in in consents with login as it does not make a lot of sense looking at the GDPR rules.

But you can do it custom though - here is some code that shows how to manipulate consents using the API.

You can use the OnBeforeExtranetLogin  notification: https://doc.dynamicweb.com/api/html/0a7343ce-b210-2d4a-c460-42cf23f60ac3.htm to control if the user has checked the checkbox and if not, deny them the login.

If the checkbox has been set, you can add a consent to the system using the below code. Remember that the consent should not be collected on further logins - or you need to handle them as a consent is valid until it is withdrawn.

You need to use the package Dynamicweb.DataProcessing to do this

using System;

using Dynamicweb.Environment;


namespace Dynamicweb.DataProcessing.Examples

{

    class CreateAndCheckForConsent

 {

 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["RecipientId"]);

 string recipientSecret = Dynamicweb.Context.Current.Request.QueryString["RecipientSecret"];


 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;

 }

 }

}

 

You must be logged in to post in the forum