Closed mBbkr closed 3 years ago
you can find it in the component scope like most plugins:
<template>
<div>
<button @click="track">Track</button>
</div>
</template>
<script>
export default {
name: 'MyComponent',
methods: {
track () {
this.$gtag.pageview('/foo')
}
}
}
</script>
I already know that. This is not what I'm looking for.
I'm not in a .vue i'm in a dot js for a plugin. this is where i need $gtag.
import { pageview } from 'vue-gtag'
pageview('/foo')
if you want to use all gtag feature, you can import the query
method: it would be like calling gtag
itself
@m8bkr I found a solution to this problem What is the order of your plugin initialization? Your vue-gtag.client.js and vue-gtag.server.js must come before the plugin that wants to access app.$gtag else it will always be undefined
I have integrated a vue-gtag component for NuxtJs in a plugin :
I'm looking for how to call the $gtag global var instantiate by the gtag component, in another component.
In the target plugin I've tried :
or :
or :
It's always undefined.
Somebody have an idea how to do that ?
gtag-plugin.client.js