All records count twice in SPA


(Ace Kyub) #1

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?


(Lukas Winkler) #2

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.


(Fabian Dellwing) #3

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

Just tacking quick glance at the project GitHub - AmazingDreams/vue-matomo: Vue plugin for Piwik / Matomo Analytics :

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


(Ace Kyub) #4

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


(Fabian Dellwing) #5

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.