Martijn Geerts Posted October 1, 2013 Share Posted October 1, 2013 Is there a possibility to deliver a page From ProCache, but update a 'view count field' inside the requested Page. Link to comment Share on other sites More sharing options...
Soma Posted October 1, 2013 Share Posted October 1, 2013 Only through JS. 2 Link to comment Share on other sites More sharing options...
apeisa Posted October 1, 2013 Share Posted October 1, 2013 I just (like 5 mins ago) implemented "Most Viewed Pages" widget for a client. I used Wanzes excellent ProcessGoogleAnalytics module and it was easy enough pull data when it was first setup. It might be that this is not a fit for your project Martijn (if you need the data for selectors for example), but this is how I did it: $pga = wire('modules')->get("ProcessGoogleAnalytics"); $ga = new GoogleAnalyticsAPI(); $ga->auth->setClientId($pga->clientId); $ga->auth->setClientSecret($pga->clientSecret); $ga->auth->setRedirectUri($pga->page->httpUrl); $ga->setAccessToken($pga->accessToken); $ga->setAccountId($pga->accountId); $defaults = array( 'start-date' => date('Y-m-d', strtotime('-1 month')), 'end-date' => date('Y-m-d'), ); $ga->setDefaultQueryParams($defaults); $params = array( 'metrics' => 'ga:pageviews', 'dimensions' => 'ga:pagePath', 'sort' => '-ga:pageviews', 'max-results' => 11, ); $visits = $ga->query($params); $out = "<h2>Most read articles</h2><ul>"; foreach($visits['rows'] as $row) { if ($row[0] == "/") continue; // Skip the homepage, should be on top 10 always, if not, then 11 articles is shown $p = $this->pages->get($row[0]); if ( ! $p->id ) continue; // For some reason page is not found anymore... $out .= "<li><a href='$p->url'>$p->title</a></li>"; } $out .= "</ul>"; 8 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 1, 2013 Author Share Posted October 1, 2013 tnx apeisa, interresting ! I gonna marinate this a little. As my needs are indeed a little different. Think I gonna use abuse WebPageServices module cause I want to use it for other items to. Thank you guys for resetting my brain. 1 Link to comment Share on other sites More sharing options...
ryan Posted October 5, 2013 Share Posted October 5, 2013 If using ProCache, it would be kind of defeating some of the benefit of it if you are still loading ProcessWire for every request to update a view counter. I'd think you might be better off using an external service like Google Analytics to keep track of this for you. It already does this if you are using it, but of course that's not data you can easily pull back in to sort pages, etc. (as far as I know) 1 Link to comment Share on other sites More sharing options...
diogo Posted October 5, 2013 Share Posted October 5, 2013 I'd think you might be better off using an external service like Google Analytics to keep track of this for you. It already does this if you are using it, but of course that's not data you can easily pull back in to sort pages, etc. (as far as I know) I'm sure you can, using their API https://developers.google.com/analytics/devguides/reporting/core/v3/ 3 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 5, 2013 Author Share Posted October 5, 2013 Makes sense what Ryan said & Diogo finished the how to do. Thank You very much ! Link to comment Share on other sites More sharing options...
Pierre-Luc Posted April 15, 2014 Share Posted April 15, 2014 This might be a dead topic, but I'm looking at doing an implementation using Google Analytics (GA) API to do that on a website that has caching (and don't want to create too much custom cache code that I'll have to maintain afterwards), using a cron job. I looked at the documentation, and tried a few things with GA's Query Explorer : http://ga-dev-tools.appspot.com/explorer/ https://www.googleapis.com/analytics/v3/data/ga?ids=ga:YOUR_GA_ID // Set your request metrics here &metrics=ga:visits,ga:pageviews // Set a filter for your page, you can combine multiple paths into one request using commas (OR operator) and multiple pagePath values &filters=ga:pagePath=~/event/x/,ga:pagePath=~/en/events/x/ // start-date cannot go before 2005-01-01 (GA launch date) and end-date should be set to today &start-date=2005-01-01&end-date=2014-04-15 This will return json data that you can then insert into a field. All in all, it seems easy: Setup a script that will parse all pages, get multiple values, create a GA Api query, get values, update database fields. Note that there are limits and quotas to the API. For what I need it, it's not a problem, but you might need to reach support to get more info. Hope this helps some of you. 2 Link to comment Share on other sites More sharing options...
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