ChatALL
ChatALL copied to clipboard
Add a composable used to get the Matomo instance in SFC
After exploring the code of the "vue-matoto", I found that it initializes the Matomo instance asynchronously. This prevents the Matomo instance from being accessible to components immediately after the app is mounted.
To make it work in SFC, a possible solution without touching the code of "vue-matomo" would be to create a composable called useMatomo
. Within this function, create a ref of null, then start a timer to check if window.Piwik
exists. Once window.Piwik
becomes available, assign the value of window.Piwik.getAsyncTracker()
to the ref. Finally, return the ref as the output of the function.
Then we can use Matomo in SFC as follows:
const $matomo = useMatomo();
const onSomeCallback = () => {
$matomo.value?.trackEvent();
}
This can be used to fix the problems in #72
Looks great! Why not patch other files to use this?
At first, I planned to refactor the ChatMessage component, but I found that another PR had already accomplished it. I wondered why the inject
did not work and then found a solution. Certainly, I can provide my version of refactoring it.
Looks great! Why not patch other files to use this?
@jerray if your PR is accepted I could integrate your composable on my PR 😁
@jerray if your PR is accepted I could integrate your composable on my PR 😁
@k4lu-0p Launch it! @jerray Thank you again.
@jerray if your PR is accepted I could integrate your composable on my PR 😁
@k4lu-0p Launch it! @jerray Thank you again.
done !