All records count twice in SPA

Matomo is good analytics, but I have an analytical problem for single page applications using vue js
this is my initialization

Vue.use(VueMatomo, {
  host: 'https://example.com',
  siteId: 2,
  trackerFileName: 'piwik',
  router: router,
  enableLinkTracking: true,
  requireConsent: false,
  trackInitialView: true,
  debug: true
})

and this is the code for the record link

var currentUrl = location.href
        var titlePage = document.title
        var pathUrl = window.location.hash.substr(1)
        this.$piwik.setCustomUrl(pathUrl)
        this.$piwik.setDocumentTitle(titlePage)
        this.$piwik.deleteCustomVariables(1, 'page')
        this.$piwik.setGenerationTimeMs(5)
        this.$piwik.trackPageView()
        this.$piwik.enableLinkTracking()

the problem is that the page is recorded twice, when I go to the localhost / x page, the previous page will remain in the record, when going to the localhost / y page, the previous page will also remain in the record
is there a solution for this?

Hi,

This is probably something you should rather ask the developer of VueMatomo (or invite him to answer here), but I wouldn’t be surprised if by default the module tracks a pageview on every route change and therefore your this.$piwik.trackPageView() records it a second time.

But as said this is just a guess as I haven’t used VueMatomo.

1 Like

We do not use Vue, but React and I’m pretty sure you are right.

Just tacking quick glance at the project https://github.com/AmazingDreams/vue-matomo :

// Enables automatically registering pageviews on the router
router: router,

Thanks all, it has been solved, but there are other problems
when the user is on the “localhost/about” page, and the user reloads the page, not the “localhost/about” page that is recorded but page “localhost:8080”
is this default in vue js or not, which is clearly not what I want

I would guess, this happens because trackInitialView is enabled. But as this is surely not a Matomo problem, you should maybe ask the developer about this.

1 Like