| Line 28... |
Line 28... |
| 28 |
private static final long serialVersionUID = 1L;
|
28 |
private static final long serialVersionUID = 1L;
|
| 29 |
private static Logger log = Logger.getLogger(TrackingInterceptor.class);
|
29 |
private static Logger log = Logger.getLogger(TrackingInterceptor.class);
|
| 30 |
|
30 |
|
| 31 |
private static final int SECONDS_IN_YEAR = 60 * 60 * 24 * 365;
|
31 |
private static final int SECONDS_IN_YEAR = 60 * 60 * 24 * 365;
|
| 32 |
private static final int SECONDS_IN_DAY = 60 * 60 * 24;
|
32 |
private static final int SECONDS_IN_DAY = 60 * 60 * 24;
|
| 33 |
public static final String TRACKER = "tracker";
|
- |
|
| 34 |
public static final String AFF_COOKIE = "uafc";
|
33 |
public static final String AFF_COOKIE = "uafc";
|
| 35 |
public static final String SRC_COOKIE = "usrcc";
|
34 |
public static final String SRC_COOKIE = "usrcc";
|
| 36 |
public static final String SESSION_SRC_COOKIE = "sess_srcc";
|
35 |
public static final String SESSION_SRC_COOKIE = "sess_srcc";
|
| 37 |
public static final String SRC_TIME_COOKIE = "usrctc";
|
36 |
public static final String SRC_TIME_COOKIE = "usrctc";
|
| 38 |
public static final String SESSION_SRC_TIME_COOKIE = "sess_srctc";
|
37 |
public static final String SESSION_SRC_TIME_COOKIE = "sess_srctc";
|
| Line 46... |
Line 45... |
| 46 |
private Cookie sessionSourceCookie = null;
|
45 |
private Cookie sessionSourceCookie = null;
|
| 47 |
private Cookie firstSourceTimeCookie = null;
|
46 |
private Cookie firstSourceTimeCookie = null;
|
| 48 |
private Cookie sessionSourceTimeCookie = null;
|
47 |
private Cookie sessionSourceTimeCookie = null;
|
| 49 |
private Cookie sessionIdCookie = null;
|
48 |
private Cookie sessionIdCookie = null;
|
| 50 |
private Map<String, Cookie> cookiesMap = null;
|
49 |
private Map<String, Cookie> cookiesMap = null;
|
| - |
|
50 |
|
| 51 |
private HttpServletRequest request;
|
51 |
private HttpServletRequest request;
|
| 52 |
private HttpServletResponse response;
|
52 |
private HttpServletResponse response;
|
| - |
|
53 |
private String referer;
|
| 53 |
private String affId = null;
|
54 |
private String affId = null;
|
| 54 |
|
55 |
|
| 55 |
static {
|
56 |
static {
|
| 56 |
paidAffIds = new HashSet<String>();
|
57 |
paidAffIds = new HashSet<String>();
|
| 57 |
paidAffIds.add("6");
|
58 |
paidAffIds.add("6");
|
| 58 |
paidAffIds.add("38");
|
59 |
paidAffIds.add("38");
|
| - |
|
60 |
paidAffIds.add("41");
|
| - |
|
61 |
paidAffIds.add("43");
|
| - |
|
62 |
paidAffIds.add("45");
|
| 59 |
}
|
63 |
}
|
| 60 |
|
- |
|
| 61 |
|
64 |
|
| 62 |
public void setCookieDomain(String cookieDomain) {
|
65 |
public void setCookieDomain(String cookieDomain) {
|
| 63 |
this.cookieDomain = cookieDomain;
|
66 |
this.cookieDomain = cookieDomain;
|
| 64 |
}
|
67 |
}
|
| 65 |
|
68 |
|
| 66 |
@Override
|
69 |
@Override
|
| 67 |
public String intercept(ActionInvocation invocation) throws Exception {
|
70 |
public String intercept(ActionInvocation invocation) throws Exception {
|
| 68 |
request = ServletActionContext.getRequest();
|
71 |
request = ServletActionContext.getRequest();
|
| 69 |
response = ServletActionContext.getResponse();
|
72 |
response = ServletActionContext.getResponse();
|
| 70 |
|
73 |
referer = request.getHeader("referer");
|
| 71 |
affId = request.getParameter("afid");
|
74 |
affId = request.getParameter("afid");
|
| - |
|
75 |
|
| 72 |
createCookiesMap();
|
76 |
createCookiesMap();
|
| 73 |
updateFirstSourceCookie();
|
77 |
updateFirstSourceCookie();
|
| 74 |
updateSessionSourceCookie();
|
78 |
updateSessionSourceCookie();
|
| 75 |
|
79 |
|
| 76 |
updateAffCookie();
|
80 |
updateAffCookie();
|
| Line 88... |
Line 92... |
| 88 |
}
|
92 |
}
|
| 89 |
String src = getSource();
|
93 |
String src = getSource();
|
| 90 |
DesEncrypter des = new DesEncrypter(ENCRIPTION_STRING);
|
94 |
DesEncrypter des = new DesEncrypter(ENCRIPTION_STRING);
|
| 91 |
String sourceCookieVal = des.encrypt(src);
|
95 |
String sourceCookieVal = des.encrypt(src);
|
| 92 |
|
96 |
|
| 93 |
firstSourceCookie = new Cookie(SRC_COOKIE, sourceCookieVal);
|
97 |
firstSourceCookie = createCookie(SRC_COOKIE, cookieDomain, sourceCookieVal, SECONDS_IN_YEAR);
|
| 94 |
firstSourceCookie.setMaxAge(SECONDS_IN_YEAR);
|
98 |
firstSourceTimeCookie = createCookie(SRC_TIME_COOKIE, cookieDomain, Long.toString((new Date()).getTime()), SECONDS_IN_YEAR);
|
| 95 |
firstSourceCookie.setPath("/");
|
- |
|
| 96 |
if (!cookieDomain.isEmpty()) {
|
- |
|
| 97 |
firstSourceCookie.setDomain(cookieDomain);
|
- |
|
| 98 |
}
|
99 |
|
| 99 |
cookiesMap.put(SRC_COOKIE, firstSourceCookie);
|
100 |
cookiesMap.put(SRC_COOKIE, firstSourceCookie);
|
| 100 |
|
- |
|
| 101 |
firstSourceTimeCookie = new Cookie(SRC_TIME_COOKIE,
|
- |
|
| 102 |
Long.toString((new Date()).getTime()));
|
- |
|
| 103 |
firstSourceTimeCookie.setMaxAge(SECONDS_IN_YEAR);
|
- |
|
| 104 |
firstSourceTimeCookie.setPath("/");
|
- |
|
| 105 |
if (!cookieDomain.isEmpty()) {
|
- |
|
| 106 |
firstSourceTimeCookie.setDomain(cookieDomain);
|
- |
|
| 107 |
}
|
- |
|
| 108 |
cookiesMap.put(SRC_TIME_COOKIE, firstSourceTimeCookie);
|
101 |
cookiesMap.put(SRC_TIME_COOKIE, firstSourceTimeCookie);
|
| 109 |
|
102 |
|
| 110 |
response.addCookie(firstSourceCookie);
|
103 |
response.addCookie(firstSourceCookie);
|
| 111 |
response.addCookie(firstSourceTimeCookie);
|
104 |
response.addCookie(firstSourceTimeCookie);
|
| 112 |
}
|
105 |
}
|
| 113 |
|
106 |
|
| - |
|
107 |
private Cookie createCookie(String name, String domain, String value, Integer age) {
|
| - |
|
108 |
Cookie cookie = new Cookie(name, value);
|
| - |
|
109 |
if (age != null) {
|
| - |
|
110 |
cookie.setMaxAge(age);
|
| - |
|
111 |
}
|
| - |
|
112 |
cookie.setPath("/");
|
| - |
|
113 |
if (!domain.isEmpty()) {
|
| - |
|
114 |
cookie.setDomain(domain);
|
| - |
|
115 |
}
|
| - |
|
116 |
return cookie;
|
| - |
|
117 |
}
|
| - |
|
118 |
|
| 114 |
/**
|
119 |
/**
|
| 115 |
* Update first source cookie
|
120 |
* Update first source cookie
|
| 116 |
*
|
121 |
*
|
| 117 |
*/
|
122 |
*/
|
| 118 |
private void updateSessionSourceCookie() {
|
123 |
private void updateSessionSourceCookie() {
|
| 119 |
sessionSourceCookie = (Cookie) cookiesMap.get(SESSION_SRC_COOKIE);
|
124 |
sessionSourceCookie = (Cookie) cookiesMap.get(SESSION_SRC_COOKIE);
|
| 120 |
if (sessionSourceCookie != null) {
|
125 |
if (sessionSourceCookie != null) {
|
| - |
|
126 |
if (referer == null || referer.isEmpty() || referer.startsWith("http://www.saholic.com") || referer.startsWith("http://local.shop2020.in")) {
|
| - |
|
127 |
log.info("No change in session cookie");
|
| 121 |
return;
|
128 |
return;
|
| - |
|
129 |
}
|
| 122 |
}
|
130 |
}
|
| 123 |
String src = getSource();
|
131 |
String src = getSource();
|
| 124 |
|
132 |
|
| 125 |
DesEncrypter des = new DesEncrypter(ENCRIPTION_STRING);
|
133 |
DesEncrypter des = new DesEncrypter(ENCRIPTION_STRING);
|
| 126 |
String sessionSourceCookieVal = des.encrypt(src);
|
134 |
String sessionSourceCookieVal = des.encrypt(src);
|
| 127 |
|
135 |
|
| 128 |
//session source
|
136 |
//session source
|
| 129 |
sessionSourceCookie = new Cookie(SESSION_SRC_COOKIE,
|
137 |
sessionSourceCookie = createCookie(SESSION_SRC_COOKIE, cookieDomain, sessionSourceCookieVal, null);
|
| 130 |
sessionSourceCookieVal);
|
- |
|
| 131 |
sessionSourceCookie.setPath("/");
|
- |
|
| 132 |
if (!cookieDomain.isEmpty()) {
|
- |
|
| 133 |
sessionSourceCookie.setDomain(cookieDomain);
|
- |
|
| 134 |
}
|
- |
|
| 135 |
cookiesMap.put(SESSION_SRC_COOKIE, sessionSourceCookie);
|
138 |
cookiesMap.put(SESSION_SRC_COOKIE, sessionSourceCookie);
|
| - |
|
139 |
log.info("new session cookie : " + sessionSourceCookieVal);
|
| 136 |
|
140 |
|
| 137 |
//session time
|
141 |
//session time
|
| 138 |
sessionSourceTimeCookie = new Cookie(SESSION_SRC_TIME_COOKIE,
|
142 |
sessionSourceTimeCookie = createCookie(SESSION_SRC_TIME_COOKIE, cookieDomain, Long.toString((new Date()).getTime()), null);
|
| 139 |
Long.toString((new Date()).getTime()));
|
- |
|
| 140 |
sessionSourceTimeCookie.setPath("/");
|
- |
|
| 141 |
if (!cookieDomain.isEmpty()) {
|
- |
|
| 142 |
sessionSourceTimeCookie.setDomain(cookieDomain);
|
- |
|
| 143 |
}
|
- |
|
| 144 |
cookiesMap.put(SESSION_SRC_TIME_COOKIE, sessionSourceTimeCookie);
|
143 |
cookiesMap.put(SESSION_SRC_TIME_COOKIE, sessionSourceTimeCookie);
|
| 145 |
|
144 |
|
| 146 |
//session id
|
- |
|
| 147 |
String sessionId = request.getSession().getId();
|
145 |
UserSessionInfo userInfo = (UserSessionInfo) request
|
| 148 |
sessionIdCookie = new Cookie(SESSION_ID_COOKIE, sessionId);
|
146 |
.getAttribute(UserInterceptor.USER_INFO_COOKIE_NAME);
|
| 149 |
sessionIdCookie.setPath("/");
|
- |
|
| 150 |
if (!cookieDomain.isEmpty()) {
|
- |
|
| 151 |
sessionIdCookie.setDomain(cookieDomain);
|
- |
|
| 152 |
}
|
- |
|
| 153 |
cookiesMap.put(SESSION_ID_COOKIE, sessionIdCookie);
|
- |
|
| 154 |
|
147 |
|
| - |
|
148 |
//session id for chaining user actions over one year
|
| - |
|
149 |
sessionIdCookie = (Cookie) cookiesMap.get(SESSION_ID_COOKIE);
|
| - |
|
150 |
if (sessionIdCookie == null) {
|
| - |
|
151 |
String sessionId = request.getSession().getId();
|
| - |
|
152 |
sessionIdCookie = createCookie(SESSION_ID_COOKIE, cookieDomain, sessionId, SECONDS_IN_YEAR);
|
| - |
|
153 |
cookiesMap.put(SESSION_ID_COOKIE, sessionIdCookie);
|
| - |
|
154 |
|
| - |
|
155 |
response.addCookie(sessionIdCookie);
|
| - |
|
156 |
String firstSrc = "";
|
| - |
|
157 |
firstSourceCookie = (Cookie) cookiesMap.get(SRC_COOKIE);
|
| - |
|
158 |
if (firstSourceCookie != null) {
|
| - |
|
159 |
firstSrc = des.decrypt(firstSourceCookie.getValue());
|
| - |
|
160 |
}
|
| - |
|
161 |
DataLogger.logData(EventType.NEW_SESSION, cookiesMap.get(SESSION_ID_COOKIE).getValue(),
|
| - |
|
162 |
userInfo.getUserId(), userInfo.getEmail(), src, firstSrc);
|
| - |
|
163 |
}
|
| 155 |
|
164 |
|
| 156 |
response.addCookie(sessionSourceCookie);
|
165 |
response.addCookie(sessionSourceCookie);
|
| 157 |
response.addCookie(sessionSourceTimeCookie);
|
166 |
response.addCookie(sessionSourceTimeCookie);
|
| 158 |
response.addCookie(sessionIdCookie);
|
- |
|
| 159 |
|
- |
|
| 160 |
UserSessionInfo userInfo = (UserSessionInfo) request
|
- |
|
| 161 |
.getAttribute(UserInterceptor.USER_INFO_COOKIE_NAME);
|
- |
|
| 162 |
|
- |
|
| 163 |
String firstSrc = "";
|
- |
|
| 164 |
firstSourceCookie = (Cookie) cookiesMap.get(SRC_COOKIE);
|
- |
|
| 165 |
if (firstSourceCookie != null) {
|
- |
|
| 166 |
firstSrc = des.decrypt(firstSourceCookie.getValue());
|
- |
|
| 167 |
}
|
- |
|
| 168 |
DataLogger.logData(EventType.NEW_SESSION, cookiesMap.get(SESSION_ID_COOKIE).getValue(),
|
- |
|
| 169 |
userInfo.getUserId(), userInfo.getEmail(), src, firstSrc);
|
- |
|
| 170 |
}
|
167 |
}
|
| 171 |
|
168 |
|
| 172 |
private void createCookiesMap() {
|
169 |
private void createCookiesMap() {
|
| 173 |
cookiesMap = new HashMap<String, Cookie>();
|
170 |
cookiesMap = new HashMap<String, Cookie>();
|
| 174 |
Cookie[] cookies = request.getCookies();
|
171 |
Cookie[] cookies = request.getCookies();
|
| Line 182... |
Line 179... |
| 182 |
}
|
179 |
}
|
| 183 |
|
180 |
|
| 184 |
private void updateAffCookie() {
|
181 |
private void updateAffCookie() {
|
| 185 |
try {
|
182 |
try {
|
| 186 |
if(affId == null || affId.isEmpty()) {
|
183 |
if(affId == null || affId.isEmpty()) {
|
| 187 |
String referer = request.getHeader("referer");
|
- |
|
| 188 |
if (referer != null && !referer.isEmpty() && !referer.contains("saholic.com" ) && !referer.contains("shop2020.in" )) {
|
184 |
if (referer != null && !referer.isEmpty() && !referer.startsWith("http://www.saholic.com") && !referer.startsWith("http://www.shop2020.in")) {
|
| 189 |
Cookie affCookie = cookiesMap.get(AFF_COOKIE);
|
185 |
Cookie affCookie = cookiesMap.get(AFF_COOKIE);
|
| 190 |
if(affCookie != null) {
|
186 |
if(affCookie != null) {
|
| 191 |
affCookie.setDomain(cookieDomain);
|
187 |
affCookie.setDomain(cookieDomain);
|
| 192 |
affCookie.setPath("/");
|
188 |
affCookie.setPath("/");
|
| 193 |
affCookie.setValue("");
|
189 |
affCookie.setValue("");
|
| Line 224... |
Line 220... |
| 224 |
}
|
220 |
}
|
| 225 |
}
|
221 |
}
|
| 226 |
|
222 |
|
| 227 |
private String getSource() {
|
223 |
private String getSource() {
|
| 228 |
String src = "";
|
224 |
String src = "";
|
| 229 |
String referer = request.getHeader("referer");
|
- |
|
| 230 |
|
225 |
|
| 231 |
if (referer == null || referer.isEmpty()) {
|
226 |
if (referer == null || referer.isEmpty()) {
|
| 232 |
String queryString = request.getQueryString();
|
227 |
String queryString = request.getQueryString();
|
| 233 |
queryString = queryString == null? "" : "?" + queryString;
|
228 |
queryString = queryString == null? "" : "?" + queryString;
|
| 234 |
src = "DIRECT : " + "(" + request.getRequestURL() + "/" + queryString + ")";
|
229 |
src = "DIRECT : " + "(" + request.getRequestURL() + "/" + queryString + ")";
|