Skip to content

Commit

Permalink
Merge pull request react-ga#402 from hilezir/dev
Browse files Browse the repository at this point in the history
add options.redactEmail, fix react-ga#144
  • Loading branch information
SimeonC authored May 29, 2020
2 parents 5c1ae8c + 7e00c97 commit bc331fc
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.9.0
12.13.1
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ ReactGA.initialize([{
|options.testMode| `Boolean`. Optional. Defaults to `false`. Enables test mode. See [here](https://github.com/react-ga/react-ga#test-mode) for more information.|
|options.standardImplementation| `Boolean`. Optional. Defaults to `false`. Enables loading GA as google expects it. See [here](https://github.com/react-ga/react-ga#standard-implementation) for more information.|
|options.useExistingGa| `Boolean`. Optional. Skips call to `window.ga()`, assuming you have manually run it.
|options.redactEmail| `Boolean`. Optional. Defaults to `true`. Enables redacting a email as the string that in "Event Category" and "Event Action".

If you are having additional troubles and setting `debug = true` shows as working please try using the [Chrome GA Debugger Extension](https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna).
This will help you figure out if your implementation is off or your GA Settings are not correct.
Expand Down
361 changes: 268 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
"react": "^15.6.2",
"react-addons-test-utils": "^15.0.1",
"react-dom": "^15.0.1",
"react-router": "4.4.0",
"react-router-dom": "4.4.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"rewire": "^2.5.2",
"should": "^12.0.0",
"sinon": "^3.2.1",
Expand Down
7 changes: 6 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let _debug = false;
let _titleCase = true;
let _testMode = false;
let _alwaysSendToDefaultTracker = true;
let _redactEmail = true;

const internalGa = (...args) => {
if (_testMode) return TestModeAPI.ga(...args);
Expand All @@ -33,7 +34,7 @@ const internalGa = (...args) => {
};

function _format(s) {
return format(s, _titleCase);
return format(s, _titleCase, _redactEmail);
}

function _gaCommand(trackerNames, ...args) {
Expand Down Expand Up @@ -68,6 +69,10 @@ function _initialize(gaTrackingID, options) {
_titleCase = false;
}

if (options.redactEmail === false) {
_redactEmail = false;
}

if (options.useExistingGa) {
return;
}
Expand Down
18 changes: 8 additions & 10 deletions src/utils/format.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import mightBeEmail from './mightBeEmail';
import redactEmail from './redactEmail';
import toTitleCase from './toTitleCase';
import warn from './console/warn';

const redacted = 'REDACTED (Potential Email Address)';
export default function format(s = '', titleCase, redactingEmail = true) {
let _str = s || '';

export default function format(s, titleCase) {
if (mightBeEmail(s)) {
warn('This arg looks like an email address, redacting.');
return redacted;
if (titleCase) {
_str = toTitleCase(s);
}

if (titleCase) {
return toTitleCase(s);
if (redactingEmail) {
_str = redactEmail(_str);
}

return s;
return _str;
}
13 changes: 13 additions & 0 deletions src/utils/redactEmail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import warn from './console/warn';
import mightBeEmail from './mightBeEmail';

const redacted = 'REDACTED (Potential Email Address)';

export default function redactEmail(string) {
if (mightBeEmail(string)) {
warn('This arg looks like an email address, redacting.');
return redacted;
}

return string;
}
8 changes: 8 additions & 0 deletions test/utils/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import sinon from 'sinon';
import format from '../../src/utils/format';

describe('format()', function () {
it('should not format when redactingEmail is false', function () {
const titleCase = false;
const redactingEmail = false;
format('[email protected]', titleCase, redactingEmail).should.eql('[email protected]');
format('[email protected]', titleCase, redactingEmail).should.eql('[email protected]');
format('[email protected]', titleCase, redactingEmail).should.eql('[email protected]');
});

it('should not format email addresses', function () {
sinon.stub(console, 'warn');
console.warn.callCount.should.eql(0);
Expand Down
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface InitializeOptions {
gaOptions?: GaOptions;
alwaysSendToDefaultTracker?: boolean;
standardImplementation?: boolean;
/** Optional. Defaults to `true`. Enables redacting a email as the string that in "Event Category" and "Event Action". */
redactEmail?: boolean;
useExistingGa?: boolean;
}

Expand Down

0 comments on commit bc331fc

Please sign in to comment.