Subversion Repositories SmartDukaan

Rev

Rev 3508 | Rev 3860 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3508 Rev 3588
Line 7... Line 7...
7
import in.shop2020.thrift.clients.UserClient;
7
import in.shop2020.thrift.clients.UserClient;
8
import in.shop2020.utils.DataLogger;
8
import in.shop2020.utils.DataLogger;
9
 
9
 
10
import java.util.Date;
10
import java.util.Date;
11
import java.util.HashMap;
11
import java.util.HashMap;
-
 
12
import java.util.HashSet;
12
import java.util.Map;
13
import java.util.Map;
-
 
14
import java.util.Set;
13
 
15
 
14
import javax.servlet.http.Cookie;
16
import javax.servlet.http.Cookie;
15
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletRequest;
16
import javax.servlet.http.HttpServletResponse;
18
import javax.servlet.http.HttpServletResponse;
17
 
19
 
Line 34... Line 36...
34
    public static final String SESSION_SRC_COOKIE = "sess_srcc";
36
    public static final String SESSION_SRC_COOKIE = "sess_srcc";
35
    public static final String SRC_TIME_COOKIE = "usrctc";
37
    public static final String SRC_TIME_COOKIE = "usrctc";
36
    public static final String SESSION_SRC_TIME_COOKIE = "sess_srctc";
38
    public static final String SESSION_SRC_TIME_COOKIE = "sess_srctc";
37
    public static final String SESSION_ID_COOKIE = "sess_idc";
39
    public static final String SESSION_ID_COOKIE = "sess_idc";
38
    public static final String ENCRIPTION_STRING = "Saholic";
40
    public static final String ENCRIPTION_STRING = "Saholic";
-
 
41
    private static final Set<String> paidAffIds;
39
 
42
    
40
    private String cookieDomain = "";
43
    private String cookieDomain = "";
41
    private Cookie affCookie = null;
44
    private Cookie affCookie = null;
42
    private Cookie firstSourceCookie = null;
45
    private Cookie firstSourceCookie = null;
43
    private Cookie sessionSourceCookie = null;
46
    private Cookie sessionSourceCookie = null;
44
    private Cookie firstSourceTimeCookie = null;
47
    private Cookie firstSourceTimeCookie = null;
45
    private Cookie sessionSourceTimeCookie = null;
48
    private Cookie sessionSourceTimeCookie = null;
46
    private Cookie sessionIdCookie = null;
49
    private Cookie sessionIdCookie = null;
47
    private Map<String, Cookie> cookiesMap = null;
50
    private Map<String, Cookie> cookiesMap = null;
48
    private HttpServletRequest request;
51
    private HttpServletRequest request;
49
    private HttpServletResponse response;
52
    private HttpServletResponse response;
-
 
53
    private String affId = null;
-
 
54
    
-
 
55
    static {
-
 
56
        paidAffIds = new HashSet<String>();
-
 
57
        paidAffIds.add("6");
-
 
58
        paidAffIds.add("38");
-
 
59
    }
-
 
60
    
50
 
61
 
51
    public void setCookieDomain(String cookieDomain) {
62
    public void setCookieDomain(String cookieDomain) {
52
        this.cookieDomain = cookieDomain;
63
        this.cookieDomain = cookieDomain;
53
    }
64
    }
54
 
65
 
55
    @Override
66
    @Override
56
    public String intercept(ActionInvocation invocation) throws Exception {
67
    public String intercept(ActionInvocation invocation) throws Exception {
57
        request = ServletActionContext.getRequest();
68
        request = ServletActionContext.getRequest();
58
        response = ServletActionContext.getResponse();
69
        response = ServletActionContext.getResponse();
59
        
70
        
60
        String affId = request.getParameter("afid");
71
        affId = request.getParameter("afid");
61
        createCookiesMap();
72
        createCookiesMap();
62
        updateFirstSourceCookie();
73
        updateFirstSourceCookie();
63
        updateSessionSourceCookie();
74
        updateSessionSourceCookie();
64
 
75
 
65
        updateAffCookie(affId);
76
        updateAffCookie();
66
        return invocation.invoke();
77
        return invocation.invoke();
67
    }
78
    }
68
 
79
 
69
    /**
80
    /**
70
     * Update first source cookie
81
     * Update first source cookie
Line 168... Line 179...
168
        for (Cookie cookie : cookies) {
179
        for (Cookie cookie : cookies) {
169
            cookiesMap.put(cookie.getName(), cookie);
180
            cookiesMap.put(cookie.getName(), cookie);
170
        }
181
        }
171
    }
182
    }
172
 
183
 
173
    private void updateAffCookie(String affId) {
184
    private void updateAffCookie() {
174
        try {
185
        try {
175
            if(affId == null || affId.isEmpty()) {
186
            if(affId == null || affId.isEmpty()) {
176
                String referer = request.getHeader("referer");
187
                String referer = request.getHeader("referer");
177
                if (referer != null && !referer.isEmpty() && !referer.contains("saholic.com" ) && !referer.contains("shop2020.in" )) {
188
                if (referer != null && !referer.isEmpty() && !referer.contains("saholic.com" ) && !referer.contains("shop2020.in" )) {
178
                    Cookie affCookie = cookiesMap.get(AFF_COOKIE);
189
                    Cookie affCookie = cookiesMap.get(AFF_COOKIE);
Line 214... Line 225...
214
	}
225
	}
215
    
226
    
216
    private String getSource() {
227
    private String getSource() {
217
        String src = "";
228
        String src = "";
218
        String referer = request.getHeader("referer");
229
        String referer = request.getHeader("referer");
-
 
230
        
-
 
231
        if (referer == null || referer.isEmpty()) {
219
        String queryString = request.getQueryString();
232
            String queryString = request.getQueryString();
220
        queryString = queryString == null? "" : "?" + queryString;
233
            queryString = queryString == null? "" : "?" + queryString;
221
 
-
 
222
        if (referer == null || referer.isEmpty() || referer.startsWith("http://www.saholic.com")
-
 
223
                || referer.startsWith("http://www.shop2020.in")) {            
-
 
224
            src = "DIRECT : " + "(" + request.getRequestURL() + queryString + ")";
234
            src = "DIRECT : " + "(" + request.getRequestURL() + "/" + queryString + ")";
225
        } else {
235
        } 
226
            final String PAID_AFID_REGEX = ".*afid=(6|38)([^0-9].*)?";
-
 
227
            if (referer.contains("google.co")) {
236
        else if (referer.startsWith("http://www.saholic.com") || referer.startsWith("http://www.shop2020.in")) {
228
                if(queryString.matches(PAID_AFID_REGEX)) {
-
 
229
                    src = "PAID : " + "(" + referer + ")";
237
            src = "DIRECT : " + "(" + referer + ")";
230
                }
238
        } 
231
                else {
239
        else if(paidAffIds.contains(affId)) {
232
                    src = "ORGANIC : " + "(" + referer + ")";
240
            src = "PAID : " + "(" + referer + ")";
233
                }
241
        }
234
            } else {
-
 
235
                if(queryString.contains(PAID_AFID_REGEX)) {
242
        else if (referer.contains("google.co")) {
236
                    src = "PAID : " + "(" + referer + ")";
243
            src = "ORGANIC : " + "(" + referer + ")";
237
                }
244
        }
238
                else {
245
        else {
239
                    src = referer;
246
            src = referer;
240
                }
-
 
241
            }
-
 
242
        }
247
        }
243
        return src;
248
        return src;
244
    }
249
    }
245
}
250
}
246
251