Learn business growth with Google Analytics 4 Forums Google Analytics 4 How can I send user properties in React-GA4 for Google Analytics? Reply To: How can I send user properties in React-GA4 for Google Analytics?

  • Sophia

    Member
    24 May 2023 at 11:10 am

    From looking at your initialization, I see that you’re using gaOptions for user properties. However, gaOptions is actually used to set up fields that control how the pageview hit is processed, so it’s not the right place to put user properties.

    To send user properties, you should use the set command, which is used to set user-level and session-level dimensions and metrics. You can use it similar to how you’d do in Google Analytics’ JavaScript (gtag.js). It would look something like the following:

    `
    ReactGA.set({ ‘user_role’: userRole });
    `

    Keep in mind that you first need to create these user properties in Google Analytics and use the exact name you set there. In the new GA4 property, you’ll need to set it up under User-Scoped Custom Definitions.

    However, as per react-ga4 official documentation, please note that set command is not currently supported. Therefore, you might need to leverage gtag.js directly or use another library that supports GA4 user properties if this is mandatory for your application.

    This is a rapidly developing area – make sure you are on top of the latest releases and checking the react-ga4 GitHub page for any updates.