wjc
2023-07-07 22494af577e21a930abef309f2f60c03c9615bd1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.hdl.log.utils;
 
import com.aliyu.LogProducerClient;
import com.aliyun.sls.android.producer.Log;
import com.hdl.log.HDLLog;
import com.hdl.log.bean.LogBean;
 
import java.util.Map;
 
/**
 * Created by hxb on 2023/3/16.
 *
 */
public class PointUtil {
    private static LogProducerClient pointProducerClient;
    private static LogBean logBean;
 
    private static synchronized LogProducerClient getExceptionProducerClient() {
        if (pointProducerClient == null) {
            pointProducerClient = new LogProducerClient(HDLLog.getContext(),HDLLog.getEndPoint(),HDLLog.getProjectName(),HDLLog.getEventTracking(),HDLLog.getAccessId(),HDLLog.getAccessKey(),null,null);
        }
        return pointProducerClient;
    }
    /**
     * 数据埋点
     * @param eventId 标题
     * @param eventMap 附加数据内容
     * @param otherMsg 其他附加数据,没有可为空
     */
    public static void point(String eventId,String eventMap,Map<String, String> otherMsg) {
        Log log = new Log();
        log.putContent("eventId", eventId);
        log.putContent("eventMap", eventMap);
        log.putContent("userId", getLogBean().getUserId());
        log.putContent("homeId", getLogBean().getHomeId());
        log.putContent("time", System.currentTimeMillis() + "");
        log.putContent("userAgent", getLogBean().getUserAgent());
        log.putContent("appVersion", getLogBean().getAppVersion());
        if (otherMsg != null) {
            log.putContents(otherMsg);
        }
        getExceptionProducerClient().sendLog(log);
    }
 
    public static LogBean getLogBean() {
        if(logBean==null){
            logBean=new LogBean();
        }
        return logBean;
    }
}