Creating custom reports |
This example is describing in detail how to log custom events and how to display result statistics. A button click event will be logged for this purpose.
Logging the event
To log custom events for web analytics use the following code from CMS.Analytics namespace: HitLogProvider.LogHit(string codeName, string siteName, string culture, string objectName, int objectId[, int count]);
Example of logging of the button click event follows:
[C#]
Statistics code name is “buttonclicked” and the logged value is user name of the current user who clicked the button. Now logs will be created and stored in DB after clicking the button. Before you can see your statistics in CMSDesk -> Tools -> Web Analytics the reports have to be done in CMSDesk -> Tools -> Reporting. Next step is creation of reports which display statistics in graph or table form.
Creating reports
Go to CMSDesk -> Tools -> Reporting and edit Web Analytics category. There are some reports already in the list. These reports belong to default statistics like page views, visits, campaigns, etc. Each statistics has four reports: daily, weekly, monthly and yearly report. Code names of the reports have to be in specific form:
In our example <statisticscodename> is buttonclicked, as defined above.
Now we will create daily report for the new statistics.
Go to Parameters section and create three essential parameters which are used in queries:
Disable the Display attribute in the editing form for all parameters.
Go to General section and click Add button near Tables to create report table:
There are six important DB tables used in web analytics module.
Table Analytics_Statistics contains general information about statistics, other five tables store statistics hit records for specific time period – Analytics_HourHits, Analytics_DayHits, Analytics_WeekHits, Analytics_MonthHits and Analytics_YearHits. As the report is daily report table Analytics_DayHits is used beside Analytics_Statistics table. See the diagram below to understand DB structure of web analytics:
Now click OK and use Insert button near Tables to insert macro to the layout of the report. Click OK and daily report is ready now.
And finally the result:
|