codler / react-ga4

React Google Analytics 4
https://www.npmjs.com/package/react-ga4
266 stars 34 forks source link

I am using the below code and it's not working with the custom definition and getting "not set" as a value. But in the debug view I am getting the value in the "data layer". #83

Open priyabratap opened 1 month ago

priyabratap commented 1 month ago

I am using the below code and it's not working with the custom definition and getting "not set" as a value. But in the debug view I am getting the value in the "data layer". [image:debug-datalayer]

debug-datalayer
// Set user properties using ReactGA set
  ReactGA.set({
    user_name: userData?.name,
    pst_code: userData?.store?.code,
    pst_name: userData?.store?.name,
  });

I changed the above code and able to see the "data layer" as well as in the "hit details" [image:Hit Details]

Hit Details
ReactGA.gtag('set','user_properties',{
    user_name: userData?.name,
    pst_code: userData?.store?.code,
    pst_name: userData?.store?.name,
  });

ReactGA.set required Object only and can't use set method Do you know if it is something I need to pass like above? [I mean "user_properties" is important to pass]

Originally posted by @priyabratap in https://github.com/codler/react-ga4/issues/22#issuecomment-2276238436