Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Tracking user views View modes: 
User avatar
Member
Member
Chanan - 5/16/2011 3:21:05 PM
   
Tracking user views
Hello,

We need to track which articles a user reads. I see that the Analytics only tracks aggregates and not by user. We do not have the source code license. Should I just create a web part to update a custom table with this info or is there a better way?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 5/24/2011 12:37:44 PM
   
RE:Tracking user views
Hi,

In short, you can create a webpart or control where you would use WebAnalytics API to log a hit and store current user information. This webpart can be placed into the master page template (or to the specific set of templates according your needs). The logged information would then be used in your custom report.

Generally, when logging an event, saving of the user's name (login) is done by passing appropriate parameters on CMS.WebAnalytics.HitLogProvider.LogHit method call. You will need to use your own name as CodeName parameter (1st) and pass the username/login/userID value as the ObjectName parameter (4th one).
Please find the sample code below:

if (CMS.WebAnalytics.AnalyticsHelper.AnalyticsEnabled(CMSContext.CurrentSiteName))
{
CMS.WebAnalytics.HitLogProvider.LogHit("MembershipDocumentPageView", CMSContext.CurrentSiteName, CMSContext.CurrentUser.PreferredCultureCode, CMSContext.CurrentUser.UserName, CMSContext.CurrentDocument.DocumentId);
}


The string parameter ObjectName is saved in the Analytics_Statistics table in the StatisticsObjectName column. This column is used for any string you want to log, it doesn't have any predefinied purpose. Some reports, as you can see in this table, use also the StatisticsObjectID column, in your case this will be the ID of the requested document (file). After you change this, you'll also have to customize the report generated so it can be displayed. Please see the custom reports article for details.

Some details about tracking downloads per user can be found in
this thread.


It would be possible to store the information in your custom webpart into custom table, however the WebAnalytics uses better & scalable method of capturing the data, so that it won't create such load to the DB, what would happen with higher traffic on the website.

Should you need any additional details, feel free to ask.

Regards,
Zdenek

User avatar
Member
Member
Chanan - 5/24/2011 12:53:56 PM
   
RE:Tracking user views
Hi Zdenek,

That is exactly what I needed. Thanks!