-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to set dimensions across all requests #29
Comments
try sending your custom dimension as props of gtagOptions.
|
Had the same issue. You can keep your own reference to a dimensions object, and send it with events. import ReactGA from 'react-ga4';
// Keep this in memory in your module.
let currentDimensions= {};
// Update only changed properties.
function updateDimensions(dimensions: any) {
currentDimensions = {
dimension1: dimensions.dimension1 || currentDimensions.dimension1,
dimension2: dimensions.dimension1 || currentDimensions.dimension2,
}
}
// Send dimensions with events.
function sendEvent(event: any) {
ReactGA.event(event.action, {
event_category: event.category,
event_label: event.label,
value: event.value,
non_interaction: event.nonInteraction,
...currentDimensions,
}
}
// Example usage
function clickedButton() {
updateDimensions({ dimension2: 'new_value' });
sendEvent({ action: 'clicked_button', category: 'ui', label: 'buttons', value: 1 });
} |
@fehbari does sending it as an event, the custom dimensions works at session level? What scope are you using in your custom dimensions? I cannot use my custom dimension when initializing G4, anyone with another solution? |
@tloszabno there is another PR where they solve the problem. |
Was anyone able to log custom dimensions? |
Hello,
Previously I used
react-ga
lib where I could use ReactGA.set command ( in my case it wasReactGA.set({ dimension1: data.userJobTitle})
and after thatdimention1
with proper value was added to each event automatically.I tried to do a similar thing in
react-ga4
but it did not work.What I tried:
I also found in some reported issues that I need to add custom dimensions to the initialization phase like that:
but after all that combinations I see in the console only clear events without additional dimensions sent. Could you advise me on how I can set this dimension to be added to each event?
The text was updated successfully, but these errors were encountered: