Files
justice/www/html/player-log-track.js
T

47 lines
1.5 KiB
JavaScript

/**
* บันทึกกิจกรรมผู้เล่น → Admin/api/player-log.php
* ใช้: jdTrackPlayerLog('lobby_enter', { roomId: '...' })
*/
(function (global) {
'use strict';
function apiUrl() {
return typeof global.appPath === 'function'
? global.appPath('/Admin/api/player-log.php')
: '/Admin/api/player-log.php';
}
function readLs(key) {
try { return global.localStorage.getItem(key) || ''; } catch (e) { return ''; }
}
global.jdTrackPlayerLog = function jdTrackPlayerLog(event, meta) {
if (!event) return;
var playerKey = readLs('jdPlayerKey');
if (!playerKey || playerKey.length < 8) return;
var body = {
action: 'track',
playerKey: playerKey,
event: String(event),
displayName: readLs('roomLobbyDisplayName') || readLs('playerName') || '',
loginType: readLs('loginType') || 'guest',
page: (global.location && global.location.pathname) ? global.location.pathname : '',
meta: meta && typeof meta === 'object' ? meta : {},
};
try {
if (typeof global.fetch === 'function') {
global.fetch(apiUrl(), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'omit',
keepalive: true,
body: JSON.stringify(body),
}).catch(function () { /* ignore */ });
return;
}
} catch (e) { /* ignore */ }
};
})(typeof window !== 'undefined' ? window : this);