Vue 集成 Matomo
https://github.com/AmazingDreams/vue-matomo
Installation
Browser
Usage
Bundler (Webpack, Rollup)
For available operations see the matomo api docs
Note on async loading
This plugin loads the matomo.js
asynchronously, which means it is possible that $matomo
is not (yet) loaded. Furthermore anti-tracking plugins on browsers might block matomo.js
entirely. You should always guard your calls to $matomo
, or use window._paq.push
:
Note on external link tracking
When using the option to trackExternalLinks
, vue-matomo
ensures the corresponding Matomo method is called after each navigation event. Matomo scans the entire DOM for external links and adds its link handling. This means that if your external links are rendered dynamically these links may not be picked up. You need to call this method manually if links might not exist after the page has finished rendering (for example if the links come from some REST call). For more information refer to https://developer.matomo.org/guides/spa-tracking#link-tracking
Nuxt
Nuxt can work by creating a plugin that will load VueMatomo with SSR disabled. Note how the router is passed in the second snippet:
Ignoring routes
It is possible to ignore routes using the route meta:
Managing tracking consent
First of all load the plugin with the requireConsent
option enabled:
Matomo has a built in way to give and remember consent. The simplest way is to simply use this method provided by Matomo:
Another option is to use your own implementation for remembering consent. In that case you can simply callthis.$matomo.setConsentGiven()
on each page load when you establish that the user has given consent.
Managing cookie consent
You can use Matomo Analytics without consent and cookie banner. For more information see matomo faq: “How do I use matomo analytics without consent or cookie banner?.
First of all load the plugin with the requireCookieConsent
option enabled:
Matomo has a built in way to give and remember consent. The simplest way is to simply use this method provided by Matomo:
Another option is to use your own implementation for remembering cookie consent. In that case you can simply callthis.$matomo.setCookieConsentGiven()
on each page load when you establish that the user has given cookie consent.
Build
Bundle the js and css of to the dist
folder:
最后编辑:Jeebiz 更新时间:2024-11-26 23:26