---
title: Logging custom conversions through the API
related:
  - https://docs.kentico.com/k10/on-line-marketing-features/managing-your-on-line-marketing-features/web-analytics.md
  - https://docs.kentico.com/k10/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-web-analytics/configuring-logging-of-actions-as-custom-conversions.md
  - https://docs.kentico.com/k10/on-line-marketing-features/managing-your-on-line-marketing-features/web-analytics/logging-custom-conversions-on-your-website.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.

If you need to log custom conversions for actions that are not supported by default (see [Logging custom conversions on your website](https://docs.kentico.com/k10/on-line-marketing-features/managing-your-on-line-marketing-features/web-analytics/logging-custom-conversions-on-your-website.md)), you can write your own custom code and use the API to log custom conversions. This allows you to monitor any type of activity performed by users on your website and to view the results using the custom conversion reports available in the [Web analytics](https://docs.kentico.com/k10/on-line-marketing-features/managing-your-on-line-marketing-features/web-analytics.md) application.

Use the following code to log custom conversions via the API:

```csharp

using CMS.WebAnalytics;
using CMS.DocumentEngine;
using CMS.SiteProvider;
using CMS.Localization;

...

string siteName = SiteContext.CurrentSiteName;
string aliasPath = DocumentContext.CurrentAliasPath;

// Checks that web analytics are enabled in the site's settings.
// Confirms that the current IP address, alias path and URL extension are not excluded from web analytics tracking.
if (AnalyticsHelper.IsLoggingEnabled(siteName, aliasPath))
{
    // Logs the conversion according to the specified parameters.
    HitLogProvider.LogConversions(siteName, LocalizationContext.PreferredCultureCode, ConversionName, 0, 1, ConversionValue);
}

```

Log custom conversions using the **HitLogProvider** class from the **CMS.WebAnalytics** namespace, specifically the following method:

_LogConversions(string siteName, string culture, string objectName, int objectId, int count, double value)_

- **siteName** – sets the code name of the site for which the conversion is logged.
- **culture** – sets the culture code under which the conversion is logged.
- **objectName** – specifies the code name of the conversion that is logged.
- **objectId** – specifies the ID of the conversion. You can set this parameter to _0_ if you specify a valid code name in the _objectName_ parameter.
- **count** – sets the number of conversion hits that the method logs. This parameter is optional. The default value (_1_) is used if not specified.
- **value** – specifies the value logged for the conversion.

In addition to logging a general custom conversion, this method checks if the current user has passed through a page with a running [A/B](https://docs.kentico.com/k10/on-line-marketing-features/managing-your-on-line-marketing-features/optimization-testing/a-b-testing-website-pages.md) or [Multivariate test](https://docs.kentico.com/k10/on-line-marketing-features/managing-your-on-line-marketing-features/optimization-testing/multivariate-testing.md). If this is the case, the method automatically logs the conversion within the appropriate context and includes the conversion in the statistics of the given test.

## Integrating the custom code into your website

There are several possible ways to include your custom conversion code into the website's functionality:

- When tracking conversions on a specific page, you can use a [custom user control](https://docs.kentico.com/k10/custom-development/miscellaneous-custom-development-tasks/adding-custom-code-to-portal-engine-page-templates.md) or [web part](https://docs.kentico.com/k10/custom-development/developing-web-parts.md) to ensure that the system executes the code as required.
- To log actions that may occur anywhere on the website, use [global event handlers](https://docs.kentico.com/k10/custom-development/handling-global-events.md).
