/* eslint-disable react/forbid-prop-types */
import { useEffect } from "react";
import ReactGA from "react-ga4";
import PropTypes from "prop-types";

var GoogleAnalytics4 = function GoogleAnalytics4(props) {
  var userId = props.userId,
      userData = props.userData,
      analytics4Id = props.analytics4Id,
      isSandbox = props.isSandbox,
      debug = props.debug,
      children = props.children,
      onInit = props.onInit;
  useEffect(function () {
    if (!isSandbox) {
      ReactGA.initialize(analytics4Id, {
        debugMode: debug
      });
      ReactGA.ga(function (tracker) {
        var clientId = tracker.get("clientId");
        onInit({
          client_id: clientId
        });
      });
    }
  }, []);
  useEffect(function () {
    if (userId) {
      ReactGA.gtag("set", "user_properties", {
        "clever_id": userId
      });
    }
  }, [userId]);
  useEffect(function () {
    if (userData) {
      ReactGA.gtag("set", "user_properties", userData);
    }
  }, [userData]);
  return children;
};

GoogleAnalytics4.propTypes = {
  analytics4Id: PropTypes.string.isRequired,
  debug: PropTypes.bool,
  isSandbox: PropTypes.bool,
  userData: PropTypes.object,
  children: PropTypes.node,
  onInit: PropTypes.func
};
GoogleAnalytics4.defaultProps = {
  debug: false,
  isSandbox: true,
  children: null,
  onInit: function onInit() {}
};
export default GoogleAnalytics4;