Log email activities

Advanced license required

Features described on this page require the Xperience by Kentico Advanced license tier.

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:

  1. Open your Xperience solution in Visual Studio.
  2. Create a new class implementing the IEmailActivityTrackingEvaluator interface.
  3. Add the IsTrackingAllowed method.
    • Return a true or false value based on the provided ContactInfo and EmailConfigurationInfo arguments.
  4. Register the implementation using the RegisterImplementation assembly attribute.
C#
IEmailActivityTrackingEvaluator example

// 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.