I would like to implement the Nuxt Meta Pixel on production only and track events.
Problem: My current setup is working as intended but when I use $fbq I'm getting '$fbq' is of type 'unknown'.ts(18046)
I'm aware of the $production option in the nuxt config which I have used like so:
$production: {
modules: [
'nuxt-meta-pixel'
],
}
My runtime config in nuxt config looks like so:
runtimeConfig: {
public: {
metapixel: {
// ID is in .env
default: { id: '', pageView: '**', autoconfig: true }
},
}
}
This is how I track an event on a certain page:
const { $fbq } = useNuxtApp()
const { NODE_ENV } = useRuntimeConfig().public
onMounted(() => {
if (NODE_ENV === 'production') {
// `'$fbq' is of type 'unknown'.ts(18046)`
$fbq('track', 'Lead')
}
})
Is this approach correct for only implementing the tracking pixel on production? How can I keep Typescript support when importing $fbq?
I would like to implement the Nuxt Meta Pixel on production only and track events.
Problem: My current setup is working as intended but when I use
$fbqI'm getting'$fbq' is of type 'unknown'.ts(18046)I'm aware of the
$productionoption in the nuxt config which I have used like so:My runtime config in nuxt config looks like so:
This is how I track an event on a certain page:
Is this approach correct for only implementing the tracking pixel on production? How can I keep Typescript support when importing
$fbq?