How to display article views and pdf download counts on journal website

Hi there, hope the team is doing well. I want to ask that I want to show the article views and pdf download counts in the similar way as in the below screenshot. please can anyone guide me how to achieve this? it will be really helpful for our journal and I am getting constant queries regarding this requirement.

Hi @Farhan_Abbas

What OJS version are you using?

Best,
Bozana

How can it be done on OJS 3.4.0.5

@bozana OJS 3.3.0.17

Hi @Farhan_Abbas and @Simon_Muchemi ,

For 3.3.0.x:

You would need to implement/copy this function into your classes/submission/Submission.inc.php (or lib/pkp/classes/submission/PKPSubmission.inc.php): ops/classes/submission/Submission.inc.php at stable-3_3_0 · pkp/ops · GitHub
Then you would need to adapt your file templates/frontend/objects/issue_toc.tpl. I do not know how you would need to style it so that it looks like that above (with aye and PDF download icon), but this way you can access the numbers (after this line ojs/templates/frontend/objects/issue_toc.tpl at stable-3_3_0 · pkp/ojs · GitHub):
Abstract Views: {$article->getViews()}
Galley File Downloads: {$article->getTotalGalleyViews()}

For 3.4.0.x:

You would need to implement e.g. this function into your classes/submission/Submission.php (or lib/pkp/classes/submission/PKPSubmission.php):

 public function getDownloads()
    {
        $filters = [
            'dateStart' => StatisticsHelper::STATISTICS_EARLIEST_DATE,
            'dateEnd' => date('Y-m-d', strtotime('yesterday')),
            'contextIds' => [$this->getData('contextId')],
            'submissionIds' => [$this->getId()],
            'assocTypes' => [Application::ASSOC_TYPE_SUBMISSION_FILE],
        ];
        $metrics = Services::get('publicationStats')
            ->getQueryBuilder($filters)
            ->getSum([])
            ->value('metric');
        return $metrics ? $metrics : 0;
    }

This function is pretty much the same as the existing function PKPSubmission::getViews() except for the value for assocTypes.

Then you would need to adapt your file templates/frontend/objects/issue_toc.tpl. I do not know how you would need to style it so that it looks like that above (with aye and PDF download icon), but this way you can access the numbers (after thie line ojs/templates/frontend/objects/issue_toc.tpl at stable-3_4_0 · pkp/ojs · GitHub):
Abstract Views: {$article->getViews()}
Galley File Downloads: {$article->getDownloads()}

NOTE: Please note that the function PKPSubmission::getViews() is deprecated from 3.4.0 on, so it will be soon removed…

Best,
Bozana

1 Like

Alright, I will try to use the approach you mentioned and see whether I get it working or not.

Regards,