Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'gatsby-plugin-google-analytics' is not working for my gatsby-strapi website

this is my code in gatsby-config.js

module.exports = {
  siteMetadata: {
    title: `title`,
    description: ``,
    author: `@Wavii`,
  },

  plugins: [
    {
      resolve: `gatsby-plugin-google-analytics`,
      options: {
        trackingId: "UA-XXXXXX-XX",
        // Defines where to place the tracking script - `true` in the head and `false` in the body
        head: true,
      },
    },
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },

don't know why it is not working, it is not even showing any google analytics on my source code.

Thanks in advance.

like image 625
Ankit Jain Avatar asked Nov 26 '19 11:11

Ankit Jain


People also ask

Where do I put the Google Analytics code in The Great Gatsby?

Add Google Analytics via official pluginAdd the plugin to your gatsby-config. js file: module. exports = { plugins: [ // All other plugins { resolve: `gatsby-plugin-google-gtag`, options: { // You can add multiple tracking ids and a pageview event will be fired for all of them.

What is the difference between Google Analytics and Google Tag Manager?

Google Tag Manager and Google Analytics are both Google tools used for tracking website data. However, they serve different purposes. Google Tag Manager is used for managing tags on a website, while Google Analytics is used for analyzing website data.


1 Answers

I can't get it working in production either. I've also tried https://www.gatsbyjs.org/packages/gatsby-plugin-gtag/ - which I hear is the "newer" way, and I can get some results using Helmet like so:

  <Helmet>
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXX-X"></script>
  <script type="application/ld+json">{`
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('config', 'UA-XXX-X');
  `}</script>
  </Helmet>

... but I don't have it successfully testing in production yet. I've installed all the google analytics plugins and though debug works in the case of Helmet, I'm not really getting good results otherwise.

like image 108
RevelationX Avatar answered Nov 08 '22 07:11

RevelationX