If you need to log conversions for actions that are not supported by default (see Logging conversions on your website), you can write your own custom code and use the API to log conversions. This allows you to monitor any type of activity performed by users on your website and view the results using the conversion reports available in the Web analytics application.
Use the following code to log conversions via the API:
using CMS.WebAnalytics;
using CMS.DocumentEngine;
using CMS.SiteProvider;
using CMS.Localization;
...
string siteName = SiteContext.CurrentSiteName;
string aliasPath = DocumentContext.CurrentAliasPath;
// Checks that web analytics and conversion tracking 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) && AnalyticsHelper.TrackConversionsEnabled(siteName))
{
// Logs the conversion according to the specified parameters.
HitLogProvider.LogConversions(siteName, LocalizationContext.PreferredCultureCode, ConversionName, 0, 1, ConversionValue);
}Log 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)
In addition to logging a general conversion, this method checks if the current user has passed through a page with a running A/B or Multivariate test, or has arrived on the website through a Campaign. 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 or campaign.
There are several possible ways to include your custom conversion code into the website's functionality: