Access gtag instance directly

I try to make all method a bit simpler so you don't need extra boilerplate, but gtag api is quite vast, so in case you didn't find what you were looking for, you can use the query method: it will be like using gtag itself.

Composition API

import { useGtag } from "vue-gtag-next";

export default {
  name: 'MyComponent',

  setup() {
    const { query } = useGtag();

    const trackScreenview = () => {
      query("event", "screen_view", {
        app_name: "MyApp",
        screen_name: "Home page"
      });
    };

    return {
      trackScreenview
    };
  }
};

Options API

export default {
  name: 'MyComponent',

  methods: {
    track () {
      this.$gtag.query('event', 'screen_view', {
        app_name: 'MyApp',
        screen_name: 'Home page',
      })
    }
  }
}

Last updated