---
title: Logging activities
related:
  - https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-activities/enabling-activity-tracking.md
  - https://docs.kentico.com/13/managing-users/user-registration-and-authentication/integrating-xperience-membership.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:** **Enterprise license required**
>
> Features described on this page require the **Kentico Xperience Enterprise** license.

This page provides detailed instructions on logging of activities that require additional adjustments of your live site 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 live site project in Visual Studio.
2. Edit the code files that process  [sign-ins](https://docs.kentico.com/13/managing-users/user-registration-and-authentication/setting-up-authentication.md)  and [registrations](https://docs.kentico.com/13/managing-users/user-registration-and-authentication/enabling-user-registration.md) (_MembershipController_  in the example code below).
3. Initialize an instance of the **IMembershipActivityLogger** service.

   > **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/13/developing-websites/initializing-xperience-services-with-dependency-injection.md) to initialize service instances.

   ```csharp

   using CMS.Activities.Loggers;
   using CMS.Core;

   ```

   ```csharp

       public class MembershipController : Controller
       {
           private readonly IMembershipActivityLogger membershipActivityLogger;

           public MembershipController(IMembershipActivityLogger membershipActivityLogger)
           {
               this.membershipActivityLogger = membershipActivityLogger;

               // ...
           }

           // ...


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

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

     ```csharp

                 membershipActivityLogger.LogRegistration(userName);


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

     ```csharp

                 membershipActivityLogger.LogLogin(userName);


     ```

The _User registration_ activity will now 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.

## Logging page related activities

For logging of the _External search_ and the _Page_ related activities, you need to enable the activity tracking feature for your live site application.

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

1. Open your MVC project in Visual Studio.
2. Enable the activity tracking feature by calling the **UseActivityTracking** method of the _ApplicationBuilder_ instance.

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

     > **Info:** MVC projects created by the [installer](https://docs.kentico.com/13/installation/installing-xperience.md) 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 Xperience MVC features).

     > **Note:** **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.

     ```csharp

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

     ...

     protected void Application_Start()
     {
         ...

         // Gets the ApplicationBuilder instance
         // Allows you to enable and configure selected Xperience MVC integration features
         ApplicationBuilder builder = ApplicationBuilder.Current;

         // Enables the activity tracking feature
         builder.UseActivityTracking();

         ...
     }

     ```
3. Register the activity logging script onto all pages by calling the **ActivityLoggingScript** extension method in views.
   - Call the method in your MVC website's main layout (and any other used layouts) to ensure that performed activities are logged for every page.
   - The logging script runs asynchronously, so we recommend adding it at the end of the __ tag in the page code.

```csharp

@using Kentico.Activities.Web.Mvc

```

```csharp

    @* Registers scripts that ensure logging of campaign page visits and page-related activities *@
    @Html.Kentico().ActivityLoggingScript()


```

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

1. Open your live site project in Visual Studio.
2. Edit your application's startup class (**Startup.cs** by default).
3. [Enable](https://docs.kentico.com/13/developing-websites/developing-xperience-applications-using-asp-net-core/starting-with-asp-net-core-development/enabling-xperience-features-in-asp-net-core-applications.md) the activity tracking feature by calling the **UseActivityTracking** method of the _IFeaturesBuilder_ delegate passed to the _IServiceCollection.AddKentico_ method within _ConfigureServices_.

   ```csharp

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

   ...

   public void ConfigureServices(IServiceCollection services)
   {
       ...
       // Enables and configures Xperience features
       services.AddKentico(features =>
       {
           // Enables the activity tracking feature
           features.UseActivityTracking();
           ... 
       });

       ...
   }

   ```
4. Register the activity logging script onto all pages by calling the **ActivityLoggingScript** extension method in views.

   - Call the method in your website's main layout (and any other used layouts) to ensure that performed activities are logged for every page.
   - The logging script runs asynchronously, so we recommend adding it at the end of the __ tag in the page code.

     ```csharp

     @using Kentico.Activities.Web.Mvc

     ```

     ```csharp

         @* Registers scripts that ensure logging of campaign page visits and page-related activities *@
         @Html.Kentico().ActivityLoggingScript()


     ```

<!-- dev-model:core end -->

Enabling the _UseActivityTracking_ feature ensures that the system registers routes that receive activity logging requests.

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

## Logging the Product added to wishlist activity

To ensure that your website logs the _Product added to wishlist_ activity, you need to:

1. Open your live site project in Visual Studio.
2. Edit the code handling requests that add products to the wishlist (_SampleWishlistController_  in the example code below).
3. Initialize an instance of the **IEcommerceActivityLogger** service.

   > **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/13/developing-websites/initializing-xperience-services-with-dependency-injection.md) to initialize service instances.

   ```csharp

   using CMS.Core;
   using CMS.Ecommerce;

   ```

   ```csharp

       public class SampleWishlistController : Controller
       {
           private readonly IEcommerceActivityLogger ecommerceActivityLogger;

           public SampleWishlistController(IEcommerceActivityLogger ecommerceActivityLogger)
           {
               this.ecommerceActivityLogger = ecommerceActivityLogger;

               // ...
           }

           // ...


   ```
4. Call the **LogProductAddedToWishlist** method of the **IEcommerceActivityLogger** instance in the action that adds products to the wishlist. Specify the submitted product (_SKUInfo_) as the method's parameter.

   ```csharp

               ecommerceActivityLogger.LogProductAddedToWishlistActivity(wishlistProduct);


   ```

The _Product added to wishlist_ activity will now be logged when visitors add a product to their wishlist.

## Logging the Internal search activity

To ensure that your website logs the _Internal search_ activity, you need to:

1. Open your live site project in Visual Studio.
2. Edit the [code thatprocesses search requests](https://docs.kentico.com/13/configuring-xperience/setting-up-search-on-your-website/using-locally-stored-search-indexes/building-a-search-interface-for-local-indexes.md)   (_SampleSearchController_  in the example code below).
3. Initialize an instance of the **IPagesActivityLogger** service.

   > **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/13/developing-websites/initializing-xperience-services-with-dependency-injection.md) to initialize service instances.

   ```csharp

   using CMS.Core;
   using CMS.WebAnalytics;

   ```

   ```csharp

       public class SampleSearchController : Controller
       {
           private readonly IPagesActivityLogger pagesActivityLogger;

           public SampleSearchController(IPagesActivityLogger pagesActivityLogger)
           {
               this.pagesActivityLogger = pagesActivityLogger;

               // ...
           }

           // ...


   ```
4. Call the **LogInternalSearch** method of the **IPagesActivityLogger** instance in the action that handles search requests. Specify the submitted search keywords as the method's parameter.

   ```csharp

               pagesActivityLogger.LogInternalSearch(searchKeywords);


   ```

The _Internal search_ activity will now be logged when visitors use your website's local search functionality.
