| 1 | <?php |
| 2 | require_once("./JSON.php"); |
| 3 | |
| 4 | $filename = "./logs/analytics.log"; |
| 5 | $json = new Services_JSON; |
| 6 | |
| 7 | $id = $_REQUEST["id"]; |
| 8 | $items = $json->decode($_REQUEST["data"]); |
| 9 | |
| 10 | if (!$handle = fopen($filename, 'a+')) { |
| 11 | print '{error: "server error"}'; |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | foreach($items as $i=>$item){ |
| 16 | $item->_analyticsId = $id; |
| 17 | $item->_analyticsTimeStamp = time(); |
| 18 | $log = $json->encode($item) . "\n"; |
| 19 | fwrite($handle, $log); |
| 20 | } |
| 21 | |
| 22 | fclose($handle); |
| 23 | |
| 24 | $response = '{"eventsReceived": "' . sizeof($items) . '", "id": "' . htmlentities($id) . '"}'; |
| 25 | if ($_REQUEST["callback"]){ |
| 26 | print htmlentities($_REQUEST["callback"]) . "(" . $response . ");"; |
| 27 | }else{ |
| 28 | print $response; |
| 29 | } |
| 30 | |
| 31 | ?> |