Migration from ga to gtag.js scripts

366 Views Asked by At

Couldn't find direct migration tutorial or clear description on https://developers.google.com/gtagjs/reference. Have limitation to analitic portal access and can't properly to test it.

Need to change next ga scripts under my SPA app to gtag.

1. ga('set', 'page', url)
2. ga('send', 'pageview')
3. ga('send', 'event', 'button-interest-request', 'submit-request')

I didn't find how should works set on gtag.

I supposed should be something like next strings for strings 1 and 2

gtag('event', 'page_view', { page_location: url })

And next for string 3

gtag('event', 'button-interest-request', {
  'value': 'submit-request'
});

Am I right?

1

There are 1 best solutions below

0
Michele Pisani On

You have to define at least event category and event action in gtag with this syntax:

gtag('event', <action>, {
  'event_category': <category>,
  'value': <value>
});

In your situation, like this:

gtag('event', 'submit-request', {
  'event_category': 'button-interest-request'
});