How do I set up Google Analytics 4 (GA4) in Nuxt.js?

Currently, Google Analytics 4 (GA4) is not supported by @nuxtjs/google-gtag or @nuxtjs/gtm (as of August 08, 2021).
You can manually set up the integration by creating a custom plugin as follows.

First, install vue-gtag:

npm i vue-gtag

In the plugins folder, make a new file named gtag.js containing the following:

import Vue from 'vue';
import VueGtag from 'vue-gtag';
Vue.use(VueGtag, {
    config: { id: 'G-********' }
});

Insert the code below into nuxt.config.js:

    plugins: [
        '@/plugins/gtag',
    ],

If you have any other questions, please use our contact form or Slack workspace.