Commit d9aedb66 authored by Mahmoud Aglan's avatar Mahmoud Aglan

feat(analytics): every day a player opens the app, for the manager

player_daily_activity (one row per player per Cairo day: first and last
seen, time in the app, platform) is written by the presence pulse the app
already sends, inside el3ab_social_pulse (no extra call); the app now sends
its platform (android, ios, web). Backfilled from the games, coins and
messages already on record. manager_insights(p_days) computes the
dashboard's numbers in one call. Service role only.
Co-Authored-By: 's avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 7267057e
......@@ -160,7 +160,8 @@ if ($method === 'POST') {
if ($action === 'pulse') {
$game = in_array($input['game'] ?? null, SOCIAL_GAMES, true) ? $input['game'] : null;
$online = ($input['online'] ?? true) !== false;
$res = supabaseRpc('el3ab_social_pulse', ['p_uid' => $userId, 'p_game' => $game, 'p_online' => $online]);
$platform = in_array($input['platform'] ?? null, ['android', 'ios', 'web'], true) ? $input['platform'] : null;
$res = supabaseRpc('el3ab_social_pulse', ['p_uid' => $userId, 'p_game' => $game, 'p_online' => $online, 'p_platform' => $platform]);
if (!is_array($res) || isset($res['code']) || isset($res['message'])) jsonError('pulse failed', 502);
$dm = (array)($res['dm'] ?? []);
$groups = (array)($res['groups'] ?? []);
......
This diff is collapsed.
......@@ -64,7 +64,7 @@ async function pulse() {
if (inFlight) return inFlight;
inFlight = (async () => {
try {
const res = await net.post('social.php', { action: 'pulse', game: currentGame() });
const res = await net.post('social.php', { action: 'pulse', game: currentGame(), platform: platformName() });
if (!res || res.error) return null;
apply(res);
openPendingLink();
......@@ -137,3 +137,9 @@ async function openPendingLink() {
toast(t('social.link_broken'), { type: 'error' });
}
}
/** Where the app runs, for the manager's analytics: the store app (android / ios) or the web. */
function platformName() {
if (!(window.IS_NATIVE_APP || window.flutter_bridge)) return 'web';
return /iphone|ipad|ipod|ios/i.test(navigator.userAgent || '') ? 'ios' : 'android';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment