This question is in the weeds of the API.
I’m using a fork of the excellent Matomo theme component. This lets you track page views with Matomo. My fork is an attempt to work-around issues. It’s essentially identical. The behavior described below occurs with the upstream component as well.
The component uses the
onPageChange callback to configure a Matomo API/facility.
The issue I’m having is that, at times, the
onPageChange callback is made before the page title is generated. This is inconsistent. Sometimes the title is fully formed, sometimes it’s not.
The result is that the Matomo log history has a mix of fully-formed page titles and not.
Looking over the Discourse source code, this is called prior to the
This all looks like it should work - the title should be refreshed by the time
onPageChange is called. It is not - at least not consistently.
There’s another issue that may be related.
onPageChange is sometimes called twice. This is my work-around (and the motivation for the fork):
In the case when
onPageChange is called called twice for the same page view, one of the two calls provides a
url arg that’s different from the current window location. I check this and exit early.
(Note that I handle the
page:changed event via
onAppEvent rather than
onPageChange but I see the same behavior in either case.)