OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



How to show the view times to the visitors?

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

Re: How to show the view times to the visitors?

Postby asmecher » Wed Jan 15, 2014 9:12 am

Hi Garant,

The implementation of the getGalleysCountNum function shown above will need to be changed; it references the now-obsolete column.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8470
Joined: Wed Aug 10, 2005 12:56 pm

Re: How to show the view times to the visitors?

Postby mikimos » Thu Jan 23, 2014 1:24 am

Hi Alec,
we too are using 2.4.3 version: is there any possibility to get some instructions on how to implement this feature? We absolutely need to show number of views and PDF downolads for our articles as soon as possible.
Thank you in advance.
mikimos
 
Posts: 14
Joined: Tue Dec 23, 2008 3:17 am

Re: How to show the view times to the visitors?

Postby mikimos » Thu Jan 23, 2014 2:09 am

...for PAGEPress journals (www.pagepress.org)
:)
mikimos
 
Posts: 14
Joined: Tue Dec 23, 2008 3:17 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Thu Jan 23, 2014 1:10 pm

Hi guys,

What you can do is still use the method getViews() that Galleys still implement to show the number of downloads/views. Just instantiate the Galley you want to know the stats and call getViews(). The result is an integer and you can use it directly into template.

Note that the metric type used to get statistics will be the journal default one, which is the new OJS COUNTER metric type. Because the way we count is different from the previous ways (COUNTER plugin, timed view, and view columns) we can't merge the stats. So don't be surprised to see low counts for galleys that you knew had much more downloads, for example. The numbers will represent the usage since the upgrade day until now.

But, if you really need to show the old COUNTER stats mixed with the new ones, you have two options:

1 - process the old log files that you might have to bring as much as possible statistics into the new OJS COUNTER metric type. Although it might not be the complete set of statistics that you had previously because you may not have the entire log files to process, this is the only possible correct one, because it will give a chance for the code to process the logs and to produce statistics that are aligned with what the metric type represents;

2 - THIS IS NOT CONCEPTUALLY CORRECT, but made possible to let users still present old statistics while showing the new ones too. Use it with care. If you use it, you cannot say that your journal presents only OJS COUNTER statistics anymore. It will be a mix of the new OJS COUNTER metric type and the old one. To do this you can tell the system to merge two metric type statistics results directly using the metrics DAO to get merged stats (from ojs::counter and ojs::legacyCounterPlugin metric types) when retrieving stats for the galley objects. It should be something like this:

Code: Select all
$stats = $metricsDao->getMetrics(
    array(OJS_METRIC_TYPE_LEGACY_DEFAULT, OJS_METRIC_TYPE_COUNTER),
    array(STATISTICS_DIMENSION_ASSOC_ID),
    array(STATISTICS_DIMENSION_SUBMISSION_ID => $submissionId, STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_GALLEY),
    array(),
    null,
    false
);


This will return an array with all article galleys stats. Each array value will be another array, containing stats data for one article galley. This array will have items with columns that you asked for as keys and the result as values. In the case above, we will have the object id (that we asked for) and the metrics column (that's always there to show the stats). So it should be like this the access to the stats:

Code: Select all
foreach ($stats as $record) {
    $articleGalleyViews[$record[STATISTICS_DIMENSION_ASSOC_ID]] = $stats[STATISTICS_METRIC];
}


Of course that you can ask for each galley stat at a time, but this would require more database access. If your objective is to show each stats per each galley, the way described will access the database only once. Specially with the metrics table, that can get really large, this should be better.
bbeghelli
 
Posts: 104
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Thu Jan 23, 2014 1:26 pm

HI bbeghelli!
Does it mean, that using inside the article's template this code:
Code: Select all
$article->getViews($article->getId())

will show the true/new view counts which were introduced in 2.4.3 version?

I've just tested it with new issue which was published after the upgrade.
What is interesting the view counts in Editing->layout->views are "11".
But opening this article as a reader (in normal view) with provided code gives the "22" views as the result...
Something is wrong?
Thank you!
Garant
 
Posts: 212
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Thu Jan 23, 2014 2:55 pm

Hi Garant,

The getViews() method is only available to galleys. Article and other objects doesn't have this interface. The getViews() method is an old interface that I didn't wanted to remove for compatibility purposes. But now the correct method of getting statistics for any object is to use the interface presented in Application class, getMetrics().

I am not sure how your code is working, the Article object, as I said, has no interface to retrieve statistics.

For OJS 3.0 all published objects will have the same interface to retrieve stats, getMetrics(). I didn't expected the need to implement that on OJS 2.4.3, as I thought the old getViews() were enough.

Are you sure this is the code that is running?
bbeghelli
 
Posts: 104
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Thu Jan 23, 2014 11:59 pm

Hi bbeghelli!
As I said before I've placed this code:
Code: Select all
$article->getViews($article->getId())

inside the template and it does work, but incorrectly - shows wrong numbers.
So I've removed it completely.
Sorry I don't understand, so there is no any possibility to show correct statistics with new getMetrics() function?

Just some thoughts: such thing should be implemented by default in the system. It's must have feature. IMHO
Garant
 
Posts: 212
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Fri Jan 24, 2014 5:33 am

Hi Garant,

Can you post more code, especially how you retrieve the article object?

There is no lack of feature. To solve the old stats problem you have two options: the correct one, reprocessing log files using the new way of counting views OR using the getMetrics() to merge the old and new stats, which is conceptually wrong but maybe the only way for some users, due to a lack of access log files.

Cheers,
Bruno
bbeghelli
 
Posts: 104
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Fri Jan 24, 2014 6:47 am

Hi!
I've just placed this code:
Code: Select all
<strong>{$article->getViews($article->getId())} {translate key="plugins.block.popularArticles.views"}</strong><br />

inside the article.tpl
But now it's removed
That's all
Garant
 
Posts: 212
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Fri Jan 24, 2014 3:49 pm

Hi Garant,

My bad. The getViews() method is available to articles too, but only for published articles, which makes sense. Sorry for this. :)

The difference in numbers that you saw are correct. The article geViews() method will return statistics associated with the article object only. This not includes galleys. So, the number that you see (22) is the number of times the article main page (abstract) was visited. Please, take a look on this table: http://pkp.sfu.ca/wiki/index.php?title= ... ject_Types

To get the total number of article galley downloads and views without having to instantiate each article galley and ask for views separately you should do this:

Code: Select all
$application =& PKPApplication::getApplication();
$stats = $application->getMetrics(
    OJS_METRIC_TYPE_COUNTER,
    null,
    array(STATISTICS_DIMENSION_SUBMISSION_ID => $submissionId, STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_GALLEY)
);
$articleGalleysViewsAndDownloads = $stats[STATISTICS_METRIC];


Note that this solution will not provide the merged statistics discussed previously. The metric type that we ask for is just the OJS_METRIC_TYPE_COUNTER one. If you want to merge the old and new counter metric types, you have to use the code that I've posted to you previously, removing the column parameter so you can get the galley stats aggregated at article level.
bbeghelli
 
Posts: 104
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Sat Jan 25, 2014 12:22 am

Hi bbeghelli!
That's getting more clearer for me now :D
Here left one question: how to show this calculation inside article's template?
I've placed all your provided code in article.tpl, placed each string in smarties {} brackets like this:
Code: Select all
{$application =& PKPApplication::getApplication();}
{$stats = $application->getMetrics(
    OJS_METRIC_TYPE_COUNTER,
    null,
    array(STATISTICS_DIMENSION_SUBMISSION_ID => $submissionId, STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_GALLEY)
);}
{$articleGalleysViewsAndDownloads = $stats[STATISTICS_METRIC];}
<strong>{echo $articleGalleysViewsAndDownloads} {translate key="plugins.block.popularArticles.views"}</strong><br />

But as I understood is not right :)
Could you guide me a bit?
Thank you!
Garant
 
Posts: 212
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Sat Jan 25, 2014 1:47 pm

Hi Garant,

This code can't be executed inside the tpl file. It's a thing that goes inside the controller. If I am not wrong, look the ArticleHandler class, the view() method. You will have to do this calculation there and assign the result as a smarty variable, like this:

Code: Select all
$templateMgr->assign('articleGalleysViewsAndDowloads', $articleGalleysViewsAndDowloads);


Cheers,
Bruno
bbeghelli
 
Posts: 104
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Sun Jan 26, 2014 1:06 am

Hi Bruno!
Thank you for you reply!
I've tried you solution: I've placed provided code in view() function, so it looked like::
Code: Select all
...
$application =& PKPApplication::getApplication();
$stats = $application->getMetrics(
    OJS_METRIC_TYPE_COUNTER,
    null,
    array(STATISTICS_DIMENSION_SUBMISSION_ID => $submissionId, STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_GALLEY)
);
$articleGalleysViewsAndDownloads = $stats[STATISTICS_METRIC];
      // consider public identifiers
      $pubIdPlugins =& PluginRegistry::loadCategory('pubIds', true);
      $templateMgr->assign('pubIdPlugins', $pubIdPlugins);
      $templateMgr->display('article/article.tpl');


$templateMgr->assign('articleGalleysViewsAndDowloads', $articleGalleysViewsAndDowloads);
      // consider public identifiers
      $pubIdPlugins =& PluginRegistry::loadCategory('pubIds', true);
      $templateMgr->assign('pubIdPlugins', $pubIdPlugins);
      $templateMgr->display('article/article.tpl');

but it gives an error:
Code: Select all
DB Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND assoc_type = 260 AND metric_type = 'ojs::counter' LIMIT 5000' at line 1
Garant
 
Posts: 212
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Sun Jan 26, 2014 12:21 pm

Hi Garant,

I don't think you have the $submissionId variable defined.

Cheers,
Bruno
bbeghelli
 
Posts: 104
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Sun Jan 26, 2014 1:01 pm

HI Bruno!
As I understood the
Code: Select all
$submissionId=getSubmissionId();
trick won't work before the provided code.
It shows the blank screen and I can't debug further. the print_r call doesn't show anything. So it's impossible for me to debug...
Garant
 
Posts: 212
Joined: Wed May 30, 2012 8:53 am

PreviousNext

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest