Most Visited Pages Count in Liferay 6.1

Liferay 6.1 provides Custom Fileds for Pages , set viewCount as a Custom Field and update it using a servicePreAction Hook.

public class CustomServicePreAction extends Action {

    /**
     * This Method is used for Creating the Map Variable of the Pages
     *
     * @param HttpServletRequest
     * @param HttpServletResponse
     */
    @Override
    public void run(HttpServletRequest req, HttpServletResponse res)
            throws ActionException {
              ThemeDisplay themeDisplay = (ThemeDisplay) req
                .getAttribute(WebKeys.THEME_DISPLAY);
        if (!themeDisplay.getURLCurrent().contains("control_panel")) {
            Layout layout = themeDisplay.getLayout();
            try {
                    setupExpandos(layout);
                } catch (Exception e) {
                  
                }
            }
    
    }

    protected void setupExpandos(Layout layout) throws Exception {
        
        
        ExpandoTable table = null;
        try {
            table = ExpandoTableLocalServiceUtil.addTable(layout.getCompanyId(), Layout.class.getName(),ExpandoTableConstants.DEFAULT_TABLE_NAME);
        } catch (DuplicateTableNameException dtne) {
            table = ExpandoTableLocalServiceUtil.getTable(layout.getCompanyId(), Layout.class.getName(),ExpandoTableConstants.DEFAULT_TABLE_NAME);
        }
         String column = "viewCount";
         ExpandoColumn expcolumn = null;
         try {
              expcolumn = ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(), column,ExpandoColumnConstants.LONG,0L);
         }
         catch (DuplicateColumnNameException dcne)
         {
               expcolumn =        ExpandoColumnLocalServiceUtil.getColumn(layout.getCompanyId(),PortalUtil.getClassNameId(Layout.class.getName()), table.getName(), column);
         }
        long count = Long.valueOf(ExpandoValueLocalServiceUtil.getData(layout.getCompanyId(),Layout.class.getName(),      table.getName(), expcolumn.getName() , layout.getPrimaryKey(),0L));
        ExpandoValueLocalServiceUtil.addValue(layout.getCompanyId(),Layout.class.getName(), table.getName(), expcolumn.getName() , layout.getPrimaryKey(),count+1L);

    }

  
}

Blogs
This approach may hit the performance. There should be some thing different. For asset publisher Liferay is using TagsAssetLocalServiceUtil.incrementViewCounter() to track visits for assets. I guess similar we can implement by hooking layout portlet.
TagsAssetLocalServiceUtil.incrementViewCounter() will use only when we assign some tag to the page. AssetPublisher dosent have any entry for page view count in Database , so we have to save this count somewhere in DB .