-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gatsby-plugin-google-gtag] Analytics isn't working #12967
Comments
Problem was in |
Can you elucidate on this? |
@janbaykara, I got tripped up on this, too. Basically, the "How to use" at https://www.gatsbyjs.org/packages/gatsby-plugin-google-gtag/ shows |
I'm using this config:
And it is not working for me. No data is displayed in GA. |
Anyone found the solution? I am doing
|
I figured out! It was the path of the .env file inside the gatsby-config.js of the starter that I am using:
|
Actually it was not that, I even removed again the
then, in the .env file i inserted the credentials like: How the .env is a .gitignore file, in Netlify I used the credentials inside the Build command like:
It worked! clap |
I don't know why but I just put the plugin as the first one in the config file. |
This plugin has issues. This is how I solved it: Put it at very first position so it is the first plugin to be loaded. This is how it looks in my
|
If you have problems, keep in mind "do not track" setting in your browser. Anyways, tracking seems to work now, but it's quite unstable. Not all events are tracked so not sure what's the problem. |
I would just like to add (for future note) that moving |
This thing hasn't worked me since the first time I tried (maybe 1.5 years ago). At one point it did track the first pageview, but the subsequent navigations to other pages didn't trigger anything. Quite unsatisfied with the quality of this library and has caused me to waste a lot of time. You would think that given that this is an officially supported plugin it would have official-level support. It's not nice having to debug 3rd party code with no obvious clues why it's not working. Even tricks like the aforementioned moving of the plugin to the top of the plugin list are ugly hacks, not permanent fixes. Sometimes I feel Gatsby has become too tangled of a mess to use it without weird problems. Or well, it was a mess to start with and it feels it still is. It's just as a developer I don't have interest in debugging arcane problems. And the JS source code itself looks quite spagetti. No wonder no one can understand what is the problem with it. |
@TeemuKoivisto |
@AAverin I am not sure what you were going for, yes I can write my own wrapper? But why should I? I thought the point of having libraries is that I can rely on them to let me focus on more productive things. And "go to the plain react app", what you mean by that? I am not making a plain react app, that is why I am here. I just wanted to add GA with basic pageviews and that's it. Didn't think it was this hard. After fiddling with the So I decided to give |
Thank you for opening this! The PR (#19175) addressed some of the things here although I never had any issues with the positioning of the analytics plugin in the plugins list. But it's now in the docs, it doesn't hurt anyone... This could also be an issue with a bunch different outside factors like browser settings, AdBlockers, software on your machine. Or even how Google handles gtag and analytics differently. AFAIK they're pushing people towards gtag, so feel free to look into that. We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby! |
Summary: this is a known and strange issue -- the gatsby GA plugin would work in production only when the plugin is on the very top of the plugin list the fix is **very ugly** but seems the only easy way gatsbyjs/gatsby#12967 gatsbyjs/gatsby#19175 Test Plan: I tested in local and it worked. {F108362} But it worked before too.. the issue only exists in prod, so I could only test it after I deploy it 🤦♀️ Reviewers: sashank, max Reviewed By: sashank Differential Revision: https://dagster.phacility.com/D2379
Quite silly to say this, but I noticed that the it is disabled Nothing was added or altered other than adding below in
|
Moving the plugin to the top did nothing for me, but switching to plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-plugin-gtag`,
options: {
trackingId: `UA-XXXXXXXXX-X`,
head: false,
anonymize: true,
},
},
...
], |
@ilyankou are you able to get it to track page views? it seems to be hard-coded not to do so. |
@ardalis Yes, gtag works for it all (I created the code snippet from Google Analytics): https://developers.google.com/analytics/devguides/collection/gtagjs/ See what Google Tag Assistant shows (I only added the |
Did this go anywhere? I'd love to get GA working in dev/test mode, so we can build and test analytics (we have separate dev and prod GA profiles) |
after configuring how to how acces gatg and fbq in the project in order to emit events like fbq('init', '1234567'); fbq('track', 'PageView'); like this and fbq('track', 'checkout'); in a particular pages like this |
I tried a variety of options listed above and this is the combo that eventually worked for me:
|
I've been struggling with this for a while. I could get it working with by placing the gtag plugin before the other plugins (including the react helmet) as mentioned by @dkoloditch here. A mentioned already use |
…anonymise' options
this save my life |
Using the gatsby-plugin-google-gtag plugin worked for me, I had to set "send_page_view: true" in the options, it seems to default to false.
|
@knambiar Thank you for your solution. However, I don't quite understand how you can override
As you can see, it looks like it always set to false. Even though we set it to true from In addition, I think we also need to update a setting in Google Analytics admin as in this video. FYI 9842 PR set |
…anonymise' options
did anyone found a reliable way to make it work? The gtag plugin isn't sending page view events to google tag manager. I have tried everything that is mentioned above in this thread |
@itstyro Have you tried the GA Debug extension? This works pretty good to show what the scripts are doing. You might be able to step through in the console and get some insight to your issue. |
Worked for me :) |
For someone who is still struggling with this issue (like me). {
resolve: `gatsby-plugin-google-gtag`,
options: {
trackingIds: [
"G-XXXXXXX", // Google Analytics / GA
],
pluginConfig: {
head: true,
},
},
}, |
Summary
Relevant information
With the default setting of gatsby-plugin-google-gtag, analytics doesn't seem to work at all.
No active users or custom events are being tracked.
I tested on production, also tried putting script into header
Environment (if relevant)
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.10.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Browsers:
Chrome: 73.0.3683.86
Safari: 12.1
npmPackages:
gatsby: ^2.2.8 => 2.2.8
gatsby-image: ^2.0.34 => 2.0.34
gatsby-plugin-catch-links: ^2.0.13 => 2.0.13
gatsby-plugin-facebook-pixel: ^1.0.3 => 1.0.3
gatsby-plugin-google-analytics: ^2.0.17 => 2.0.17
gatsby-plugin-google-gtag: ^1.0.16 => 1.0.16
gatsby-plugin-react-helmet: ^3.0.10 => 3.0.10
gatsby-plugin-sharp: ^2.0.30 => 2.0.30
gatsby-remark-autolink-headers: ^2.0.16 => 2.0.16
gatsby-remark-copy-linked-files: ^2.0.11 => 2.0.11
gatsby-remark-images: ^3.0.10 => 3.0.10
gatsby-source-filesystem: ^2.0.28 => 2.0.28
gatsby-transformer-remark: ^2.3.8 => 2.3.8
gatsby-transformer-sharp: ^2.1.17 => 2.1.17
npmGlobalPackages:
gatsby-cli: 2.4.4
File contents (if changed)
gatsby-config.js
:The text was updated successfully, but these errors were encountered: