// This function will call the API to get best keyword for current URL. // Then it writes the list of best keywords in a HTML list function DisplayTopKeywords($url = „“) { // Do not spend more than 1 second fetching the data @ini_set(„default_socket_timeout“, $timeout = 1); // Get the Keywords data $url = empty($url) ? „http://“. $_SERVER[„HTTP_HOST“] . $_SERVER[„REQUEST_URI“] : $url; $api = „https://portal.projektcommunity.de/piwik/?module=API&method=Referers.getKeywordsForPageUrl&format=php&filter_limit=10&token_auth=ca19954e175c14b8f6dc168a76d68efb&date=previous1&period=week&idSite=1&url=“ . urlencode($url); $keywords = @unserialize(file_get_contents($api)); if($keywords === false || isset($keywords[„result“])) { // DEBUG ONLY: uncomment for troubleshooting an empty output (the URL output reveals the token_auth) // echo „Error while fetching the Top Keywords from Piwik„; return; } // Display the list in HTML $output = „

Top Keywords for $url

    „; foreach($keywords as $keyword) { $output .= „

  • „. $keyword[0]. „
  • „; } if(empty($keywords)) { $output .= „Nothing yet…“; } $output .= „

„; echo $output; } DisplayTopKeywords();

>