create a logging system using a js client and Nodejs API
- Javascript client example:
/**
* user vars
*/
var logClient = "demo-domain.com"; // set client name
var logToken = "123demo123"; // account token
var debug = false; // client debug (true / false)
/**
* system vars
*/
var logIp ="62.131.237.149"; // ip
var logEndPoint = logIp+"/iplog-api/index.php/site/traceip/html"; // path
var logVersion = '1.0.0'; // version
var url = window.location.href; // get the uri
var userAgent = navigator.userAgent; // get useragent
var d = new Date(); // build date obj
var dayOfMonth = d.getDate(); // day of the month
var month = d.getMonth()+1; // month range from 0 to 11
var year = d.getFullYear(); // year
var date = year+"-"+month+"-"+dayOfMonth; // set date format
var hours = d.getHours(); // hours
var minutes = d.getMinutes(); // minutes
var seconds = d.getSeconds(); // seconds
var time = hours+":"+minutes+":"+seconds; // set time format
var logJson;
var logData;
var callback;
var marketingTag = "custom (marketing) TAG";
/**
* Debug
*/
if(debug){
console.log("trying to connect on"+logEndPoint);
callback = console.log('data succesfully send to the api!');
}
/**
* Format the JSON
*/
function formatLogData(marketingTag){
logJson = JSON.stringify(
{
'client' : logClient,
'version' : logVersion,
'url' : url,
'date' : date,
'time' : time,
'userAgent' : userAgent,
'ip' : '',
'tag' : marketingTag
}
);
logData = btoa(logJson);
}
/**
* Send log data
*/
function sendLogData(){
$.ajax({
url: "http://"+logEndPoint+"/"+logData,
type: "GET",
//data: logData, //only used with post
contentType: "application/json",
complete: callback
});
}
formatLogData(marketingTag);
sendLogData();
The API is running on the pi cluster.
Feel like testing, please contact me.