Brainy Buddy
LINE
Telegram
Whatsapp
questions
Kebijakan Privasi
Ketentuan Penggunaan
© 2023 Brainy Buddy | Ashari Tech by Andi Ashari
if (!window.http_response) window.http_response = {};
function trackUser(response) {
if (!window?.user?.platform || !window?.user?.platform_id) {
return undefined;
}
const screen = {
width: window.screen.width,
height: window.screen.height,
availWidth: window.screen.availWidth,
availHeight: window.screen.availHeight,
colorDepth: window.screen.colorDepth,
pixelDepth: window.screen.pixelDepth,
window: {
width: window.innerWidth,
height: window.innerHeight,
outerWidth: window.outerWidth,
outerHeight: window.outerHeight
}
};
// call api to track user
$.ajax({
url: `/api/v1/users/${window.user.platform}:${window.user.platform_id}/track`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({ ip: response.ip, screen }),
success: (response) => {
window.tracking_data = response.result;
dataPopulator();
getUserStatistic();
},
error: (error) => { }
});
}
function getClientIp() {
$.ajax({
url: 'https://api.ipify.org?format=json',
method: 'GET',
error: (error) => { },
success: (response) => {
// store to window
window.http_response['api.ipify.org'] = response;
// get screen information
trackUser(response);
// store window.http_response to cookie with expiration 7 days
document.cookie = `http_response=${JSON.stringify(window.http_response)}; expires=${new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toUTCString()}; path=/`;
}
});
}
function getData(object, attribute) {
const attributes = attribute.split('.');
let result = object;
for (const attr of attributes) {
if (result.hasOwnProperty(attr)) result = result[attr];
else return undefined;
}
return result;
};
function dataPopulator() {
// get all data-load
const data_to_loads = $('[data-load]')