A
A
anatoliy_vas152019-12-03 01:49:55
Google Analytics
anatoliy_vas15, 2019-12-03 01:49:55

How to send a gtm vue event?

I need to submit a target like this on successful completion of a form in Vue

gtag('event', 'send', {
  'event_category': 'forms'
}); return true;

How can I do it right?
There is a vue-gtm and vue-analytic plugin, is it possible to do this through them, because I can’t find any information. I connect it to index.html, it swears gtag is not defined.
<script async src="https://www.googletagmanager.com/gtag/js?id=GA-TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'GA-TRACKING_ID');
</script>

This way it doesn’t work either, they say everything breaks down in general (does not see the form processing)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Tikhonov, 2019-12-03
@mylp

Create a variable in the windows object with a handler function pointer like this: mounted() {
window.vuehookfunction = this.someMethod.bind(this);
}
And then call in gtag:
gtag() {... window.vuehookfunction && window.vuehookfunction(params) ;}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question