$metric = "NewUsers?"; $url = $url_root . $metric . $api_accesscode . $api_key . $row['apikey'] . $start . $end; debugger("URL : {$url}"); $json_new = get_json($url); sleep(2); $metric = "Sessions?"; $url = $url_root . $metric . $api_accesscode . $api_key . $row['apikey'] . $start . $end; debugger("URL : {$url}"); $json_session = get_json($url); sleep(2); debugger("JSON Active : " . print_r($json_active, TRUE)); debugger("JSON Install : " . print_r($json_new, TRUE)); debugger("JSON Session : " . print_r($json_session, TRUE)); add_value($fh, $json_active, $row['game_id'], $row['device_id']); add_value($fh, $json_new, $row['game_id'], $row['device_id']); add_value($fh, $json_session, $row['game_id'], $row['device_id']); } fclose($fh); function debugger($msg) { global $debug; if ($debug) { $debug->log($msg, PEAR_LOG_DEBUG); } } function add_value($fh, $metric, $game_id, $device_id) { if ($metric['day']['@value'] == 0) { return; } $record = "{$game_id},{$device_id},'" . date("Y-m-d H:i:s") . "','" . $metric['@metric'] . "'," . $metric['day']['@value'] . "\n";
debugger("URL : {$url}"); $json_avg = get_json($url); sleep(1); $metric = "RetainedUsers?"; $url = $url_root . $metric . $api_accesscode . $row['apicode'] . $api_key . $row['apikey'] . $start . $end; debugger("URL : {$url}"); $json_retained = get_json($url); sleep(1); add_value($fh, $json_active, $row['game_id'], $row['device_id']); add_value($fh, $json_new, $row['game_id'], $row['device_id']); add_value($fh, $json_session, $row['game_id'], $row['device_id']); add_value($fh, $json_week, $row['game_id'], $row['device_id']); add_value($fh, $json_month, $row['game_id'], $row['device_id']); add_value($fh, $json_median, $row['game_id'], $row['device_id']); add_value($fh, $json_avg, $row['game_id'], $row['device_id']); add_value($fh, $json_retained, $row['game_id'], $row['device_id']); } fclose($fh); mysqli_close($db); function add_value($fh, $metric, $game_id, $device_id) { if (is_array($metric['day']) && array_key_exists('@value', $metric['day'])) { $record = "{$game_id},{$device_id},'" . $metric['day']['@date'] . "','" . $metric['@metric'] . "'," . $metric['day']['@value'] . "\n"; $rc = fwrite($fh, $record); } else { $day = array(); $day = $metric['day']; foreach ($day as $key => $value) { $record = "{$game_id},{$device_id},'" . $value['@date'] . "','" . $metric['@metric'] . "'," . $value['@value'] . "\n"; $rc = fwrite($fh, $record); }