Migration v2 to v3
All functionality from version v2 is preserved in v3, although most options have been renamed and organized by their scope. The primary focus has been on rewriting the entire codebase in TypeScript to enhance the developer experience and ensure better type safety.
In addition, new methods have been added like consent, consentGrantedAll, consentDeniedAll, ecommerce, and the useConsent composable.
installation
v2
import { createApp } from "vue";
import App from "./App.vue";
import VueGtag from "vue-gtag";
createApp(App).use(VueGtag, {
config: { id: "GA_MEASUREMENT_ID" }
}).mount("#app");v3
I suggest using the `configure` method to install vue-gtag, as it has a smaller initial bundle size and won't add all methods to the Vue instance. While you won't be able to use $gtag in your templates, you can still import each method individually as needed.
import { configure } from "vue-gtag";
configure({
tagId: "GA_MEASUREMENT_ID"
})Use the `createGtag` method if you wish to install global properties. This will increase the bundle size because all methods will be bundled together when injected into the Vue instance. You will be able to use $gtag in your template.
Multiple account tracking
v2
v3
Plugin hooks: onReady and onError
v2
v3
For more details about hooks, check the Plugin hooks page
Auto tracking
The auto-tracking feature moved to a separate object. Check the Page tracker page
v2
v3
Deferred plugin initialization
v2
v3
Last updated