var clientip = ''; $.getScript('/app/vendor/js-cookie/src/js.cookie.js', function() { do_tracking(); }); function do_tracking(){ $.get("//api.ipify.org?format=json", function(response) { clientip = response.ip; //console.log("clientip1: " + clientip); viewFunction(); $("input[type='submit']").click(function () { clickFunction(this); }); $("input[value='submit']").click(function () { clickFunction(this); }); $( "a" ).click(function() { clickFunction(this); }); $( "button" ).click(function() { clickFunction(this); }); }); } function viewFunction() { //console.log('submit'); $.post({ url: "/manage/track/create", data: { action: 'view', ip: clientip, url: $(location).attr('href'), ref: document.referrer, mobile: '0', mobile_grade: 'C', test: '', ReaderID: Cookies.get('ReaderID'), ClassID: Cookies.get('ClassID'), ReadathonID: Cookies.get('ReadathonID'), AdvertiserID: Cookies.get('AdvertiserID'), PHPSESSID: Cookies.get('PHPSESSID') }, success:function(e) { //console.log(e); } }); } function clickFunction(x) { var html = $(x).html(); if(html == '') { html = $(x)[0].outerHTML; } $.post({ url: "/manage/track/create", data: { action: 'click', ip: clientip, html: html, url: $(location).attr('href'), ref: document.referrer, mobile: '', mobile_grade: 'C', test: '', ReaderID: Cookies.get('ReaderID'), ClassID: Cookies.get('ClassID'), ReadathonID: Cookies.get('ReadathonID'), AdvertiserID: Cookies.get('AdvertiserID'), PHPSESSID: Cookies.get('PHPSESSID') } }); }