/* * Copyright (C) 2020 wit inc. */ var witCMSLog = witCMSLog || new function(){ this._aid = null; this._initStatus = {}; /** 初期設定処理ステータス (S:初期設定前, W:初期設定処理中, E:初期設定処理終了) **/ this._initProcList = {}; /** 初期設定ファンクションリスト **/ this._pkeyList = {}; /** PageID **/ this._pvCountList = {}; /** PageView Count **/ this._procStatus = {}; this._procStack = {}; this._lastCBID = 0; this._execstack = {}; this._params = {}; this._sys = {}; this._env = {}; this._setting = { server:'https://g-cms.wit-inc.jp' ,lver:100 /** Loader Version **/ ,sttime:null /** 起動開始時間 **/ ,timeout:1000 /** 通信のタイムアウト時間 **/ ,cookietype:'accept' /** Cookieの発行 */ ,cookie_expires:2*365*24*3600 /** Cookieの保持期間(2年) */ ,uid:null /** UserID(キャッシュ用) **/ ,uidcookie:'_wcms_uid' /** UID Cookie Name **/ ,muidcookie:'_wcms_mcc' /** MUID Cookie Name **/ ,sesstimeout:1800 /** セッションのタイムアウト時間 **/ }; this._constructor = function(){ this._env = { 'scs': function(){return ''+screen.width+'x'+screen.height} /** 画面サイズ **/ ,'scc': function(){return screen.colorDepth} /** 解像度 **/ ,'loc': function(){return document.location.href} /** ページURL **/ ,'tit': function(){return document.title} /** ページタイトル **/ ,'ref': function(){return document.referrer} /** 参照元 **/ ,'cha': function(){return document.charset} /** 文字コード **/ }; }; this.Exec = function(type, value, aid) { // console.log([type, value, aid, this._procStatus[aid]]); aid = aid || this._aid; this._aid = aid; if(!aid){return;}; /** 初期化処理 **/ if(type=='init'){ return this.stInit(aid, value); }; /** env **/ if(type=='setting'){ return this.setSetting(value[0], value[1]); }; /** param **/ if(type=='params'){ return this.setParams(aid, value[0], value[1]); }; if(type=='cinfo'){ return this.setCInfo(aid, value[0], value[1], value[2]); }; if(type=='uinfo'){ return this.setUInfo(aid, value[0], value[1], value[2]); }; if(type=='ipinfo'){ return this.loadIPInfo(aid); }; if(type=='nocookie'){ return this.loadIPInfo(aid); }; /** loadinit **/ if(type=='loadinit'){ return this.loadInit(aid, value); }; /** Functionを実行 **/ if(type=='funcinit'){ if(typeof(value)=='function'){return value(this, aid)} }; /** start **/ if(type=='start'){ return this.execStackProcess(aid, value); }; /** 初期設定処理未完了の場合 実行命令をスタックに保存 **/ // console.log(['_initProcList', this._initProcList['wit']]); if(this._procStatus[aid] != 'E'){ (this._procStack[aid]=this._procStack[aid]||[]).push([type, value, aid]); return; }; /** 実行処理 **/ if(type=='load'){ return this.loadScript(aid, value); }; if(type=='func'){ if(typeof(value)=='function'){return value(this, aid)} }; if(type=='loadcontents'){ return this.setLoadContents(aid, value); }; if(type=='send'){ return this.loadImage(aid, value); }; if(type=='pageview'){ return this.setSendPageview(aid, value); }; if(type=='event'){ return this.setSendEvent(aid, value); }; }; /** 初期化処理 **/ this.stInit = function(aid, ename) { // console.log(['stInit', aid, ename]); if(!this.getPKey(aid)){ this.setPKey(aid); }; // USERID var uid = this.getcookie(this.getSetting('uidcookie')); if(!uid){ uid = this.createID(); } this.setSetting('uid', uid); this.setParams(aid, 'sys.uid', uid); this.setParams(aid, 'sys.muid', this.getcookie(this.getSetting('muidcookie'))); // this.setState(cbid, 'success'); this._initStatus[aid] = this._initStatus[aid] || 'S'; if(this._initStatus[aid]!='S'){return}; this._initStatus[aid] = 'W'; this._initProcList[aid] = {}; if(ename=='load'){ this.addEvent( ename, function(){ var aid = arguments[0]; return function(){ witCMSLog.execStackProcess(aid) }; }(aid)); } else{ this._initStatus[aid]='E'; if(this._initProcList[aid]){ delete this._initProcList[aid]; }; this.execStackProcess(aid); }; }; this.enInit = function(aid) { if(this._initStatus[aid]!='W'){return}; var size = 0; for(var prop in this._initProcList[aid]){ if(this._initProcList[aid].hasOwnProperty(prop)){ size++; } }; if(size==0){ this._initStatus[aid]='E'; if(this._initProcList[aid]){ delete this._initProcList[aid]; }; this.execStackProcess(aid); }; }; this.loadInit = function(aid, argv){ if(!aid || !argv){return null;}; argv.type='init'; return this.loadScript(aid, argv); }; /** スタック処理を実行 **/ this.execStackProcess = function(aid) { // console.log(['execStackProcess', this._initStatus[aid]]); if(this._initStatus[aid]!='E'){return}; this._procStatus[aid] = this._procStatus[aid] || 'S'; if(this._procStatus[aid]!='E'){ this._procStatus[aid] = 'S'; }; if(this._procStatus[aid]!='S'){return}; /** 初期設定処理終了後、スタック処理を実行 **/ this._procStatus[aid] = 'E'; this._procStack[aid]=this._procStack[aid] || []; for(var i=0;i=1){ return res[0]; }; return null; }; /** UINFOパラメーター設定 **/ this.initUInfo = function(aid, key, values) { if(!this.getUInfo(aid, key)){ return this.setParams(aid, 'uinfo.'+key, [values]); }; return false; }; this.setUInfo = function(aid, key, values, expires) { expires = expires || this.getSetting('param_expires'); return this.setParams(aid, 'uinfo.'+key, [values, expires]); }; this.getUInfo = function(aid, key) { var res = this.getParams(aid, 'uinfo.'+key); if(res && res.length>=1){ return res[0]; }; return null; }; /** システム設定 **/ this.getUptime = function(){ return +new Date() - this._setting.sttime; }; this.setSttime = function(time){ this._setting.sttime = this._setting.sttime || time; }; /** Query **/ this.getBaseQuery = function(aid){ var result = ''; result+='?aid='+this.strencode(aid); result+='&u='+this.strencode(this.getUptime()); result+='&lv='+this.strencode(this.getSetting('lver')); result+='&uid='+this.strencode(this.getParams(aid, 'sys.uid')); result+='&gid='+this.strencode(this.getParams(aid, 'sys.gid')); result+='&muid='+this.strencode(this.getParams(aid, 'sys.muid')); result+='&uip='+this.strencode(this.getSetting('useipinfo')); return result; }; this.getEnvQuery = function() { var result = ''; for (var key in this._env){ var val = this._env[key](); if(val){ result+= '&e_'+this.strencode(key)+'='+this.strencode(val); }; }; return result; }; this.getParamsQuery = function(aid) { var url = ''; // console.log(['getParamsQuery', this._params]); if(!this._params[aid]){ return ''; }; if(this._params[aid]['cinfo']){ url+='&p_ci='+this.strencode(this.JsonStringfy(this._params[aid]['cinfo'])); }; if(this._params[aid]){ for (var key in this._params[aid]) { if(key.indexOf('ipinfo.') !== -1){ url+='&'+this.strencode(key)+'='+this.strencode(this._params[aid][key]); } }; }; return url; }; this.getArgvQuery = function(argv) { var url = ''; if(argv.params){ for (var key in argv.params) { url+='&'+this.strencode(key)+'='+this.strencode(argv.params[key]); }; }; return url; }; this.getTQuery = function() { var url = ''; url+='&t='+(1*new Date())+Math.random(); return url; }; /** 外部JavaScriptを読み込み **/ this.loadScript = function(aid, argv){ if(!aid || !argv){return null;}; var cbid = this.createCBID(); this._execstack[cbid] = {aid:aid, argv:argv}; /** 初期設定の場合 **/ if(argv.type=='init' && this._initProcList[aid]){ this._initProcList[aid][cbid]=1; }; /** preLoad **/ if(!this.setState(cbid, 'init')){return null;}; var url = ''; if(argv.url.match(/^\//)){ url+=this.getSetting('server')+argv.url; }else{ url+=argv.url; }; url+=this.getBaseQuery(aid); url+='&cbid='+this.strencode(cbid); url+=this.getArgvQuery(argv); url+=this.getEnvQuery(); if(argv.type!='init'){ url+=this.getParamsQuery(aid); }; url+=this.getTQuery(); var script = this.loadJavaScript(url); this._execstack[cbid]['script'] = script; this._execstack[cbid]['url'] = url; script.onload = function(){ var cbid = arguments[0]; return function(){ witCMSLog.setState(cbid, 'load') }; }(cbid); script.onreadystatechange = function(){ var cbid = arguments[0]; return function(){ if(this._execstack[cbid]['script'].readyState=='complete'){ witCMSLog.setState(cbid, 'load') } }; }(cbid); var timeout = argv.timeout || this.getSetting('timeout'); this._execstack[cbid]['timeoutID'] = setTimeout( function(){ var cbid = arguments[0]; return function(){ witCMSLog.setState(cbid, 'timeout') }; }(cbid), timeout); this._execstack[cbid]['timeout'] = timeout; return cbid; }; this.setState = function(cbid, status){ // console.log(['setState', cbid, status]); if(!(this._execstack[cbid])){return false}; this._execstack[cbid]['status'] = status; var stack = this._execstack[cbid]; if(stack.argv['on'+status]){ stack.argv['on'+status](this, stack.aid, stack.argv, status); }; if(status == 'success' || status == 'timeout' || (status == 'load' && stack.argv['plugin3rdparty'])){ if(stack.argv['onend']){ stack.argv['onend'](this, stack.aid, stack.argv, status); }; if(this._execstack[cbid]['timeoutID']){ clearTimeout(this._execstack[cbid]['timeoutID']); }; /** Init終了処理 **/ if(this._initProcList[stack.aid]){ delete this._initProcList[stack.aid][cbid]; this.enInit(stack.aid); }; delete this._execstack[cbid]; }; return true; }; this.createCBID = function(){ this._lastCBID++; return this._lastCBID; }; /** データ送信 **/ this.loadImage = function(aid, argv){ if(!aid || !argv){return null;}; var url = ''; if(argv.url.match(/^\//)){ url+=this.getSetting('server')+argv.url; }else{ url+=argv.url; }; url+=this.getBaseQuery(aid); url+=this.getArgvQuery(argv); url+=this.getEnvQuery(); url+=this.getParamsQuery(aid); url+='&t='+(1*new Date())+Math.random(); var im=new Image(1,1); im.src=url; url.onload=function(){ return; }; }; this.replaceContent = function(selector, content){ var obj = null; var jquery_flg = false; if(typeof(selector)==='object'){ if(selector['id']){ obj = document.getElementById(selector['id']); }else if(selector['tag'] && typeof(document.getElementsByTagName)==='function'){ obj = document.getElementsByTagName(selector['tag']); }else if(selector['class'] && typeof(document.getElementsByClassName)==='function'){ obj = document.getElementsByClassName(selector['class']); }else if(selector['jquery'] && typeof(jQuery)==='function'){ obj = jQuery(selector['jquery']); jquery_flg = true; }; }else if(selector){ obj = document.getElementById(selector); }; if(!obj){return;}; if(jquery_flg){ if(obj.length > 0){ jQuery.each(obj, function(){ jQuery(this).html(content); }); }else{ obj.html(content); }; }else{ if(obj.length > 0){ for(var i=0;i 1){ this.setPKey(aid); }; params = {}; params['ac'] = 'pv'; params['pid'] = value; this.Exec('send', { url: '/g/s.php', params: params }, aid); }; /** setSendEvent **/ this.setSendEvent = function(aid, value) { if(!this.getPKey(aid)){ this.setPKey(aid); }; params = {}; params['ac'] = 'ev'; if(value){ value = value || []; params['ev_l'] = value[0]?value[0]:''; params['ev_v'] = value[1]?value[1]:''; }; this.Exec('send', { url: '/u/'+aid+'/s.php', params: params }, aid); }; /** create JSON **/ this.JsonStringfy = function(e) { function n(e) { var r,i,s,u; var a = typeof e; if (a == "object") { if (!e) { return "null"; } else if (e.constructor == Array) { s = ''; u = e.length; for (r = 0; r < u; r++) { if (r) s += ","; s += n(e[r]); }; return "[" + s + "]"; } else { s = ''; for (i in e) { if (s != '') s += ","; s += n(i) + ":" + n(e[i]); }; return "{" + s + "}"; }; } else if (a == "string") { s = ''; u = e.length; for (r = 0; r < u; r++) { if (t[e.charAt(r)] != undefined) { s += t[e.charAt(r)] } else { s += e.charAt(r) }; }; return '"' + s + '"'; } else if (a == "number") { if (isNaN(e)) return "null"; if (e == Number.POSITIVE_INFINITY) return "null"; if (e == Number.NEGATIVE_INFINITY) return "null"; return e.toString(); } else if (a == "boolean") { return e.toString(); } else if (a == "null" || a == "undefined") { return "null"; }; return null; }; var t = new Object; t["\b"] = "\\b"; t["\f"] = "\\f"; t["\n"] = "\\n"; t["\r"] = "\\r"; t[" "] = "\\t"; t['"'] = '\\"'; t["\\"] = "\\\\"; return n(e); }; /** create ID **/ this.createID = function(){ return (this._s4()+this._s4()+"-"+this._s4()+"-"+this._s4()+"-"+this._s4()+"-"+this._s4()+this._s4() +this._s4()); }; this._s4 = function(){ return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }; this.strencode = function(str) { if(typeof(encodeURIComponent)==='function'){ return encodeURIComponent(str); }else{ return escape(str); }; }; this.strdecode = function(str) { if (typeof(decodeURIComponent)==='function') { return decodeURIComponent(str); } else { return unescape(str); }; }; /** Event **/ this.addEvent = function(event_name,func){ try{ window.addEventListener(event_name,func,false); }catch(e){ window.attachEvent('on'+event_name,func); }; }; /** Query **/ this.getquery = function(key) { var c1 = document.search; c1 = " "+c1+"&"; var ind1 = 0; var len = c1.length; while (ind1 < len) { var ind2 = c1.indexOf("&", ind1); var c2 = c1.substring(ind1 + 1, ind2); var ind3 = c2.indexOf("="); if (c2.substring(0, ind3) == key) { if(ind2 - ind1 - 1 <= 0){ return null; }; return this.strdecode(c2.substring(ind3 + 1, ind2 - ind1 - 1)); }; ind1 = ind2 + 1; }; return null; }; /** Cookie **/ this.getcookie = function(key) { var c1 = document.cookie; c1 = " "+c1+";"; var ind1 = 0; var len = c1.length; while (ind1 < len) { var ind2 = c1.indexOf(";", ind1); var c2 = c1.substring(ind1 + 1, ind2); var ind3 = c2.indexOf("="); if (c2.substring(0, ind3) == key) { if(ind2 - ind1 - 1 <= 0){ return null; }; return this.strdecode(c2.substring(ind3 + 1, ind2 - ind1 - 1)); }; ind1 = ind2 + 1; }; return null; }; this.setcookie = function(key, val) { var c = key + "=" + this.strencode(val) + "; "; c += "path=/; "; c += "max-age="+this.getSetting('cookie_expires')+"; "; document.cookie = c; eval('try{ if(parent != null){ parent.document.cookie = c; } }catch(e){}'); }; this.isarray = function(value) { return value && typeof value === 'object' && typeof value.length === 'number' && typeof value.splice === 'function' && !(value.propertyIsEnumerable('length')); }; this._constructor(); }; (function(){ var v = 'witlog'; if(!window[v]){return;}; var q = window[v].q||[]; var s = window[v].s||(+new Date()); witCMSLog.setSttime(s); window[v]=function(type,value,aid){witCMSLog.Exec(type, value, aid);}; for(var i=0;i