Reputation: 909
I'm looking to get a lit of top three visited urls from a website within a specific sub-directory. For example, top three URLs from http://www.website.com/news/ (while all the pages on http://www.website.com are being tracked).
It'd be amazing if the API could return clean urls (such as, without referral tracking like utm_source=campaign).
I'm looking to get it returned with JSON.
Upvotes: 1
Views: 533
Reputation: 909
OK, so at this time there is no way to accurately get a list of top urls based on metrics. This is because they are broken down based on '/' character into categories and no actual URL strings are being recorded anywhere convenient.
A good way to do this is to define a custom variable and push the browser URL there:
_paq.push(['setCustomVariable', 1,'url', window.location.href, 'visit']);
You can also clean that URL from campaign values using the following JavaScript function
removeURLCampaigns: function(search){
if(search.indexOf('&') > -1){
search = search.split('&').filter(function(v) {
return !/^utm_/.test(v);
}).join('&');
}
if(search.indexOf('?') > -1){
search = search.split('?').filter(function(v) {
return !/^utm_/.test(v);
}).join('?');
}
return search;
}
You can then use Piwik API call with CustomVariables.getCustomVariablesValuesFromNameId, sort by filter_sort_column=sum_daily_nb_uniq_visitors (daily unique visitors) and make sure that your order is descending: filter_sort_order=desc. You can also limit your results: filter_limit=1
Upvotes: 1