Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jay Trivedi
User tracking in liferay CE
February 4, 2013 2:06 AM
Answer

Jay Trivedi

Rank: Regular Member

Posts: 107

Join Date: November 23, 2012

Recent Posts

Hi Friends,
Like we have a functionality of UserTracking in EE. Is there something in CE that can be implemented with similar functionalities. Or Any third party tool suggestion that could stop me from writing thousand lines of code for user log.
Please Suggest.??

for more you can also take a visit at.
http://www.liferay.com/community/wiki/-/wiki/Main/User+Behavior+Tracking

Thanks
Jay Trivedi emoticon
Jay Trivedi
RE: User tracking in liferay CE
February 7, 2013 1:39 AM
Answer

Jay Trivedi

Rank: Regular Member

Posts: 107

Join Date: November 23, 2012

Recent Posts

I don't Know yet if there is any other way but since i my-self was not able to get any inbuild functionality i created my own jsp and dynamically added it to every page.
My Jsp has functionality to get all logs and store them in database UserTracker and UserTrackerPath.

Followed this Steps:
1. entries in portal-ext.properties
1
2session.tracker.persistence.enabled=true
3live.users.enabled=false
4session.tracker.ignore.paths=\/portal/render_portlet,\/document_library/get_file

You can also use
session.tracker.friendly.paths.enabled

2. For dynamically adding Jsp to entire portal/project
-> There are multiple ways you can get it done.
if you want to add this tracking particular to your project the use web.xml of your project and write following code
Goto http://www.liferay.com/community/forums/-/message_boards/message/21274969 [follow first post].

-> To include entirely into portal you can..use below link
http://www.liferay.com/community/forums/-/message_boards/message/21280276
but it adds an dependency that if you create a new theme then you need to include your jsp file. Thats headache.
better way is you find out a way to include jsp dynamically to all other jsp run time[when user opens page] using web.xml of tomcat.
That makes your code independent.

use following code to generate Log
 1
 2<%@page import="com.liferay.portal.service.persistence.UserTrackerPathUtil"%>
 3<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
 4<%@page import="com.liferay.portal.service.UserTrackerPathLocalServiceUtil"%>
 5<%@page import="com.liferay.portal.service.UserTrackerLocalServiceUtil"%>
 6<%@page import="com.liferay.counter.service.CounterLocalServiceUtil" %>
 7<%@page import="com.liferay.portal.util.PortalUtil" %>
 8<%@page import="java.util.ArrayList"%>
 9<%@page import="com.liferay.portal.model.UserTracker" %>
