/* * A complete cookies reader/writer framework with full unicode support. */ var docCookies = { getItem: function (sKey) { return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null; }, setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) { if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; } var sExpires = ""; if (vEnd) { switch (vEnd.constructor) { case Number: sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd; break; case String: sExpires = "; expires=" + vEnd; break; case Date: sExpires = "; expires=" + vEnd.toUTCString(); break; } } document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : ""); return true; }, removeItem: function (sKey, sPath, sDomain) { if (!sKey || !this.hasItem(sKey)) { return false; } document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + ( sDomain ? "; domain=" + sDomain : "") + ( sPath ? "; path=" + sPath : ""); return true; }, hasItem: function (sKey) { return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie); }, keys: /* optional method: you can safely remove it! */ function () { var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/); for (var nIdx = 0; nIdx < aKeys.length; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); } return aKeys; } }; /* * Event Util */ var EventUtil = { getEvent: function (event) { return event ? event : window.event; }, addHandler: function (element, type, handler) { if (element.addEventListener) { element.addEventListener(type, handler, false); } else if (element.attachEvent) { element.attachEvent("on" + type, handler); } else { element["on" + type] = handler; } } }; /* * Document Util */ var DomUtil = { addScript: function(url, callback_name) { var newScript = document.createElement('script'), firstScript = document.getElementsByTagName('script')[0]; newScript.async = 1; if(callback_name) { url += url.indexOf('?') > -1 ? '&' : '?'; url += 'callback=' + callback_name; } newScript.src = url; firstScript.parentNode.insertBefore(newScript, firstScript); } } var ChartsmithTracker = {}; /* * Track initialize */ ChartsmithTracker.create = function() { }; /* * Track Send request to an image * bind page information within the request param */ ChartsmithTracker.send = function() { /* * Send Track function (by send image with Get param) as soon as page load */ sendTrackData(); var temp_cookie = docCookies.getItem('_chartsmith_t') || ''; var perm_cookie = docCookies.getItem('_chartsmith_p') || ''; /* * Process tracking identity */ var newScript = document.createElement('script'), firstScript = document.getElementsByTagName('script')[0]; newScript.async = 1; var newScriptUrl = 'https://www.oneday.com.ph/ti/?q=66ac1be627c9aeb3fdb00a0a14630052dcdad517aec00a88d4682a19058e9966'; newScriptUrl += newScriptUrl.indexOf('?') > -1 ? '&' : '?'; //Add url newScriptUrl += 'url=' + encodeURIComponent(location.href); var path = location.href; //Add temp cookie and perm cookie params to url newScriptUrl += '&_chartsmith_p=' + perm_cookie; newScriptUrl += '&_chartsmith_t=' + temp_cookie; newScript.src = newScriptUrl; firstScript.parentNode.insertBefore(newScript, firstScript); /* * Get page information */ //Set url var path = location.href; //Set User Agent var useragent = navigator.userAgent; //Send the request when trigger unload event EventUtil.addHandler(window, "beforeunload", function (event) { event = EventUtil.getEvent(event); /* * Store Track data before the web page unlaod, bind the data with window.name */ storeTrackData(); }); /* * Store Track data before the web page unlaod, bind the data with window.name */ function storeTrackData() { /* * Check to see if set cookie * For support anonymous person, permanent cookie dont't require any more */ var temp_cookie = docCookies.getItem('_chartsmith_t') || ''; var perm_cookie = docCookies.getItem('_chartsmith_p') || ''; if(temp_cookie) { //Caculate duration var duration = new Date().getTime() - ChartsmithTracker.clientObj.l; duration = parseInt(duration / 1000, 10); var trackData = ''; trackData += '_chartsmith_p=' + perm_cookie; trackData += '&_chartsmith_t=' + temp_cookie; trackData += '&url='+encodeURIComponent(path); trackData += '&useragent=' + useragent; trackData += '&duration=' + duration; // save trackData to cookie docCookies.setItem('_chartsmith_d', trackData, null, '/'); } } /* * Send Track function (by send image with Get param) */ function sendTrackData() { /* * Check to see if set track data cookie, track data cookie include the information of previous page activity */ var prevTrackData = docCookies.getItem('_chartsmith_d'); if(prevTrackData) { var collect_url = '//www.oneday.com.ph/r/response/core/track/webvisit/?q=66ac1be627c9aeb3fdb00a0a14630052dcdad517aec00a88d4682a19058e9966'; var image = new Image(); image.src = collect_url + '&' + prevTrackData; } } }; /* * Get page statistics */ ChartsmithTracker.pageStats = function() { var param = arguments[0]; if(!param) { console.error("No any arguments"); return false; } if(!param[0]) { console.error("No first argument"); return false; } if(!param[1]) { console.log("No second argument"); return false; } var item = param[0]; var callback = param[1]; var url = "//www.oneday.com.ph/r/response/core/track/pageAPI/?q=66ac1be627c9aeb3fdb00a0a14630052dcdad517aec00a88d4682a19058e9966"; url += '&item=' + item; url += '&url=' + encodeURIComponent(location.href); //define the callback function //the function will be executed after page stats script loaded var Chartsmith = ChartsmithTracker.clientObj; Chartsmith.pageStats = Chartsmith.pageStats || {}; Chartsmith.pageStats[item] = Chartsmith.pageStats[item] || {}; Chartsmith.pageStats[item].callback = function(response) { if(response.num) { Chartsmith.pageStats[item].data = response; callback(response); } else { Chartsmith.pageStats[item].data = false; callback(false); } }; DomUtil.addScript(url, "ChartsmithTracker.clientObj.pageStats."+ item +".callback"); }; /* * Execute client request */ ChartsmithTracker.execute = function() { if(typeof window.ChartsmithTrackerObj != 'undefined') { var clientObj = eval(window.ChartsmithTrackerObj); ChartsmithTracker.clientObj = clientObj; for(var i=0,len=clientObj.q.length;i0) func_args.push(clientObj.q[i][j]); } if(typeof ChartsmithTracker[func_name] != 'undefined') ChartsmithTracker[func_name](func_args); } } } ChartsmithTracker.execute();