onehilltech / ember-cli-google

a collection of Google services as an Ember CLI add-on
Apache License 2.0
12 stars 3 forks source link

Huge event decrease on google analytic after update to ember-cli-google-analytics@1.5.0 #8

Closed romgere closed 2 months ago

romgere commented 1 year ago

Hi there,

I recently update to ember-cli-google-analytics@1.5.0 on one of my pet project (was previously on 1.2) & I think there's something wrong (maybe my integration) because since I got huge decrease of events on my web site : image

Here is gtag related changes : image

Any clue on what's happening there ? Did I miss something in the changes from 1.2 to 1.5 🤔

Thanks !

hilljh82 commented 1 year ago

@romgere What version of Google Analytics are you using? Are you using V4 via the Tag Manager?

romgere commented 1 year ago

@hilljh82 I won't lie I'm not sure, I can't find any "version" indicator in Google Analytics / Tag manager... I created the tag 1 year ago, so I was assuming that it's a v4 🤷🏻‍♂️

I was using version 1.2 with v4 config & didn't change it when upgrade to 1.5 :

'ember-cli-google': {
      analytics: {
        version: 'v4',
        measurementId: 'G-47QBQ5GB3Y',
      },
    },

I guess, if it was working with 1.2, it's a v4 tag 🤔

romgere commented 1 year ago

I used Tag assistant to debug my gtag integration & I found that the event method of gtag service is not working properly (at least for my needs)...

According to documentation event should be send like this :

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

So implicitly gatg function is using :

dataLayer.push(['event', <action>, {
  'event_category': <category>,
  'event_label': <label>,
  'value': <value>
}])

But in gtag service, the event function is doing :

dataLayer.push({
  'event': <action>
  'event_category': <category>,
  'event_label': <label>,
  'value': <value>
})

Which (according to the doc) is not the way to send custom event ...

I tried changing gtag service event function to this :

event(name, params) {
  this.push('event', name, {...params });
}

And I can now see my custom event poping in Tag assistant debugger : image

romgere commented 1 year ago

That make me wondering if the gtatg service event function has been done for sending custom event ? I'm figuring out that previously I was not using the gtatg service, but I was calling directly gtag(...) function in my app (aka. I was just using ember-cli-google-analytics add-on to inject the gtag js script in my app 🤔)

romgere commented 1 year ago

Another thing I noticed, is that gtag script was previsouly injected by packages/ember-cli-google-analytics/index.js at app build where now, the script is injected at run time when gtagservice is first used.

I think this change can make a huge difference, given, is the consuming app is not using the gtag service, script won't be injected in app 🤔

romgere commented 1 year ago

I fixed issue on my side, so from my POV this can be closed, but I let you closing this issue given there may be some action you want to take regarding what was discussed here. Thx !