gatsby-plugin-gdpr-cookies icon indicating copy to clipboard operation
gatsby-plugin-gdpr-cookies copied to clipboard

G tag code commented out?

Open arnars opened this issue 4 years ago • 7 comments

Thanks for this plugin. Made my life a lot easier.

I was looking at the GTAG code and I was wondering why the main methods were commented out. Is that on purpose or is it by mistake? It might be me that are misunderstanding how things works, but the other services seems to have the code active.

Best, Anders

arnars avatar Oct 30 '21 09:10 arnars

@arnars Were you able to find a solution? Did you fork the repo or used another approach?

kb1995 avatar Dec 02 '21 18:12 kb1995

I also don't understand why the code is commented out. @andrezimpel ? In fact i forked the repo to include the commented code and it works for me.

gabriardi avatar Dec 05 '21 13:12 gabriardi

@gabriardi I ended up doing the same thing (forked your fork) and it looks like it working fine now.

I wonder what's the reasoning behind the commenting out of a working code

kb1995 avatar Dec 09 '21 10:12 kb1995

@arnars & @gabriardi When I was testing the code I ended up receiving duplicate events because somehow gtag was ready to fire them trough the initialization. If both of you got it working by including it again I would be really happy if you could create a pull request. I'd merge it asap.

Thank you!

andrezimpel avatar Dec 09 '21 10:12 andrezimpel

Hi, I was affected by this issue too: Gatsby wasn't firing the routeChangeEvent event because all the code is commented, but by doing a little research, I think I know why this was commented and why @andrezimpel was receiving duplicate events.

There is a new version of Google Analytics (GA4) that has an Enhanced measurement for Page views, and what it does is to detect changes on the browser's history object. Having this option enabled (it's on by default) tracks every change on the browser history (every change on the address bar) as a page_view event.

Meaning if you have GA4 with enhanced measurement, you don't need the routeChangeEvent event nor the custom event trigger on GTM, you just have to set "All pages" as a trigger for the GA4 tag.

Having said that, there will be people without enhanced measurement, or with an old version of GA, so I think it would be convenient if the user has the option to control if the plugin should fire this event or not, maybe configuring routeChangeEvent to an empty string?

gonzalo-massa avatar Apr 20 '22 20:04 gonzalo-massa

@gonzalo-massa yea man. that's been the reason it was commented you but as it turns out a lot of people use it differently that's why I merged #72. Any idea on how to fix that tho?

andrezimpel avatar May 05 '22 14:05 andrezimpel

@gonzalo-massa yea man. that's been the reason it was commented you but as it turns out a lot of people use it differently that's why I merged #72. Any idea on how to fix that tho?

My suggestion is to give the developer the control over this, if they want to fire the routeChangeEvent or not, maybe setting routeChangeEvent: false (or an empty string to maintain consistency with the rest of the options). Then the plugin will check that before firing the event.

I could try to submit a PR for that, but I don't know the code very well.

gonzalo-massa avatar May 05 '22 19:05 gonzalo-massa