The following code snippet will help you to log the usage analytics into ULS:
//Log Views usage event on URL of catalog item
window.LogViewsToEventStore = function(url, site)
{
SP.SOD.executeFunc(“sp.js”, “SP.ClientContext”, function()
{
var spClientContext = SP.ClientContext.get_current();
if(!$isNull(spClientContext))
{
var spWeb = spClientContext.get_web();
var spUser = spWeb.get_currentUser();
var spScope = “{00000000-0000-0000-0000-000000000000}”;
//Event ID = 1 (Views), 2 (
SP.Analytics.AnalyticsUsageEntry.logAnalyticsEvent2(spClientContext, 1, url, spScope, site, spUser);spClientContext.executeQueryAsync(null, null);
}
});
};
LogViewsToEventStore(‘Url’, ‘SiteID’);
You can use this in your CSWP or other webparts on client side, with ease.
[…] research revealed this blog entry. It shows how to use the method SP.Analytics.AnalyticsUsageEntry.logAnalyticsEvent2 […]