Tracking marketing emails on MVC sites

You can use the email marketing features of Kentico with websites that are presented by a separate MVC application. In this scenario, you manage and send marketing emails from the administration interface of the Kentico application. All settings related to email marketing that you configure in Kentico apply (both global settings and the configuration of individual email feeds).

When you have tracking enabled for an email feed (opened emails and clicked links), the system collects data by processing hidden image requests and link redirects. On Portal Engine websites, the Kentico application handles these tracking requests. For MVC scenarios, you need to register the email tracking functionality into the MVC application. This allows the email tracking to work even when the related Kentico application is not publicly available.

Important

When you send out a marketing email, Kentico generates tracking links according to the type of the site containing the given email feed.

  • For content-only sites (i.e. MVC sites), the base URL of the tracking links uses the site’s Presentation URL.
  • For standard sites, the tracking links target the handlers within the Kentico application itself.

This means your site in Kentico must be marked as content-only if you wish to handle marketing email tracking on the side of the MVC website.

Perform the following steps to register email tracking functionality for your MVC application:

  1. Open your MVC project in Visual Studio.

  2. Enable the email tracking feature by calling the UseEmailTracking method of the ApplicationBuilder instance.

    • Create an EmailTrackingOptions object and pass it as the parameter of the UseEmailTracking method.

    • Enable the feature at the start of your application’s life cycle, for example in the Application_Start method of your project’s Global.asax file.

      MVC projects created by the installer contain the ApplicationConfig class, whose RegisterFeatures method is called in the Application_Start method by default. You can use this class to encapsulate all of your ApplicationBuilder code (enabling and configuring of Kentico MVC features).

      Note: The feature must be enabled before you register routes into the application’s RouteTable. The Kentico().MapRoutes() method adds required routes based on the set of enabled features.

      
      
      
        using Kentico.Web.Mvc;
        using Kentico.Newsletters.Web.Mvc;
      
        ...
      
        protected void Application_Start()
        {
            ...
      
            // Gets the ApplicationBuilder instance
            // Allows you to enable and configure selected Kentico MVC integration features
            ApplicationBuilder builder = ApplicationBuilder.Current;
      
            // Enables the email tracking feature, registers the following routes by default:
            // "CMSModules/Newsletters/CMSPages/Track.ashx" route for opened marketing email tracking
            // "CMSModules/Newsletters/CMSPages/Redirect.ashx" route for clicked link tracking
            builder.UseEmailTracking(new EmailTrackingOptions());
      
            ...
        }
      
      
        

Enabling the UseEmailTracking feature ensures that the system registers routes that handle opened email and clicked link tracking requests

When a recipient opens an email or clicks a link in the content, the system automatically sends the tracking requests through the MVC site. The registered routes ensure that the tracking data is processed and logged into the shared Kentico database. From the point of view of the recipient reading the email, everything works the same way as when handling tracking through the Kentico application.