Tak jak w temacie nie wiem gdzie mam wkleić kod. Wklejam instrukcję:
This widget is designed to work in your website directly. This widget makes it easy to use Piwik to automatically display the list of Top Keywords, for each of your website Page URLs.
Example API URL - For example if you would like to get the top 10 keywords, used last week, to land on the page http://lalu.sklep.pl, in format JSON: you would dynamically fetch the data using this API request URL. Make sure you encode the 'url' parameter in the URL.
PHP Function ready to use! - If you use PHP on your website, we have prepared a small code snippet that you can copy paste in your Website PHP files. You can then simply call the function
DisplayTopKeywords();
anywhere in your template, at the bottom of the content or in your blog sidebar. If you run this code in your page http://lalu.sklep.pl, it would output the following:
Here is the PHP function that you can paste in your pages:
<?php
// 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 = "http://piwik.linuxpl.com/?module=API&method=Referers.getKeywordsForPageUrl&format=php&filter_limit=10&token_auth=b209d48844bf8765c0273803cbbc8f12&date=previous1&period=week&idSite=6768&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 <a href='$api'>Top Keywords from Piwik</a>";
return;
}
// Display the list in HTML
$url = htmlspecialchars($url, ENT_QUOTES);
$output = "<h2>Top Keywords for <a href='$url'>$url</a></h2><ul>";
foreach($keywords as $keyword) {
$output .= "<li>". $keyword[0]. "</li>";
}
if(empty($keywords)) { $output .= "Nothing yet..."; }
$output .= "</ul>";
echo $output;
}
DisplayTopKeywords();
Notes: You can for example edit the code to to make the Top search keywords link to your Website search result pages. On medium to large traffic websites, we recommend to cache this data, as to minimize the performance impact of calling the Piwik API on each page view.
Question
tome
Tak jak w temacie nie wiem gdzie mam wkleić kod. Wklejam instrukcję:
This widget is designed to work in your website directly. This widget makes it easy to use Piwik to automatically display the list of Top Keywords, for each of your website Page URLs.
Example API URL - For example if you would like to get the top 10 keywords, used last week, to land on the page http://lalu.sklep.pl, in format JSON: you would dynamically fetch the data using this API request URL. Make sure you encode the 'url' parameter in the URL.
PHP Function ready to use! - If you use PHP on your website, we have prepared a small code snippet that you can copy paste in your Website PHP files. You can then simply call the function
anywhere in your template, at the bottom of the content or in your blog sidebar. If you run this code in your page http://lalu.sklep.pl, it would output the following:
Here is the PHP function that you can paste in your pages:
Notes: You can for example edit the code to to make the Top search keywords link to your Website search result pages.
On medium to large traffic websites, we recommend to cache this data, as to minimize the performance impact of calling the Piwik API on each page view.
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now