10<%@page import="com.liferay.portal.model.UserTrackerPath" %>
11<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%>
12
13<theme:defineObjects/>
14
15This is tracker Jsp File.
16<%
17/* $theme.include($themeServletContext, "<jspPath>") */
18    HttpSession http_session = request.getSession();
19   
20    //http_session.setAttribute("tracker_id",)
21    String id = http_session.getId();
22    String path = themeDisplay.getLayout().getFriendlyURL();
23    System.out.println("***==> Current Url => "+ themeDisplay.getURLCurrent());
24    //path = path.substring(path.lastIndexOf("/"));
25    String localhostname = java.net.InetAddress.getLocalHost().getHostName();
26    out.println(" Session Id => "+id+" path => "+path +" Remote Host => "+ localhostname);
27
28    String ipAddress  = java.net.InetAddress.getLocalHost().getHostAddress();
29    if(ipAddress == null) 
30    { 
31      ipAddress = request.getRemoteAddr(); 
32    } 
33    System.out.println("ipAddress:"+ipAddress);
34    String userAgent = request.getHeader("User-Agent");
35    System.out.println("User Agent :"+userAgent);
36   
37    try {
38            UserTracker user_tracker = (UserTracker)http_session.getAttribute("user_tracker");
39            if(user_tracker == null)
40            {
41                    System.out.println("****** Went in  if case finding that user_tracker is null in first case******");
42                    UserTracker tracker = null;
43                    ArrayList<UserTrackerPath> userTrackerPath = new ArrayList<UserTrackerPath>();
44                    UserTrackerPath utp= null;
45                    utp = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment());
46                    System.out.println("1");
47                   
48                    System.out.println("3");
49                   
50                    System.out.println("****** User Tracker Added Successfully in If******");
51                   
52                    System.out.println("****** Started adding user tracker path ******");
53                   
54                    utp.setPath(path);
55                    utp.setPathDate(new java.util.Date());
56                    userTrackerPath.add(utp);
57                    tracker = UserTrackerLocalServiceUtil.addUserTracker(themeDisplay.getCompanyId(),
58                            themeDisplay.getUserId(),
59                            new java.util.Date(),
60                            id,
61                            ipAddress,
62                            localhostname,
63                            userAgent,
64                            userTrackerPath);
65                    System.out.println("****** User Tracker Added Successfully in If******");
66                    http_session.setAttribute("user_tracker",tracker);
67                    System.out.println("****** User Tracker Added to Session******");
68            }
69            else
70            {
71                System.out.println("****** User Tracker Path Started adding in Else******");
72                UserTrackerPath utp  = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment());
73                utp.setUserTrackerId(user_tracker.getUserTrackerId());
74                utp.setPath(path);
75                utp.setPathDate(new java.util.Date());
76                utp = UserTrackerPathLocalServiceUtil.updateUserTrackerPath(utp, true);
77                System.out.println("****** User Tracker Path Local Service UTIL updated successfully******");
78            }
79            
80    }
81    catch(Exception e)
82    {
83        e.printStackTrace();
84    }
85   
86    // addUserTracker(long companyId, long userId, Date modifiedDate, String sessionId, String remoteAddr,
87    //        String remoteHost, String userAgent, List<UserTrackerPath> userTrackerPaths)
88   
89%>


3. Make an portlet that displays report to admin
It is open end user what is required at report view time. so it varies completely on your requirement.


If you find any other feasible way to get it done in CE. do let me know. Like making few property changes and getting entire thing work easily. No need to put down codes. ;)

Thanks Jay.
Christoph Rabel
RE: User tracking in liferay CE
February 7, 2013 4:07 AM
Answer

Christoph Rabel

Rank: Regular Member

Posts: 197

Join Date: September 24, 2009

Recent Posts

Maybe you should take a look at piwik. Easy to set up and to configure. All you have to do on Liferay side is to insert the tracking javascript code into the page.
http://piwik.org/
David H Nebinger
RE: User tracking in liferay CE
February 7, 2013 5:29 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11081

Join Date: September 1, 2006

Recent Posts

Actually I have a wiki page set up that can help w/ piwik integration...
Jay Trivedi
RE: User tracking in liferay CE
February 12, 2013 12:45 AM
Answer

Jay Trivedi

Rank: Regular Member

Posts: 107

Join Date: November 23, 2012

Recent Posts

I will try this out and let know if any issues get concerned.

Thanks emoticon
Keu Keo
RE: User tracking in liferay CE
April 7, 2014 10:05 PM
Answer

Keu Keo

Rank: New Member

Posts: 2

Join Date: April 7, 2014

Recent Posts

Hi Jay Trivedi,

Can you tell me? How can I view log of User Tracking and Database store data of it?

When I copied the code you had provide in Liferay forum,

-> I put this code to portal-ext.property

1#Tracking user
2session.tracker.persistence.enabled=true
3session.tracker.memory.enabled=true
4live.users.enabled=false
5session.tracker.ignore.paths=\/portal/render_portlet,\/document_library/get_file
6session.tracker.friendly.paths.enabled=true


-> I put the code below to this file ("classic/jsp/tracker.jsp")

 1<%@page import="com.liferay.portal.service.persistence.UserTrackerPathUtil"%>
 2<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
 3<%@page import="com.liferay.portal.service.UserTrackerPathLocalServiceUtil"%>
 4<%@page import="com.liferay.portal.service.UserTrackerLocalServiceUtil"%>
 5<%@page import="com.liferay.counter.service.CounterLocalServiceUtil" %>
 6<%@page import="com.liferay.portal.util.PortalUtil" %>
 7<%@page import="java.util.ArrayList"%>
 8<%@page import="com.liferay.portal.model.UserTracker" %>
 9<%@page import="com.liferay.portal.model.UserTrackerPath" %>
10<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%>
11
12<theme:defineObjects/>
13
14/*This is tracker Jsp File.*/
15<%
16/* $theme.include($themeServletContext, "<jspPath>") */
17    HttpSession http_session = request.getSession();
18   
19    //http_session.setAttribute("tracker_id",)
20    String id = http_session.getId();
21    String path = themeDisplay.getLayout().getFriendlyURL();
22    System.out.println("***==> Current Url => "+ themeDisplay.getURLCurrent());
23    //path = path.substring(path.lastIndexOf("/"));
24    String localhostname = java.net.InetAddress.getLocalHost().getHostName();
25    out.println(" Session Id => "+id+" path => "+path +" Remote Host => "+ localhostname);
26
27    String ipAddress  = java.net.InetAddress.getLocalHost().getHostAddress();
28    if(ipAddress == null) 
29    { 
30      ipAddress = request.getRemoteAddr(); 
31    } 
32    System.out.println("ipAddress:"+ipAddress);
33    String userAgent = request.getHeader("User-Agent");
34    System.out.println("User Agent :"+userAgent);
35   
36    try {
37            UserTracker user_tracker = (UserTracker)http_session.getAttribute("user_tracker");
38            if(user_tracker == null)
39            {
40                    System.out.println("****** Went in  if case finding that user_tracker is null in first case******");
41                    UserTracker tracker = null;
42                    ArrayList<UserTrackerPath> userTrackerPath = new ArrayList<UserTrackerPath>();
43                    UserTrackerPath utp= null;
44                    utp = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment());
45                    System.out.println("1");
46                   
47                    System.out.println("3");
48                   
49                    System.out.println("****** User Tracker Added Successfully in If******");
50                   
51                    System.out.println("****** Started adding user tracker path ******");
52                   
53                    utp.setPath(path);
54                    utp.setPathDate(new java.util.Date());
55                    userTrackerPath.add(utp);
56                    tracker = UserTrackerLocalServiceUtil.addUserTracker(themeDisplay.getCompanyId(),
57                            themeDisplay.getUserId(),
58                            new java.util.Date(),
59                            id,
60                            ipAddress,
61                            localhostname,
62                            userAgent,
63                            userTrackerPath);
64                    System.out.println("****** User Tracker Added Successfully in If******");
65                    http_session.setAttribute("user_tracker",tracker);
66                    System.out.println("****** User Tracker Added to Session******");
67            }
68            else
69            {
70                System.out.println("****** User Tracker Path Started adding in Else******");
71                UserTrackerPath utp  = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment());
72                utp.setUserTrackerId(user_tracker.getUserTrackerId());
73                utp.setPath(path);
74                utp.setPathDate(new java.util.Date());
75                utp = UserTrackerPathLocalServiceUtil.updateUserTrackerPath(utp, true);
76                System.out.println("****** User Tracker Path Local Service UTIL updated successfully******");
77            }
78            
79    }
80    catch(Exception e)
81    {
82        e.printStackTrace();
83    }
84   
85    // addUserTracker(long companyId, long userId, Date modifiedDate, String sessionId, String remoteAddr,
86    //        String remoteHost, String userAgent, List<UserTrackerPath> userTrackerPaths)
87%>




-> I write a code ($theme.include($themeServletContext,"/jsp/tracker.jsp") portal_normal.vm in Classic theme)
 1<head>
 2    <title>$the_title - $company_name</title>
 3
 4    <meta content="initial-scale=1.0, width=device-width" name="viewport" />
 5   
 6    $theme.include($themeServletContext,"/jsp/tracker.jsp")
 7
 8    $theme.include($top_head_include)
 9</head>

The code automatically remove in portal_normal.vm when I restart Tomcat.

Can you tell me to solve this issue?

Regards,

Keu