gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.19k stars 10.33k forks source link

Not updated for New Google Analytics #27627

Closed btahir closed 3 years ago

btahir commented 3 years ago

Hi - Google Analytics just characteristically rolled out a breaking change without notice. Now instead of tracking Id we have Measurement Id (because we need it so much). It seems this breaks the Gatsby plugin. Can we get an update where the new measurement id can either swap for the tracking id or have a new parameter for Measurement Id?

Thanks!

rajatrao777 commented 3 years ago

Hi @btahir I have been facing same problem due to upgrade of google analytics. Found the solution for it. If you have existing deprecated analytics you need to update it from property column in GA console page.(I don't know exact process till end). If you are including to new project, check below steps.

btahir commented 3 years ago

@rajatrao777 That worked! Thanks :)

jake920220 commented 3 years ago

Hi @rajatrao777 , i've seen your solution but don't understand it, can u help me a little?

what you mean add G measurement id to plugin? There's no options to put G measurement id in gatsby-plugin-gtag document. did you mean add a G measurement id on trackingId field?

jake920220 commented 3 years ago

oh i've solve the problem. nvm, thx!

jeanmarc5592 commented 3 years ago

Hey Guys,

I'm currently using the gatsby-plugin-gtag Plugin as recommended above. Tracking works perfectly, thanks for that so far!

But I'm wondering how can I decline the tracking?

My current setup is:

gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-gtag`,
      options: {
        trackingId: "G-TRACKING ID",
        head: true,
        anonymize: true
      },
    },
    {
      resolve: `gatsby-plugin-gdpr-cookies`,
      options: {
        googleAnalytics: {
          trackingId: "G-TRACKING ID",
          cookieName: "gatsby-gdpr-google-analytics",
          anonymize: true,
        },
      },
      environments: ["development", "production"],
    },
    ...
  ]
}

In src/pages/index.js

import React from "react"
import CookieConsent from "react-cookie-consent"

export default function Home() {

  return (
    <div>
      <CookieConsent
        overlay
        location="bottom"
        buttonText="Accept"
        enableDeclineButton
        declineButtonText="Decline"
        cookieName="gatsby-gdpr-google-analytics"
      >
        We are using cookies to enhance this site ...
      </CookieConsent>
      ...
    </div>
  )
}

I know that the gatsby-plugin-gdpr-cookies is recommended to use in combination with the deprecated gatsby-plugin-google-analytics but is there an updated way to handle the optout?

Thanks a lot in advance!