Liferay社区版中的用户跟踪

时间:2013-02-04 10:16:05

标签: liferay liferay-6

就像我们在liferay中有一个内置用户跟踪设施一样,我们在社区版本中有任何具有此类功能的东西。

您能否建议任何具有用户跟踪功能的第三方开源工具或插件。

帮助我解决这个问题。

非常感谢。

1 个答案:

答案 0 :(得分:2)

我最终实现了自己的代码。而不是使用liferay inbuild功能。 1.这是我文件的Jsp代码。

    //Page Imports & taglibs
    <%@page import="com.liferay.portal.service.persistence.UserTrackerPathUtil"%>
    <%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
    <%@page import="com.liferay.portal.service.UserTrackerPathLocalServiceUtil"%>
    <%@page import="com.liferay.portal.service.UserTrackerLocalServiceUtil"%>
    <%@page import="com.liferay.counter.service.CounterLocalServiceUtil" %>
    <%@page import="com.liferay.portal.util.PortalUtil" %>
    <%@page import="java.util.ArrayList"%>
    <%@page import="com.liferay.portal.model.UserTracker" %>
    <%@page import="com.liferay.portal.model.UserTrackerPath" %>
    <%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%>
    <%-- <%@include file="/html/demo/one.jsp" %> --%>

    <theme:defineObjects/>
    // Define theme object to get user and other basic information
    <%
    HttpSession http_session = request.getSession();
    //Get the current session variable.

     String id = http_session.getId();
    //Getting id of session
         String path = themeDisplay.getLayout().getFriendlyURL();
    //Getting path that will be stored in path field of UserTrackerPath table.
        System.out.println("***==> Current Url => "+ themeDisplay.getURLCurrent());
    //path = path.substring(path.lastIndexOf("/"));
    String localhostname = java.net.InetAddress.getLocalHost().getHostName();
        //Getting the localhost name of machine from which user is acccessing site
    String ipAddress  = java.net.InetAddress.getLocalHost().getHostAddress();
        //Getting ip address of machine, In case of if user is using an proxy env you may need some other efforts to get exact ip. 
       if(ipAddress == null)  
       {  
          ipAddress = request.getRemoteAddr();  
       }  
    try {
            UserTracker user_tracker =     (UserTracker)http_session.getAttribute("user_tracker");
    //Now when user session creates for first time then you need to add an entry in UserTracker table and all the rest entries for path traversal are need to be added at UserTrackerPath with new userTrackerPathId and userTrackerId as foreignkey.
            if(user_tracker == null) 
            {
                    UserTracker tracker = null;
                    ArrayList<UserTrackerPath> userTrackerPath = new ArrayList<UserTrackerPath>();
    //Create an Array List of UserTrackerPath needs to be added in method of addUserTracker by UserTrackerLocalServiceUtil
                    UserTrackerPath utp= null;
                    utp = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment());

                    utp.setPath(path);
                    utp.setPathDate(new java.util.Date());
                    userTrackerPath.add(utp);
    //Add an entry to array list                
            tracker = UserTrackerLocalServiceUtil.addUserTracker(themeDisplay.getCompanyId(),
                            themeDisplay.getUserId(),
                            new java.util.Date(),
                            id,
                            ipAddress,
                            localhostname,
                            userAgent,
                            userTrackerPath);
    //UserTracker will be added to database
                    http_session.setAttribute("user_tracker",tracker);
       //Adds value to session to check that next time session is null or not, so that it can decide whether to execute code of if or else.
            }
            else
            {
    //If session is not null then you already have an entry in UserTracker and you need to keep path track in UserTarckerPath Table
                UserTrackerPath utp  = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment());
                utp.setUserTrackerId(user_tracker.getUserTrackerId());
                utp.setPath(path);
                utp.setPathDate(new java.util.Date());
                utp =     UserTrackerPathLocalServiceUtil.updateUserTrackerPath(utp, true);
    //Update path 
            }

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    %>
  1. 现在转到portal-ext.properties并添加以下属性

    session.tracker.persistence.enabled=true
    
    live.users.enabled=false
    
    session.tracker.ignore.paths=\/portal/render_portlet,\/document_library/get_file
    
  2. 完成后,将Jsp包含在您的主题portal-normal.vm中,以便每个地方都可以访问它。 Add a global Jsp to include in Liferay tomcat-6 它将成功地将跟踪数据添加到表中。 :)

  3. 注意:如果在CE中有任何替代方案,我们将很高兴收到您的建议。 谢谢:))