View metrics on the website for all download and journal views

My friends,
I’m trying to put on the homepage of the site the total download metric and views of all the journals on the site. Could someone help me, as I am not able to access the specific metrics (download and view).
Would I have to add up all the metrics in the newspapers or can I in metrics pick up the total?
Do I need to set up a class and / or function?

I’ve seen that it has a new tab for statistics-> articles, I honestly loved it.
But I’d like to know how I can do to add all those numbers from the “Abstract Views” and put it in a place on the main page.

Hi @monicalp,

It depends on whether you want to get the total and add it manually to the front page, and update it yourself every now and then. Or whether you want to write custom code so that the theme automatically shows a count that is updated regularly.

To do the manual way, go to Tools > Report Generator and get the View Report. This will give you a spreadsheet with all the article views that you can add up. You can then add it to a journal’s homepage under Settings > Website > Appearance > Additional Homepage Content.

If you want to write code, you will need to write a plugin or theme that calculates this information and then customize your theme to show it in the place that you want. Off the top of my head, the steps would be something like this:

  1. Get all the abstract records from the metrics table for one context.
// Get the journal
$context = $request->getContext();

// Get every record of a daily count related to the journal
$records = DAORegistry::getDAO('MetricsDAO')->getMetrics(
  'ojs::counter',
  [STATISTICS_DIMENSION_DAY],
  [STATISTICS_DIMENSION_CONTEXT_ID => $context->getId()],
);

// Loop over the records to add up the total
...
  1. Save that information to your plugin’s settings table.
$this->updateSetting($contextId, 'totalJournalAbstractViews', /* the total */);

You can later retrieve it like this:

$this->getSetting($contextId, 'totalJournalAbstractViews');
  1. Retrieve that information and pass it to the template where you want to display it. Passing Data to Templates

However, you should beware about doing this for every page load. The metrics table is very large and queries take a long time. If you perform the query every time someone hits your server, you will quickly bring your server down.

To prevent this, you should also save the date when you calculated the stats, and only recalculate them once a day.

1 Like