MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
870 stars 67 forks source link

SSR - Fails to use send_to config on events for Google Ads #197

Closed timothymarois closed 3 years ago

timothymarois commented 4 years ago

Appears to be missing the send_to config on event conversions

Im trying to set up something similar to this:

vm.$gtag.event('conversion', {
     'send_to' : 'AW-0000/jksjdfksjdfj
});

When running this, it fails to send the fire off. You can see the send_to reference here:

https://developers.google.com/gtagjs/reference/api#event

example given:

gtag('event','conversion', { 'send_to': '<TARGET_ID1>' });

This is important for Google Ads conversions/Audience tracking

This is what Google Ads gives:

<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-000000/kDJisdjiaoSJDOA',
      'value': 1.0,
      'currency': 'USD',
      'aw_remarketing_only': true
  });
</script> 

Tried to recreate that by using the query method:

vm.$gtag.query('event','conversion', {
       'value': 0,
       'currency': 'USD',
       'send_to' : 'AW-000000/kDJisdjiaoSJDOA',
       'aw_remarketing_only': true 
 }); 

still doesnt work.

To conclude, nothing actually fires, if you remove the send_to it works, but thats not going to work properly (sending to the right account). If you add the send_to it does absolutely nothing.

timothymarois commented 4 years ago

Found the issue:

https://github.com/MatteoGabriele/vue-gtag/blob/ba592843c3b37ed00f927634c9b23b4851dd8a59/src/api/query.js

Related to the window not found because of using Nuxt. That makes sense why it just went blank. Though I wonder why event still failed while page views works just fine, but moment you use sent_to it doesnt work, as it looks like send_to is in the code base for event method.

Conclusion, does not work with Nuxt on SSR state since there is no DOM to interact with.

MatteoGabriele commented 4 years ago

Strange. Nothing should work on ssr then. The only thing I do is just checking if windows and document are defined whenever I use them, not sure to comply more to ssr applications.

Would love to hear some suggestions if you have them

Cheers

MatteoGabriele commented 3 years ago

:tada: This issue has been resolved in version 1.13.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: