AmazingDreams / vue-matomo

Vue plugin for Matomo Analytics
MIT License
272 stars 60 forks source link

How to configure userId tracking? #113

Closed badrul closed 1 year ago

badrul commented 2 years ago

I have the following setup but unable correctly track userId. When user first visit, userId is undefined, after user log-in, matomo is still tracking userId as undefined unless I refresh vue page.

main.js

const app = createApp(App)
// matomo configuration
const matomoConfig = {
  ...
  userId: store.getters.user ? store.getters.user.user_id : undefined
}
app.use(VueMatomo, matomoConfig)
  .mount('#app')
AmazingDreams commented 1 year ago

I recommend doing:

this.$matomo.setUserId(newUserId)
this.$matomo.trackPageView()
// or
window._paq.push(['setUserId', newUserId])
window._paq.push(['trackPageView']);

As soon as your user id becomes available.

atrujillofalcon commented 12 months ago

I recommend doing:

this.$matomo.setUserId(newUserId)
this.$matomo.trackPageView()
// or
window._paq.push(['setUserId', newUserId])
window._paq.push(['trackPageView']);

As soon as your user id becomes available.

But doesn't manually invoking trackPageView conflict with the router's automatic integration?