类似谷歌,在网站里面嵌入js,接收各种浏览器信息以及网站信息

需要3个步骤:js 收集,调动接口, php接收,通过ip找到国家,然后存储

1.

需要在网页里面嵌入js代码:

  1. <script type="text/javascript">
  2. var _maq = _maq || [];
  3. _maq.push(['website_id', '3']);
  4. (function() {
  5. var ma = document.createElement('script'); ma.type = 'text/javascript'; ma.async = true;
  6. ma.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'static.tomtop-cdn.com/tomtop/js/trace.js';
  7. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ma, s);
  8. })();
  9. </script>

上下面的代码,是在每一个页面都需要加入,您可以加入到页面的底部

如果您想收集某些页面的单独的数据,譬如:产品页面的sku,你可以加入下面的代码,这个代码必须在上面的代码的前面:

  1. <script type="text/javascript">
  2. var _maq = _maq || [];
  3. _maq.push(['sku', '$sku']);
  4. </script>

一定要注意,这个代码一定要在上面

如果传递购物车信息,可以用json个数传递

2. 全局加入的js代码可以看到有个trace.js    这个js文件就是下面的内容

  1. (function () {
  2. var nVer = navigator.appVersion;
  3. var nAgt = navigator.userAgent;
  4. var browserName = navigator.appName;
  5. var fullVersion = ''+parseFloat(navigator.appVersion);
  6. var majorVersion = parseInt(navigator.appVersion,10);
  7. var nameOffset,verOffset,ix;
  8. // In Opera, the true version is after "Opera" or after "Version"
  9. if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
  10. browserName = "Opera";
  11. fullVersion = nAgt.substring(verOffset+6);
  12. if ((verOffset=nAgt.indexOf("Version"))!=-1)
  13. fullVersion = nAgt.substring(verOffset+8);
  14. }
  15. // In MSIE, the true version is after "MSIE" in userAgent
  16. else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
  17. browserName = "Microsoft Internet Explorer";
  18. fullVersion = nAgt.substring(verOffset+5);
  19. }
  20. // In Chrome, the true version is after "Chrome"
  21. else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
  22. browserName = "Chrome";
  23. fullVersion = nAgt.substring(verOffset+7);
  24. }
  25. // In Safari, the true version is after "Safari" or after "Version"
  26. else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
  27. browserName = "Safari";
  28. fullVersion = nAgt.substring(verOffset+7);
  29. if ((verOffset=nAgt.indexOf("Version"))!=-1)
  30. fullVersion = nAgt.substring(verOffset+8);
  31. }
  32. // In Firefox, the true version is after "Firefox"
  33. else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
  34. browserName = "Firefox";
  35. fullVersion = nAgt.substring(verOffset+8);
  36. }
  37. // In most other browsers, "name/version" is at the end of userAgent
  38. else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) <
  39. (verOffset=nAgt.lastIndexOf('/')) )
  40. {
  41. browserName = nAgt.substring(nameOffset,verOffset);
  42. fullVersion = nAgt.substring(verOffset+1);
  43. if (browserName.toLowerCase()==browserName.toUpperCase()) {
  44. browserName = navigator.appName;
  45. }
  46. }
  47. // trim the fullVersion string at semicolon/space if present
  48. if ((ix=fullVersion.indexOf(";"))!=-1)
  49. fullVersion=fullVersion.substring(0,ix);
  50. if ((ix=fullVersion.indexOf(" "))!=-1)
  51. fullVersion=fullVersion.substring(0,ix);
  52. majorVersion = parseInt(''+fullVersion,10);
  53. if (isNaN(majorVersion)) {
  54. fullVersion = ''+parseFloat(navigator.appVersion);
  55. majorVersion = parseInt(navigator.appVersion,10);
  56. }
  57. //得到手机的设备名称
  58. operate_relase = "";
  59. var OS_Name = navigator.appVersion;
  60. if (OS_Name.indexOf("Win") != -1) {
  61. operate = "Windows";
  62. if ((OS_Name.indexOf("Windows 95") != -1)||
  63. (OS_Name.indexOf("Win95") != -1) ||
  64. (OS_Name.indexOf("Windows_95") != -1)
  65. ) {
  66. operate_relase = "Windows 95";
  67. }else if ((OS_Name.indexOf("Windows 98") != -1)||
  68. (OS_Name.indexOf("Win98") != -1)) {
  69. operate_relase = "Win98";
  70. }else if ((OS_Name.indexOf("Windows NT 5.0") != -1)||
  71. (OS_Name.indexOf("Windows 2000") != -1)) {
  72. operate_relase = "Windows 2000";
  73. }else if ((OS_Name.indexOf("Windows NT 5.1") != -1)||
  74. (OS_Name.indexOf("Windows XP") != -1)) {
  75. operate_relase = "Windows XP";
  76. }else if (OS_Name.indexOf("Win16") != -1) {
  77. operate_relase = "Windows 3.11";
  78. }else if (OS_Name.indexOf("Windows NT 5.2") != -1) {
  79. operate_relase = "Windows Server 2003";
  80. }else if (OS_Name.indexOf("Windows NT 6.0") != -1) {
  81. operate_relase = "Windows Vista";
  82. }else if (OS_Name.indexOf("Windows NT 6.1") != -1) {
  83. operate_relase = "Windows 7";
  84. }else if ((OS_Name.indexOf("Windows NT 4.0") != -1)||
  85. (OS_Name.indexOf("WinNT4.0") != -1) ||
  86. (OS_Name.indexOf("WinNT") != -1)||
  87. (OS_Name.indexOf("Windows NT") != -1)) {
  88. operate_relase = "Windows NT 4.0";
  89. }else if (OS_Name.indexOf("Windows ME") != -1) {
  90. operate_relase = "Windows ME";
  91. }
  92. } else if (OS_Name.indexOf("Mac") != -1) {
  93. operate = "Mac OS";
  94. } else if (OS_Name.indexOf("X11") != -1) {
  95. operate = "Unix";
  96. } else if (OS_Name.indexOf("Linux") != -1) {
  97. operate = "Linux";
  98. } else if (OS_Name.indexOf("SunOS") != -1) {
  99. operate = "Sun OS";
  100. } else if (OS_Name.indexOf("OpenBSD") != -1) {
  101. operate = "Open BSD";
  102. } else if (OS_Name.indexOf("QNX") != -1) {
  103. operate = "QNX";
  104. } else if (OS_Name.indexOf("BeOS") != -1) {
  105. operate = "BeOS";
  106. } else if (OS_Name.indexOf("OS/2") != -1) {
  107. operate = "OS/2";
  108. } else if ((OS_Name.indexOf("nuhk") != -1)
  109. || (OS_Name.indexOf("Googlebot") != -1)
  110. || (OS_Name.indexOf("Yammybot") != -1)
  111. || (OS_Name.indexOf("Openbot") != -1)
  112. || (OS_Name.indexOf("Slurp") != -1)
  113. || (OS_Name.indexOf("MSNBot") != -1)
  114. || (OS_Name.indexOf("Ask Jeeves/Teoma") != -1)
  115. || (OS_Name.indexOf("ia_archiver") != -1)
  116. ) {
  117. operate = "Search Bot";
  118. }else{
  119. operate = "unknow";
  120. }
  121. /
  122. //通过参数,得到url中参数的值
  123. function getParameterByName(name) {
  124. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  125. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  126. results = regex.exec(location.search);
  127. return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  128. }
  129. //得到当前的时间
  130. function getDate(){
  131. var currentdate = new Date();
  132. month = currentdate.getMonth();if(month<10){month = "0"+month;}
  133. day = currentdate.getDate();if(day<10){day = "0"+day;}
  134. hours = currentdate.getHours();if(hours<10){hours = "0"+hours;}
  135. minutes = currentdate.getMinutes();if(minutes<10){minutes = "0"+minutes;}
  136. second = currentdate.getSeconds();if(second<10){second = "0"+second;}
  137. var datetime = currentdate.getFullYear() + "-"
  138. + month + "-"
  139. + day + " "
  140. + hours + ":"
  141. + minutes + ":"
  142. + second;
  143. return datetime ;
  144. }
  145. //得到设备名称
  146. function getDevice(){
  147. var isMobile = {
  148. Android: function() {
  149. return navigator.userAgent.match(/Android/i);
  150. },
  151. webOS:function() {
  152. return navigator.userAgent.match(/webOS/i);
  153. },
  154. BlackBerry: function() {
  155. return navigator.userAgent.match(/BlackBerry/i);
  156. },
  157. iPhone: function() {
  158. return navigator.userAgent.match(/iPhone/i);
  159. },
  160. iPad: function() {
  161. return navigator.userAgent.match(/iPad/i);
  162. },
  163. iPod: function() {
  164. return navigator.userAgent.match(/iPod/i);
  165. },
  166. Opera: function() {
  167. return navigator.userAgent.match(/Opera Mini/i);
  168. },
  169. Windows: function() {
  170. return navigator.userAgent.match(/IEMobile/i);
  171. },
  172. any: function() {
  173. return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iPad() ||isMobile.iPod() || isMobile.iPhone() || isMobile.Opera() || isMobile.Windows());
  174. }
  175. };
  176. var str = "";
  177. if( isMobile.Android() ) { str = "Android"; }
  178. if( isMobile.webOS() ) { str = "webOS"; }
  179. if( isMobile.BlackBerry() ) { str = "BlackBerry"; }
  180. if( isMobile.iPhone() ) { str = "iPhone"; }
  181. if( isMobile.iPad() ) { str = "iPad"; }
  182. if( isMobile.iPod() ) { str = "iPod"; }
  183. if( isMobile.Opera() ) { str = "Opera"; }
  184. if( isMobile.Windows() ) { str = "Windows"; }
  185. if(str){
  186. return "Mobile:"+str;
  187. }else{
  188. return "PC";
  189. }
  190. }
  191. //
  192. function s4() {
  193. return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
  194. };
  195. function guid() {
  196. return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
  197. }
  198. 得到唯一标示码uuid
  199. var uuid = guid();
  200. 设置cookie,默认是设置天 expires代表的是天数。
  201. function Set_Cookie( name, value, expires, path, domain, secure )
  202. {
  203. // set time, it's in milliseconds
  204. domain = document.domain;
  205. domain = domain.replace("www.","");
  206. var today = new Date();
  207. today.setTime( today.getTime() );
  208. /*
  209. if the expires variable is set, make the correct
  210. expires time, the current script below will set
  211. it for x number of days, to make it for hours,
  212. delete * 24, for minutes, delete * 60 * 24
  213. */
  214. if ( expires )
  215. {
  216. expires = expires * 1000 * 60 * 60 * 24;
  217. }else{
  218. expires = expires * 20 * 365 * 1000 * 60 * 60 * 24;
  219. }
  220. var expires_date = new Date( today.getTime() + (expires) );
  221. this_expires = expires/1000;
  222. //document.write("thisdomain:"+domain+"<br/>");
  223. document.cookie = name + "=" +escape( value ) +
  224. ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  225. ( ( path ) ? ";path=" + path : "" ) +
  226. ( ( domain ) ? ";domain=" + domain : "" ) +
  227. ( ( secure ) ? ";secure" : "" );
  228. }
  229. //得到cookie
  230. function Get_Cookie( check_name ) {
  231. // first we'll split this cookie up into name/value pairs
  232. // note: document.cookie only returns name=value, not the other components
  233. var a_all_cookies = document.cookie.split( ';' );
  234. var a_temp_cookie = '';
  235. var cookie_name = '';
  236. var cookie_value = '';
  237. var b_cookie_found = false; // set boolean t/f default f
  238. for ( i = 0; i < a_all_cookies.length; i++ )
  239. {
  240. // now we'll split apart each name=value pair
  241. a_temp_cookie = a_all_cookies[i].split( '=' );
  242. // and trim left/right whitespace while we're at it
  243. cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
  244. // if the extracted name matches passed check_name
  245. if ( cookie_name == check_name )
  246. {
  247. b_cookie_found = true;
  248. // we need to handle case where cookie has no value but exists (no = sign, that is):
  249. if ( a_temp_cookie.length > 1 )
  250. {
  251. cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
  252. }
  253. // note that in cases where cookie is initialized but no value, null is returned
  254. return cookie_value;
  255. break;
  256. }
  257. a_temp_cookie = null;
  258. cookie_name = '';
  259. }
  260. if ( !b_cookie_found )
  261. {
  262. return null;
  263. }
  264. }
  265. //删除cookie
  266. function Delete_Cookie( name, path, domain ) {
  267. if ( Get_Cookie( name ) ) document.cookie = name + "=" +
  268. ( ( path ) ? ";path=" + path : "") +
  269. ( ( domain ) ? ";domain=" + domain : "" ) +
  270. ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  271. }
  272. var params = {};
  273. // 设置 cid 如果新的cid访问,那么cid将会被覆盖。
  274. cid = getParameterByName("cid");
  275. var cookie_cid = Get_Cookie("cid");
  276. if(cid){
  277. //set cid cookie.
  278. params.cid = cid;
  279. Set_Cookie( "cid", cid, 7, "/", '', '' );
  280. }else if(cookie_cid){
  281. params.cid = cookie_cid;
  282. }
  283. //设备
  284. params.devide = getDevice();
  285. params.user_agent = navigator.userAgent;
  286. var userLang = navigator.language || navigator.userLanguage;
  287. params.browser_name = browserName; //浏览器名称
  288. params.browser_version = majorVersion; //浏览器版本
  289. params.browser_date = getDate(); //浏览器时间
  290. params.browser_lang = userLang; //浏览器语言
  291. params.operate = operate; //操作系统
  292. params.operate_relase = operate_relase; //操作系统详细
  293. //Document对象数据
  294. //通过加入下面的代码,来辨别是否是老客户
  295. //标准为:refer domain为空,或者不包含 && _fta 这个cookie存在
  296. //在数据分析中,客户中间客户点击刷新页面,也会被标示成return:1,因此,在分析的时候,需要找UID
  297. //最小的那个,查看refer。
  298. if(document) {
  299. params.domain = document.domain || ''; //域名
  300. params.url = document.URL || ''; //当前url
  301. params.title = document.title || ''; //当前title
  302. params.refer_url = document.referrer || ''; //来源referrer
  303. //thisrefer = document.referrer || '';
  304. //refer_fta_cookie = Get_Cookie( '_fta' );
  305. //此cookie用来判断客户是否是持续的访问网站,如果设置的是6个小时,如果客户在6个小时内第二次访问网站
  306. //系统会认为这是客户的一次连贯的访问。第二次访问后,此cookie会更新超时时间
  307. _fto = Get_Cookie( '_fto' );
  308. // //永久cookie,这个cookie存在,那么说明是老客户了
  309. _fta = Get_Cookie( '_fta' );
  310. if(_fto){
  311. //继续的访问,访问的延伸。无所谓refer,和return
  312. //更新超时时间:
  313. Set_Cookie( '_fto',1, 0.25, '/', '', '' ); //online - one day
  314. }else{
  315. //相当于第一次访问。
  316. thisreferrer = document.referrer || '';
  317. // 存在refer 则记录refer ,如果不存在,则设置redirect
  318. if(!thisreferrer){
  319. thisreferrer_domain = "redirect";
  320. }else{
  321. thisreferrer_domain = thisreferrer.replace('http://','').replace('https://','').split(/[/?#]/)[0];
  322. }
  323. // 第一次访问网站的时候会记录访问来源。
  324. Set_Cookie( '_ftreferdomain',thisreferrer_domain, 1, '/', '', '' ); //refer - one day
  325. // 第一次访问的时候会设置_fto为6个小时。
  326. Set_Cookie( '_fto',1, 0.25, '/', '', '' ); //online - one day
  327. //如果存在_fta 则代表这个客户肯定访问过网站信息。
  328. if(_fta){
  329. //老客户,设置的cookie:来源域名,是否在线,是否是老客户
  330. Set_Cookie( '_ftreturn',1, 36500, '/', '', '' ); // is return - one day
  331. }else{
  332. //新客户
  333. Set_Cookie( '_ftreturn',0, 36500, '/', '', '' ); // is return - one day
  334. }
  335. }
  336. //referrer 域名,是否是老客户,是否是在线状态
  337. params.first_referrer_domain = Get_Cookie('_ftreferdomain');
  338. params.is_return = Get_Cookie('_ftreturn');
  339. //params.online = Get_Cookie('_fto');
  340. //设置uuid,如果 _fta存在,那么设置uuid为它的值,如果不存在,那么重新获取uuid。
  341. if(cookie_uuid = Get_Cookie('_fta') ){
  342. params.uuid = cookie_uuid;
  343. }else{
  344. params.uuid = uuid;
  345. Set_Cookie( '_fta', uuid, 36500, '/', '', '' );
  346. }
  347. }
  348. //Window对象数据
  349. if(window && window.screen) {
  350. //params.sh = window.screen.height || 0;
  351. //屏幕分辨率和屏幕的画质
  352. if(window.devicePixelRatio){
  353. devicePixelRatio = window.devicePixelRatio;
  354. params.device_pixel_ratio = devicePixelRatio;
  355. params.resolution = (window.screen.width*devicePixelRatio || 0) +"x"+ (window.screen.height*devicePixelRatio || 0);
  356. }else{
  357. params.resolution = (window.screen.width || 0) +"x"+ (window.screen.height || 0);
  358. }
  359. params.color_depth = window.screen.colorDepth || 0;
  360. }
  361. //解析_maq配置
  362. if(_maq) {
  363. for(var i in _maq) {
  364. x = _maq[i][0];
  365. if(x){
  366. //email
  367. //当前的customer email如果和cookie一样,那么使用customer email
  368. //如果不一样,那么保存customer email到cookie _fte
  369. //对于customer name同样也是这样
  370. if(x == 'login_email'){
  371. current_customer_email = _maq[i][1];
  372. //存在cookie
  373. if(cookie_customer_email = Get_Cookie( '_fte' )){
  374. //当前cookie存在,并且与传递过来的相同
  375. if(current_customer_email != cookie_customer_email){
  376. Set_Cookie( '_fte', current_customer_email, '36500', '/', '', '' );
  377. }
  378. //不存在cookie
  379. }else{
  380. Set_Cookie( '_fte', current_customer_email, '36500', '/', '', '' );
  381. }
  382. params[x] = current_customer_email;
  383. }else{
  384. params[x] = _maq[i][1];
  385. }
  386. }
  387. }
  388. }
  389. //如果cookie中存在客户邮箱,那么从cookie中获取
  390. if(!params.login_email){
  391. if(Get_Cookie( '_fte' )){
  392. params.login_email = Get_Cookie( '_fte' )
  393. }
  394. }
  395. //拼接参数串,形成url,然后通过图片的方式传递数据
  396. var args = '';
  397. for(var i in params) {
  398. if(args != '') {
  399. args += '&';
  400. }
  401. args += i + '=' + encodeURIComponent(params[i]);
  402. }
  403. //通过Image对象请求后端脚本
  404. var img = new Image(1, 1);
  405. img.src = 'http://trace.tomtop.com/trace.php?' + args;
  406. })();

