pulibrary / figgy

Valkyrie-based digital repository backend.
Other
36 stars 4 forks source link

Track Downloads through Universal Viewer #6388

Closed tpendragon closed 4 months ago

tpendragon commented 4 months ago

The download pane in Universal Viewer:

  1. Doesn't fire any javascript events (so we can't bind to an event and send a custom event)
  2. Doesn't count as an outbound link (https://plausible.io/docs/outbound-link-click-tracking doesn't work)
  3. Doesn't count as a "File Download" (https://plausible.io/docs/file-downloads-tracking doesn't work)
  4. DOES use window.open to open a link. (https://github.com/UniversalViewer/universalviewer/blob/main/src/content-handlers/iiif/extensions/uv-openseadragon-extension/DownloadDialogue.tsx#L431)

Thus we can fire a custom event by, if Universal Viewer is loaded, overriding window.open in the viewer. This also adds an "?embed_host" property that can be added to the iframe, and sends the environment it's sending as. This is done via the documentation at https://plausible.io/docs/custom-props/for-pageviews#2-add-your-custom-properties-to-your-plausible-snippet.

Finally, this uses manual for Plausible, which means it doesn't automatically track page views - I don't think we care how many people go to /viewer, just how many people interact with that viewer.

The documentation for sending a custom event with properties in Plausible is here: https://plausible.io/docs/custom-props/for-custom-events#2-using-the-manual-method

Closes #6376 Closes #6377

This will miss any downloads done from within Figgy. We could do that, but I'm not sure it's necessary - that's not a public interface our patrons will be accessing.

hackartisan commented 4 months ago

Are there any plausible docs you used to work this out? It would be nice to have the links to them in the description of the PR.

tpendragon commented 4 months ago

@hackartisan Good idea! Added some links.

tpendragon commented 4 months ago

Drafted so I can add some tests of this plausible functionality.