AmazingDreams / vue-matomo

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

How to set the site Id dynamically #95

Closed karimennassiri closed 1 year ago

karimennassiri commented 2 years ago

Hi everyone

I've installed the matomo vue module for my Nuxt project

the question is, is there any way to configure the site id dynamicly ?

I'm using the same base code for multiple domaine (with different content)

andorfermichael commented 2 years ago

you can set it via env (.env) and publicRuntimeConfig (nuxt.config.js) variable, and then in plugins/matomo.config.js something like that:

import Vue from 'vue' import VueMatomo from 'vue-matomo'

export default ({ app, route, $config }) => {
    if ($config.matomoUrl) {
        Vue.use(VueMatomo, {
            router: app.router,
            host: $config.matomoUrl,
            siteId: route.fullPath.includes('/site-one') ? $config.matomoSiteOneId : $config.matomoSiteTwoId,
            trackInitialView: false
        })
    }
}