AmazingDreams / vue-matomo

Vue plugin for Matomo Analytics
MIT License
273 stars 61 forks source link

Need a disabled option for local development #81

Open mdunisch opened 3 years ago

mdunisch commented 3 years ago

While i develop locally i create a lot of traffic. In vue-gtag there is option for it: https://matteogabriele.gitbooks.io/vue-analytics/content/docs/turn-off-development.html

Is there anything similar in vue-matomo?

AmazingDreams commented 3 years ago

Sorry I have had little time lately. Such a feature does not yet exist, but I think it is a good feature.

mdunisch commented 3 years ago

At the moment i do this as a workaround:

index.js

Vue.use(VueMatomo, {
  requireConsent: true
});

App.vue

created(){
    if (process.env.NODE_ENV === 'production') {
      this.$matomo.rememberConsentGiven();
    }
}

but would be awesome to just disable the tracking and not use a other feature as a workaround

AdrienAdB commented 1 year ago

Hi, you can setup URLs and "Only track visits... from URLs..." in Matomo website settings. It works fine when I develop from localhost or dev (sub-)domains.

I ended up on this issue as I was looking for a way to disable tracking based on specific parameters, such as http://mywebsite.com/?optout=1

jebarjonet commented 1 year ago

You can enable it only when you are in production like this :

if (process.env.NODE_ENV === "production") {
  Vue.use(VueMatomo);
}
JoostKersjes commented 5 months ago

This is what I ended up doing:

import App from "@/App.vue";
import { router } from "@/router";
import { createApp, type Plugin } from "vue";
import VueMatomo from "vue-matomo";

// Config from Vite .env file(s)
const siteId = import.meta.env.VITE_MATOMO_SITE_ID;
const hostDomain = import.meta.env.VITE_MATOMO_HOST;

// Wrapper plugin
const matomoPlugin: Plugin = {
  install(app) {
    if (!hostDomain || !siteId) {
      // eslint-disable-next-line no-console
      console.warn("Matomo did not load because options are missing.");
      return;
    }

    app.use(VueMatomo, {
      host: `//${hostDomain}`,
      siteId: siteId,
      router: router,
    });
  },
};

createApp(App)
  .use(router)
  .use(matomoPlugin)
  .mount("#app");

And of course you can change the if to be any condition you want.