Triggering the logUsageEvent function in usageStatsPlugin with javascript

Hi @bozana

I am thinking of developing my embedGalley plugin further so that it support also embedding HTML files to the abstract page.

What bothers me with the concept is that the file download usage events are not triggered when someone reads an embedded article. I would like to create a solution where:

  1. HTML/JATS XML converted to HTML is embedded under the abstract with only a few lines visible and a “read more” button (something like http://jedfoster.com/Readmore.js/)
  2. Clicking “read more” will reveal the whole article. The article is hidden using javascript and search engines like google can access the whole content without the need to click anything.
  3. clicking the “read more” button will trigger an usage event and log a galley file download

So any initial thoughts whether triggering logUsageEvent would be possible with javascript?

Hi @ajnyga

Hmmm… Difficult questions :slight_smile:

It is so: the UsageEventPlugin builds the events on special hooks calls. Then the UsageStatsPlugin decides when to write them to the log file.
Maybe then something similar to the current hook calls ‘HtmlArticleGalleyPlugin::articleDownload’ and ‘HtmlArticleGalleyPlugin::articleDownloadFinished’ chould be made? At the page load the first call similar to ‘HtmlArticleGalleyPlugin::articleDownload’ would be triggered and first when the user clicks “read more” maybe a function could be called that triggers the second one, that would mean that the article download is finished, similar to ‘HtmlArticleGalleyPlugin::articleDownloadFinished’.
Those hook name that mean finished downloads are listed in UsageEventPlugin::getDownloadFinishedEventHooks() and in UsageStatsPlugin::getDownloadFinishedEventHooks. In UsageEventPlugin for the plugin to know not to build an event (because the usage event for this request is already build), s. https://github.com/pkp/pkp-lib/blob/master/plugins/generic/usageEvent/PKPUsageEventPlugin.inc.php#L151. And in UsageStatsPlugin to know when to log the event, s. https://github.com/pkp/pkp-lib/blob/master/plugins/generic/usageStats/PKPUsageStatsPlugin.inc.php#L295.

But how exactly to do that… Hmmm… :thinking:

:slight_smile: Bozana