Skip to content

Instantly share code, notes, and snippets.

@leoriviera
Last active August 1, 2018 21:06
Show Gist options
  • Save leoriviera/d2e4b1b895ff484056e55676d421cde1 to your computer and use it in GitHub Desktop.
Save leoriviera/d2e4b1b895ff484056e55676d421cde1 to your computer and use it in GitHub Desktop.
// A JS file that uses Firebase, moment.js, l1.io and js_cookie to track time of access and IP address
// Dependencies include
// - https://cdn.rawgit.com/moment/moment/develop/min/moment.min.js
// - https://www.gstatic.com/firebasejs/4.1.3/firebase.js
// - https://l2.io/ip.js?var=userip
// Insert Firebase configuration data here!
firebase.initializeApp(config);
database = firebase.database();
window.onload = function(){
var databaseRef1 = database.ref('/totalcount/viewcount/');
databaseRef1.once('value', function(snapshot){
var viewnumber = snapshot.val();
if(viewnumber == null){
viewnumber = 1
} else {
viewnumber++;
}
var databaseRef2 = database.ref('/totalcount/');
databaseRef2.set({
viewcount: viewnumber
})
});
var databaseRef3 = database.ref('/datetime/').push();
var timenow = moment().format('MMMM Do YYYY, h:mm:ss a');
databaseRef3.set({
datetime: timenow,
ipaddress: userip
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment