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