Kentico CMS 6.0 On-line Marketing Guide

Logging conversions using the API

Logging conversions using the API

Previous topic Next topic Mail us feedback on this topic!  

Logging conversions using the API

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

If you need to track a type of action that is not supported by default (as described in Logging actions as conversions), 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 various conversion reports available in the web analytics interface.

 

To log a conversion via the API, you can use code similar to the following:

 

[C#]

 

using CMS.WebAnalytics;
using CMS.CMSHelper;

 
...

 
string siteName = CMSContext.CurrentSiteName;
string aliasPath = CMSContext.CurrentAliasPath;

 
// Checks that web analytics and conversion tracking are enabled in the site's settings.
// Also 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, CMSContext.PreferredCultureCode, ConversionName, 0, 1, ConversionValue);
}

 

There are several possible ways to include this type of code in your website's functionality. When tracking activity on a specific page, you may use a custom user control or web part to ensure that the code is executed as required. If you wish to log actions that may occur anywhere on the website, you may utilize global event handlers.

 

As shown above, conversions can be logged 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 should be logged.

culture - sets the culture code under which the conversion should be logged.

objectName - used to specify the code name of the conversion that should be logged.

objectId - used to specify the ID of the conversion. This parameter may be set to 0 if a valid code name is passed via the objectName.

count - sets the amount of conversion hits that should logged. This parameter is optional and the default value (1) is used if it is not specified.

value - specifies the value that will be logged for the conversion.

 

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, then the conversion is also automatically logged within the appropriate context and included in the statistics of the given test or campaign.