MatteoGabriele / vue-gtag

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

Google Ads: Conversion event #64

Closed BernhardSchlegel closed 4 years ago

BernhardSchlegel commented 4 years ago

Description

I want to emit an Google Ads conversion event. Google generated the following code:

gtag('event', 'conversion', {
      'send_to': 'AW-424270545/dwgaH7KkocA6EJHh7MAC',
      'event_callback': callback
  });

How does that translate to

this.$gtag.event(<action>, {
        'event_category': <category>,
        'event_label': <label>,
        'value': <value>
      })

I already initialized gtag with my global (Google Ads) gtag.

Thanks in advance!

MatteoGabriele commented 4 years ago

translates to this

this.$gtag.event('conversion', {
  'send_to': 'AW-424270545/dwgaH7KkocA6EJHh7MAC',
  'event_callback': callback
});

and if you already have gtag enabled you should install the plugin like so

Vue.use(VueGtag, {
  config: { id: "UA-1234567-1" },
  disableScriptLoad: true
});
BernhardSchlegel commented 4 years ago

Thanks, mate! Figured it out yesterday and saw my first conversion today. Confirmed :)

For the ones following, I added a separate, additional gtag config for Google Ads

mounted() {
  this.$gtag.config('AW-424270545');
},
Mushr0000m commented 4 years ago

Where did you set the code for the event_callback callback value ? Because Adwords give me this :

<script>
function gtag_report_conversion(url) {
  var callback = function () {
    if (typeof(url) != 'undefined') {
      window.location = url;
    }
  };
  gtag('event', 'conversion', {
      'send_to': 'XXXX',
      'event_callback': callback
  });
  return false;
}
</script>