Article statistics showing 0 abstract views and 0 PDF downloads

I am using OJS 3.0.1 .

I have pasted these codes in the my themes template /public_html/templates/frontend/objects/article_details.tpl
and the issue_toc.tpl

First I had copied in the article.tpl in the front end folder. But still it showed 0 and also now its showing 0.

Also My usage stats files (UsageStatsLoader.inc, UsageStatsPlugin.inc, UsageStatsReportPlugin.inc) are showing errors on line 16, 17 and 17 respectively.

The line 16, 17 and 17 in all files shows this error : “Call to undefined function import() in /home/u796555399/public_html/plugins/generic/usageStats/UsageStatsLoader.inc.php on line 16”

The line reads as import(‘lib.pkp.plugins.generic.usageStats.PKPUsageStatsLoader’);

I have also ran

{translate key=“article.abstract”} viewed = {$article->getViews()} times
{if $galleys}
{foreach from=$galleys item=galley name=galleyList}
{$galley->getGalleyLabel()} | {$galley->getViews()} | times
{/foreach}
{if is_a($article, ‘PublishedArticle’)}{assign var=galleys value=$article->getGalleys()}{/if}
{/foreach}

{/if}

I have also tried using crons (for scheduling ), but it showed 404 error.

Please do let me know where I am going wrong

Hi @varshilmehta

The code changed in OJS 3.0.1, so it cannot be used as it is. You will have to change the function getViews in classes/article/ArticleGalley.inc.php to be like this:

function getViews() {
$application = PKPApplication::getApplication();
if (!$this->getRemoteURL()) {
return $application->getPrimaryMetricByAssoc(ASSOC_TYPE_SUBMISSION_FILE, $this->getFileId());
} else {
return 0;
}
}

Furthermore, there is currently no getViews function for articles. If you want to use it, you will have to add the following function to your classes/article/Article.inc.php:

function getViews() {
$application = PKPApplication::getApplication();
return $application->getPrimaryMetricByAssoc(ASSOC_TYPE_SUBMISSION, $this->getId());
}

Also, you do not need the line {if is_a($article, 'PublishedArticle')}... in article_details.tpl, so there it should be something like:

{translate key=“article.abstract”} viewed = {$article->getViews()} times
{if $galleys}
{foreach from=$galleys item=galley name=galleyList}
{$galley->getGalleyLabel()} | {$galley->getViews()} | times
{/foreach}
{/if}

In issue_toc.tpl (or article_summary.tpl) you would maybe need that line, but not at that place, but rather something like this:

{if is_a($article, ‘PublishedArticle’)}{assign var=galleys value=$article->getGalleys()}{/if}
{if $galleys}
{foreach from=$galleys item=galley name=galleyList}
{$galley->getGalleyLabel()} | {$galley->getViews()} | times
{/foreach}
{/if}

You can insert that on this place in the issue_toc.tpl: https://github.com/pkp/ojs/blob/master/templates/frontend/objects/issue_toc.tpl#L92 i.e. directly after {include... and in that articles foreach loop. Or for example on this line in article_summary.tpl: https://github.com/pkp/ojs/blob/master/templates/frontend/objects/article_summary.tpl#L70.

I do not understand the error you mentioned, but maybe it will be solved when you change/apply all this…

Best,
Bozana

Thanks a lot. The download counter started working, however the abstract view is yet sowing 0. I have added the code in the Article.inc.php and changed the code in ArticleGalley.inc.php.

Anything else what is supposed to be done?

Hmmm… I don’t know why is this so now @varshilmehta :-
It seems that something is broken, because your article pages don’t display fully – maybe some syntax error or…

I was working on the page. Now its fine. Could you please recheck. Thanks a lot bro

Ah, OK, yes, now it is working, but I still don’t know why is the abstract view always 0 :frowning:
Do you have any entries with assoc_type = 1048585 in your DB table metrics?

Yes, I do have that assoc_type in my db

Hmm… I do not know why is it then 0 :frowning:
But I’ve just seen, that there is the getViews function in classes/artiche/PublishedArticle.inc.php. Thus, you do not have to insert it into the Article.inc.php. You can remove it again. Sorry! :frowning:

Hmm ok. I have deleted it.

Sorry @varshilmehta, one more thing: I think it is better to correct the function in ArticleGalleys.inc.php like this: pkp/pkp-lib#2167 fix assoc type in getViews for article galleys · pkp/ojs@32c6678 · GitHub
I.e. to ask if ($fileId) instead of if ($this->getRemoteURL()) because it could happen, that also not remote galleys have no files…
Sorry!

Done! But now the site isnt working. Will have to revert back to your old code

Have you also add the line before:

$fileId = $this->getFileId();

Because it should work… :-\

Yes, i had added that too. I dont know whats wrong. I can gv u details also to log in my server and do the changes. I dont know if i did something wrong or what.

@varshilmehta, do you have access to your server’s PHP error log? In cases where you have a blank white screen or a partially loaded page, you webserver should log useful messages about any PHP Fatal errors.

Nope… Unfortunately not.

An alternate approach would be to turn on error_reporting and show_stacktrace in config.inc.php, but this will potentially clutter the display of a production site.

Can you contact your hosting provider or system administrator for access to, or copies of, the error logs?

Greetings,

Implement total views in OJS3 is really good idea, because from statistics charts seen only statistics for this year.

ok, i have the logs. What should i do now? Let me know

I have only 4 files on log folder

Look in the php_error.log for a “PHP Fatal” message that corresponds with the date and time when you accessed the view and it showed up as a blank or truncated page.