数据采集之js埋点
一、后台nginx环境搭建
web点数据采集后台配置nginx:
https://blog.csdn.net/weixin_37490221/article/details/80894827
下载数据源:
wget -o lua-nginx-module-0.10.0.tar.gz https://github.com/openresty/lua-nginx-module/archive/v0.10.0.tar.gz
wget --no-check-certificate -oecho-nginx-module-0.58.tar.gz 'https://github.com/openresty/echo-nginx-module/archive/v0.58.tar.gz'
wget --no-check-certificate -o nginx_devel_kit-0.2.19.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
wget https://openresty.org/download/openresty-1.9.7.3.tar.gz
wget --no-check-certificate -oset-misc-nginx-module-0.29.tar.gz 'https://github.com/openresty/set-misc-nginx-module/archive/v0.29.tar.gz'
二、前端埋点
前端页面中需要加载ma.js的脚本代码
<script type="text/javascript"> var _maq = _maq || []; _maq.push(['_setaccount', 'zaomianbao']); (function() { var ma = document.createelement('script'); ma.type = 'text/javascript'; ma.async = true; ma.src = 'http://ip111/ma.js'; var s = document.getelementsbytagname('script')[ 0]; s.parentnode.insertbefore(ma, s); })(); </script>
放到后台的前端代码
(function () { var params = {}; var args = ''; if(document) { params.domain = document.domain || ''; params.url = document.url || ''; params.title = document.title || ''; params.referrer = document.referrer || ''; params.bio = document.getelementbyid("username").innerhtml || ''; params.clickbio = ''; } document.queryselector("div#page-wrapper .wrapper.wrapper-content.animated.fadeinright").addeventlistener("click",function(e){ params.clickbio = getchinese(e.target.innerhtml); console.log(params.clickbio) args = ''; console.log(params.clickbio) for(var i in params) { if(args != '') { args += '&'; } args += i + '=' + encodeuricomponent(params[i]); } var img = new image(1, 1); img.src = 'http://ip111/log.gif?' + args; }) function getchinese(strvalue) { if(strvalue!= null && strvalue!= ""){ var reg = /[\u4e00-\u9fa5]/g; return strvalue.match(reg).join(""); } } if(window && window.screen) { params.sh = window.screen.height || 0; params.sw = window.screen.width || 0; params.cd = window.screen.colordepth || 0; } if(navigator) { params.lang = navigator.language || ''; } if(_maq) { for(var i in _maq) { switch(_maq[i][0]) { case '_setaccount': params.account = _maq[i][1]; break; default: break; } } } for(var i in params) { if(args != '') { args += '&'; } args += i + '=' + encodeuricomponent(params[i]); } var img = new image(1, 1); img.src = 'http://ip111/log.gif?' + args; })();
三、后端配置
配置nginx服务器日志格式
worker_processes 2; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; log_format user_log_format "$u_clickbio||$u_bio||$time_local||$msec||$remote_addr||$status||$body_bytes_sent||$u_domain||$u_url||$u_title||$u_referrer||$u_sh||$u_sw||$u_cd||$u_lang||$http_user_agent||$u_account"; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location /log.gif { default_type image/gif; access_log logs/access.log main; access_by_lua " local uid = ngx.var.cookie___utrace if not uid then uid = ngx.md5(ngx.now() .. ngx.var.remote_addr .. ngx.var.http_user_agent) end ngx.header['set-cookie'] = {'__utrace=' .. uid .. '; path=/'} if ngx.var.arg_domain then ngx.location.capture('/i-log?' .. ngx.var.args .. '&utrace=' .. uid) end "; add_header expires "fri, 01 jan 1980 00:00:00 gmt"; add_header pragma "no-cache"; add_header cache-control "no-cache, max-age=0, must-revalidate"; empty_gif; } location /i-log { internal; set_unescape_uri $u_clickbio $arg_clickbio; set_unescape_uri $u_bio $arg_bio; set_unescape_uri $u_domain $arg_domain; set_unescape_uri $u_url $arg_url; set_unescape_uri $u_title $arg_title; set_unescape_uri $u_referrer $arg_referrer; set_unescape_uri $u_sh $arg_sh; set_unescape_uri $u_sw $arg_sw; set_unescape_uri $u_cd $arg_cd; set_unescape_uri $u_lang $arg_lang; set_unescape_uri $u_account $arg_account; log_subrequest on; access_log logs/user_defined.log user_log_format; echo ''; } } }
推荐阅读
-
基于preg_match_all采集后数据处理的一点心得笔记(编码转换和正_PHP
-
《单片机实践项目》之《电子DIY》之基于51单片机温度(DS18B20)采集系统设计(串口打印数据)
-
php 采集js传递过来的数据
-
c/c++客戶端使用google analytics进行数据埋点上传
-
Node.js学习之TCP/IP数据通讯(实例讲解)
-
每天一点数据库之
-
基于curl数据采集之单页面并行采集函数get_htmls的使用_PHP
-
javascript - 网站埋点,统计用户数据
-
利用ASP.NET MVC+Bootstrap搭建个人博客之praise.js点赞特效插件(二)
-
Node.js数据库操作之查询MySQL数据库(二)