4

I am using React-GA, and it works as expected, but I have a requirement to put user email in event tracking:

I see this in the example:

ReactGA.event({
  category: 'Editing',
  action: 'Deleted Component',
  label: 'Game Widget'
});

I have a email of each user as a string. Where do I better put it in the request?

Sergei Basharov
  • 51,276
  • 73
  • 200
  • 335

3 Answers3

9

yes i am with @davids answer but i want to give more proper answer.

first you need to import react-ga module

import ReactGA from 'react-ga';

and than whenever you initialize google analytics you can set userId there

ReactGA.initialize('UA-000000-01', {
  gaOptions: {
    userId: xxx-xxx-xxx-xxx
  }
});

Or if you want to set userId after user logs into your system, than you can do the following way

1. initialize google analytics without userId

ReactGA.initialize('UA-000000-01');

2. and just after login you can set userId

ReactGA.set({ userId: 123 });

ref: https://github.com/react-ga/react-ga#reactgasetfieldsobject

Vinay Pandya
  • 3,020
  • 2
  • 26
  • 42
5

You should not use an email address as that is personally identifiable information and as such to track it in GA is against Google's terms and conditions.

Joe Law
  • 265
  • 3
  • 11
  • Not only is it not secure and against the ToS for Analytics, if you try to set email address as the userId it will identify this and then not accept it at all. Something like a `username` field, something unique but doesn't identify the person, should work better. – Tyler Russell Jun 18 '19 at 16:38
  • @TylerRussell where can i get more information about this – rnewed_user Aug 16 '23 at 20:29
  • @JoeLaw where can i get more information about this – rnewed_user Aug 16 '23 at 20:29
1

User ID ("userId") should be setup in the "initialize" or "set" GA command, not in an event. User ID is scoped to the user, so it shouldn't ever change for a user. Also, you'll have convert email to an anonymous (non-PII) id before it's used as userId

ReactGA.initialize('UA-000000-01', { debug: true, titleCase: false, gaOptions: { userId: 123 } });

User ID doc: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#userId

davids
  • 21
  • 3