Sure! So, it looks like the piece you might be missing is how to use the ReactGA.gtag
function to send user properties. This can be done directly whenever you want to track some custom analytics data, or you can save yourself some time and effort by setting it up in a utility function.
To put it simply, the gtag
function takes a string and an object of data to send back to Google Analytics. You can use something like "set", "user_properties"
for the string, and then put whatever data you want in the object. After that, it’s as simple as just calling the function whenever you want to send data.
Here’s an example of tracking whether a user’s account is verified or not, and what their name is:
`jsx
import ReactGA from “react-ga4”;
ReactGA.gtag(“set”, “user_properties”, {
account_verified: true,
});
ReactGA.gtag(“set”, “user_properties”, {
name: “John”,
});
`
You can also create utility functions to simplify tracking your properties, like this:
`jsx
import ReactGA from “react-ga4”;
export const setAccountProperty = (value: boolean) => {
ReactGA.gtag(“set”, “user_properties”, {
account_verified: value,
});
};
export const setNameProperty = (value: string) => {
ReactGA.gtag(“set”, “user_properties”, {
name: value,
});
};
`
After setting up everything in your app, you can go to your Google Analytics dashboard and click on DebugView to check if everything’s working fine.