Log email activities
Email license requirements
The license tier required for email features depends on the size of the email channels that you use:
- Email microchannels – available for all license tiers
- Standard size email channels – require the Advanced license tier
To learn more, see the description of the Channel size property for email channels.
Unlike general email statistics, email activities are not anonymous, and provide information about the actions of individual email recipients. To ensure compliance with data protection regulations, email activities are not logged by default.
Developers need to implement logic that decides when it is possible to track email activities for specific contacts.
Email tracking prerequisite
To log email activities, you must also have Email tracking properly configured for your application.
Implement an email tracking activity evaluator
To log email activities, you must create and register an IEmailActivityTrackingEvaluator
service that decides when the logging is allowed for specific contacts and emails. The implementation depends on your project’s requirements, on the target audience of your emails, and the data protection regulations you need to comply with.
A common approach is to prepare one or more tracking consents, and only log activities for contacts who agree to be tracked.
The following example demonstrates how to enable email activity logging based on a consent:
- Open your Xperience solution in Visual Studio.
- Create a new class implementing the
IEmailActivityTrackingEvaluator
interface.- See Integrate custom code for best practices about adding custom code to your project.
- Add the
IsTrackingAllowed
method.- Return a true or false value based on the provided
ContactInfo
andEmailConfigurationInfo
arguments.
- Return a true or false value based on the provided
- Register the implementation using the
RegisterImplementation
assembly attribute.
// Registers the custom implementation of IEmailActivityTrackingEvaluator
[assembly: RegisterImplementation(typeof(IEmailActivityTrackingEvaluator), typeof(CustomEmailActivityTrackingEvaluator))]
public class CustomEmailActivityTrackingEvaluator : IEmailActivityTrackingEvaluator
{
// Services required to evaluate consent agreements
private readonly IConsentAgreementService consentAgreementService;
private readonly IInfoProvider<ConsentInfo> consentInfoProvider;
public CustomEmailActivityTrackingEvaluator(IConsentAgreementService consentAgreementService, IInfoProvider<ConsentInfo> consentInfoProvider)
{
this.consentAgreementService = consentAgreementService;
this.consentInfoProvider = consentInfoProvider;
}
public async Task<bool> IsTrackingAllowed(ContactInfo contact, EmailConfigurationInfo emailConfiguration)
{
// Gets the 'TrackingConsent' consent
ConsentInfo consent = await consentInfoProvider.GetAsync("TrackingConsent");
// Returns a true value if the contact has given an agreement for the consent
return consent is not null && consentAgreementService.IsAgreed(contact, consent);
}
}
Email activities are now only logged if the contact representing the recipient has given an agreement for the specified consent.