Closed SteveEdson closed 3 years ago
Actually, I've just figured it out:
export default ({ app }, inject) => {
inject('trackEvent',(category, action, label = null, value = null) => {
if ('$gtag' in app) {
try {
app.$gtag('event', action, {
event_category: category,
event_label: label,
value: value,
});
} catch (e) {
console.error('e', e);
}
}
});
};
Thanks
I'm trying to send events from within a plugin, where
this
and thereforethis.$gtag
isn't available. Is it possible to import it or use it some other way?Here's my plugin code:
I'm wanting to do it this way so I can have a single
$trackEvent
method which could then send to google, hotjar, the console or any other services etc