From d365a45eb1a25bdfa124c3ecea3795c49b2bf708 Mon Sep 17 00:00:00 2001 From: Bibek Shrestha Date: Wed, 20 Oct 2021 09:33:33 -0400 Subject: [PATCH] docs(plugins): usage with vue plugins (#1129) Co-authored-by: pooya parsa --- docs/content/3.docs/1.usage/4.nuxt-app.md | 2 +- .../2.directory-structure/10.plugins.md | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/content/3.docs/1.usage/4.nuxt-app.md b/docs/content/3.docs/1.usage/4.nuxt-app.md index 45262756ac..623741f783 100644 --- a/docs/content/3.docs/1.usage/4.nuxt-app.md +++ b/docs/content/3.docs/1.usage/4.nuxt-app.md @@ -39,7 +39,7 @@ In Nuxt 2 plugins, this was referred to as [inject function](https://nuxtjs.org/ ```js const nuxtApp = { - app, // the global Vue application: https://v3.vuejs.org/api/application-api.html + vueApp, // the global Vue application: https://v3.vuejs.org/api/application-api.html // These let you call and add runtime NuxtApp hooks // https://github.com/nuxt/framework/blob/main/packages/nuxt3/src/app/nuxt.ts#L18 diff --git a/docs/content/3.docs/2.directory-structure/10.plugins.md b/docs/content/3.docs/2.directory-structure/10.plugins.md index 180ba6f0eb..182bc7a1b3 100644 --- a/docs/content/3.docs/2.directory-structure/10.plugins.md +++ b/docs/content/3.docs/2.directory-structure/10.plugins.md @@ -41,3 +41,33 @@ declare module '#app' { } } ``` + +## Vue plugins + +If you want to use Vue plugins, like [vue-gtag](https://github.com/MatteoGabriele/vue-gtag) to add Google analytics tags, you can use a nuxt plugin to do so. + +> There is an Open RFC to make this even easier! See [nuxt/framework#1175](https://github.com/nuxt/framework/discussions/1175) + +First install the plugin you want. + +```bash +yarn add --dev vue-gtag +``` + +Then create a plugin file `plugins/vue-gtag.client.js`. + +```ts +import { defineNuxtPlugin } from "#app"; +import VueGtag from "vue-gtag"; + +export default defineNuxtPlugin((nuxtApp) => { + nuxtApp.vueApp.use(VueGtag, { + config: { + id: "GA_MEASUREMENT_ID", + params: { + anonymize_ip: true, + }, + }, + }); +}); +```