---
title: Enabling tracking of activities on MVC sites
related:
  - https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/implementing-on-line-marketing-features-on-mvc-sites/logging-activities-on-mvc-sites.md
  - https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/working-with-users-on-mvc-sites.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

> **Info:** **Kentico EMS required**
>
> Features described on this page require the **Kentico EMS** license.

This page provides detailed instructions on logging of activities that require additional adjustments of your MVC application.

## Logging membership activities

To ensure that the system logs every performed _Membership_ related activity, such as _User registration_ and _User login_, you need to:

1. Open your MVC project in Visual Studio.
2. Edit the controllers that process [sign-ins](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/working-with-users-on-mvc-sites.md) and [registrations](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/working-with-users-on-mvc-sites/user-registration-on-mvc-sites.md) (referred to as _MembershipController_ in the example code below).
3. Initialize a **MembershipActivitiesLogger** instance in the sign-in and registration controller's constructor. This enables you to log activities.

   > **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/initializing-kentico-services-with-dependency-injection.md) to initialize service instances. When configuring the lifetime scope for _MembershipActivitiesLogger_, create a shared instance (singleton) for all requests.

   ```csharp

   using Kentico.Activities;

   ```

   ```csharp

       public class MembershipController : Controller
       {
           private readonly IMembershipActivitiesLogger membershipActivityLogger;

           public MembershipController()
           {
               membershipActivityLogger = new MembershipActivitiesLogger();

               // ...
           }

           // ...


   ```
4. Add code according to the activity types described below:

   - **User registration activity** – to log the user registration activity, call the _LogRegisterActivity_ method of the _MembershipActivitiesLogger_ instance. Specify the user name of the newly registered user as the method's parameter.

     ```csharp

                 membershipActivityLogger.LogRegisterActivity(userName);


     ```
   - **User login activity** – to log the user login activity, call the _LogLoginActivity_ method of the _MembershipActivitiesLogger_ instance. Specify the user name of the signed in user as the method's parameter.

     ```csharp

                 membershipActivityLogger.LogLoginActivity(userName);


     ```

After adding the code mentioned above, the _U\*\*ser registration_ activity will be logged for every user that registers as a site member, and the _User login_ activity will be logged for every user that signs into the site.

## Enabling tracking of the External search and the Page related activities in MVC

For logging of the _External search_ and the _Page_ related activities, you need to adjust your MVC application by registering routes that receive logging requests.

> **Info:** **Internet Explorer 8** and older versions do **not** support this feature. Tracking of visitors using Internet Explorer 8 and older will **not** work.

To ensure that the system logs every performed _External search_, _Page visit_, and _Landing page_ activity, you need to:

1. Open your MVC project in Visual Studio.
2. Make sure the **Kentico.Activities.Web.Mvc** NuGet [integration package](https://docs.kentico.com/k10/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md) is installed.
3. Edit the application's _App\_Start\RouteConfig.cs_ file.

   1. Add a _using_ statement for the **Kentico.Activities.Web.Mvc** namespace.
   2. Call the predefined **MapActivitiesRoutes** method to register routes that receive activity logging requests (typically inside the **RegisterRoutes** method, before you map your own custom routes).

```csharp

using System.Web.Mvc;
using System.Web.Routing;

using Kentico.Activities.Web.Mvc;
using Kentico.Web.Mvc;


```

```csharp

            // Maps routes for logging of on-line marketing campaign page visits and page-related activities
            routes.Kentico().MapActivitiesRoutes();


```

4. Add the below code to your MVC website's main layout (view), so that the performed activities are logged for every page.

   ```csharp

       @* Registers scripts that ensure logging of campaign page visits and page-related activities *@
       @Scripts.Render(Url.RouteUrl("KenticoLogActivityScript"))


   ```

After adding the code mentioned above, the _External search_ activity will be logged every time a site visitor uses an external search engine that leads them to the website. Similarly, the _Page visit_ activity will be logged every time the page is visited, and the _Landing page_ activity will be logged every time a visitor opens the page when first viewing the website.
