Should Google analytics tracking ID be kept secret or can I embed it into the build

Viewed 308

Is it safe to use Google's analytics tracking id in production. I'm assuming it's not a secret and I can do something like:

const location = useLocation();

  useEffect(() => {
    ReactGA.initialize("UA-MY-GA-ID"); // Analytics tracking ID
    ReactGA.ga('send', 'pageview', location.pathname);
  }, [location]);
1 Answers

Yes, it's safe to use in production. In fact, it's necessary to use it to identify the client.

Not satisfied? Check out the HTML source of any popular website - it probably uses Google Analytics and you'll see the GA intializer with the tracking ID.

Related