Effective event watching for Page View oriented metrics

One of the truly beautiful parts about Discourse is the fact that once logged-in you load the page once and the rest of the user experience navigates like a true software application. Much of it is javascript feeding from a predictable set of Rails API endpoints.

Here are approaches I have been trading off using in my current install:

  1. The “Pre-2017 triad”:
  • new Event
  • addEventListener to node
  • setInterval to monitor

  + [insert series of conditions that can get truthy]

  1. Post-2017 MutationObserver() class:
  • MutationObserver()
  • observe w/ class-based filters

How else can we detect the Ember-based events changing the DOM inside Discourse? Are there specific events we can listen to? Are there better approaches than what I am using?

Hoping to get people to throw up some example approaches and theories.

Thanks!

For page view metrics we have built-in support:

<script type="text/discourse-plugin" version="0.2">
  api.onPageChange((url, title) => {
    // do stuff
  });
</script>
3 Likes