原理:js手机的数据,通过参数的方式拼成一个url  :http://trace.tomtop.com/trace.php? xxxxx ,然后把数据传递给trace.php

 

2. ip找到国家(穿插部分)

 

3. php 存储(market.php)这里的geoip就是第二部分的通过ip找到国家

  1. <?php
  2. //exit;
  3. //date_default_timezone_set('Asia/Shanghai');
  4. # 时区
  5. ini_set('date.timezone','UTC');
  6. # ip 库
  7. include("/www/web/market/common/lib/geoip-api-php-1.14/src/geoip.inc");
  8. # log 测试函数
  9. function logdd($info){
  10. if(is_array($info) || is_object($info)){
  11. $info = var_export($info,true);
  12. }
  13. //echo $info;exit;
  14. $logfile = './logs/my.log';
  15. $handle = fopen($logfile,"a+");/*根据需要更改这里的参数*/
  16. $contents = fwrite($handle,$info."\n");
  17. fclose($handle);
  18. }
  19. #得到IP地址。
  20. function get_client_ip() {
  21. $ipaddress = '';
  22. if (getenv('HTTP_CLIENT_IP'))
  23. $ipaddress = getenv('HTTP_CLIENT_IP');
  24. else if(getenv('HTTP_X_FORWARDED_FOR'))
  25. $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
  26. else if(getenv('HTTP_X_FORWARDED'))
  27. $ipaddress = getenv('HTTP_X_FORWARDED');
  28. else if(getenv('HTTP_FORWARDED_FOR'))
  29. $ipaddress = getenv('HTTP_FORWARDED_FOR');
  30. else if(getenv('HTTP_FORWARDED'))
  31. $ipaddress = getenv('HTTP_FORWARDED');
  32. else if(getenv('REMOTE_ADDR'))
  33. $ipaddress = getenv('REMOTE_ADDR');
  34. else
  35. $ipaddress = 'UNKNOWN';
  36. return $ipaddress;
  37. }
  38. //得到国家。通过ip 支持ipv6 已经测试。
  39. function getCountryByIp($ip){
  40. $gi = geoip_open("/www/web/market/common/lib/geoip/GeoIP.dat", GEOIP_STANDARD);
  41. if(strstr($ip,":")){
  42. $country_code = geoip_country_code_by_addr_v6($gi,$ip);
  43. $country_name = geoip_country_name_by_addr_v6($gi,$ip);
  44. }else{
  45. $country_code = geoip_country_code_by_addr($gi,$ip);
  46. $country_name = geoip_country_name_by_addr($gi,$ip);
  47. }
  48. geoip_close($gi);
  49. return [
  50. "country_code" => $country_code,
  51. "country_name" => $country_name,
  52. ];
  53. }
  54. #得到递增id
  55. /*
  56. function increament($m,$db_name,$tablename){
  57. $ids = "ids";
  58. $db_name = "tracedb";
  59. $db = $m->selectDB($db_name);
  60. $col = $m->selectDB($db_name)->$ids;
  61. $query = array('name'=>'trace_2014_11_24');
  62. $update = array('?inc'=>array('id'=>1));
  63. $result = $db->command(
  64. array(
  65. "findandmodify" => "ids",
  66. "query" => $query,
  67. "update" => $update,
  68. )
  69. );
  70. return $result['value']['id'];
  71. }
  72. */
  73. $delay_time = " -0 hours";
  74. $insertTimeStamp = strtotime(date('Y-m-d H:i:s').' '.$delay_time);
  75. $insertDateTime = date('Y-m-d H:i:s',$insertTimeStamp);
  76. $insertDate = date('Y-m-d',$insertTimeStamp);
  77. $get = array();
  78. $get['ip'] = get_client_ip();
  79. #$get['server_datetime'] = date('Y-m-d H:i:s',strtotime('-12 hours')); //+3 hours 延后12个小时,美国时间
  80. $get['service_date_str'] = $insertDate;
  81. $get['service_datetime'] = new MongoDate($insertTimeStamp); #北京时间
  82. $get['service_timestamp'] = (float)$insertTimeStamp;
  83. foreach($_GET as $k=>$v){
  84. $get[$k] = $v;
  85. }
  86. # ip6 example
  87. #$get['ip'] = "2001:0DB8:0:0:0:0:1428:0000";
  88. $ip = $get['ip'];
  89. $website_id = $get['website_id'];
  90. $countInfo = getCountryByIp($ip);
  91. $get['country_code'] = $countInfo['country_code'];
  92. $get['country_name'] = $countInfo['country_name'];
  93. #连接到mongodb
  94. $m = new MongoClient('mongodb://localhost:27017');
  95. $database_name = "tracedb";
  96. #trace_网站编号_年份_月_initial_data
  97. $collection_name = "trace_".$website_id."_".date("Y_m",strtotime($delay_time))."_initial_data";
  98. $db = $m->$database_name;
  99. $collection = $db->$collection_name;
  100. #得到递增id。
  101. #$id = increament($m,$database_name,$collection_name);
  102. #$get["_id"] = $id;
  103. #var_dump($get);
  104. #订单信息
  105. if($get['order']){
  106. $get['order'] = json_decode($get['order'],true);
  107. $get['order_status'] = 'fail';
  108. }
  109. #购物车信息。
  110. if($get['cart']){
  111. $get['cart'] = json_decode($get['cart']);
  112. }
  113. #购物车信息。
  114. if($get['search']){
  115. $get['search'] = json_decode($get['search']);
  116. }
  117. #插入数据到mongodb
  118. if(!empty($get) && is_array($get)){
  119. $collection->insert($get);
  120. echo "Insert succsessfully";
  121. }

这样就把数据保存到mongodb里面去了。

然后就可以通过mongodb的mapreduce进行统计分析数据了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值