Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Check for debug flag before logging in ga()
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun committed Sep 14, 2016
1 parent ae25344 commit 4cfd94c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-ga",
"version": "2.1.1",
"version": "2.1.2",
"homepage": "https://github.com/react-ga/react-ga",
"authors": [
"Tay Yang Shun <tay.yang.shun@gmail.com>"
Expand Down
7 changes: 5 additions & 2 deletions dist/react-ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ var ReactGA = {
ga: function () {
if (arguments.length > 0) {
ga.apply(this, arguments);
log('called ga(arguments);');
log('with arguments: ' + JSON.stringify([].slice.apply(arguments)));
if (_debug) {
log('called ga(\'arguments\');');
log('with arguments: ' + JSON.stringify([].slice.apply(arguments)));
}

return;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/react-ga.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-ga",
"version": "2.1.1",
"version": "2.1.2",
"description": "React Google Analytics Module.",
"main": "src/index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ var ReactGA = {
ga: function () {
if (arguments.length > 0) {
ga.apply(this, arguments);
log('called ga(arguments);');
log('with arguments: ' + JSON.stringify([].slice.apply(arguments)));
if (_debug) {
log('called ga(\'arguments\');');
log('with arguments: ' + JSON.stringify([].slice.apply(arguments)));
}

return;
}

Expand Down
9 changes: 9 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ describe('react-ga', function () {
['send', 'pageview', '/mypage']
]);
});

it('should output debug info, if debug is on', function () {
ReactGA.initialize('foo', { debug: true });
ReactGA.ga('send', 'pageview', '/mypage');
console.info.args.should.eql([
['[react-ga]', "called ga('arguments');"],
['[react-ga]', 'with arguments: ["send","pageview","/mypage"]']
]);
});
});

/**
Expand Down

0 comments on commit 4cfd94c

Please sign in to comment.