-
Notifications
You must be signed in to change notification settings - Fork 71
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
Gtag, access user-id config inside redux-beacon, React #330
Comments
Hi @MatteoGioioso. Thanks for taking the time to open up a feature request! We don't currently have that feature, but I'm totally open to adding it in. Here's what I'm thinking as an implementation plan: Add a line like this on L21: const userTracking = events.filter(event => event.type === 'userId');
Then anywhere below that line (could be before, after, or between the userTracking.forEach(event => {
gtag('config', defaultTrackingId, {
'user_id': event.userId
});
});
Then a unit test to verify that it'll work: describe('userTracking', () => {
test("given { type: 'userId', userId: 'some user id' }", () => {
const events = [{ type: 'userId', userId: 'some user id' }];
const target = GoogleAnalyticsGtag('GA_TRACKING_ID');
target(events);
expect(window.gtag).toHaveBeenCalledWith('config', 'GA_TRACKING_ID', { user_id: 'some user id' });
});
}); We should probably also add an event helper to make the feature easy to use. const trackUserId = (
eventDef: EventDefinition<{
userId: string;
}>
): EventDefinition => (action, prevState, nextState) => {
const event = eventDef(action, prevState, nextState);
return {
type: 'userId',
userId: event.userId,
}
}; Last but not least, we'll need docs! |
@ttmarek So, as I have understood correctly you want to add it as an event? For now I have monkey patched like this
Also another question. Instead of
I could try to make a pull request, later this week, if you are ok. Thanks |
Hey @MatteoGioioso. Thanks for getting back to me. Yeah, I think it makes more sense as an event no? In that way we could set the user_id on the fly. If we didn't set it as an event then there'd be no way to switch a user right? The docs use |
This is a...
Which version of Redux Beacon are you using?
Which target(s) are you using?
...Describe the feature or documentation you wish you had.
Hello
I would like to track the user_id with gtag
I am using React and I unfortunately cannot access my the currently logged user_id in my index.html.
Is is possible to set the user_id inside redux-beacon?
Something like this perhaps:
GoogleAnalyticsGtag(trackingId, {user_id: 'USER_ID'});
If not, is it possible to add this feature?
Thanks
Can you help out?
The text was updated successfully, but these errors were encountered: