digital-analytics-program / gov-wide-code

Provides a set of javascript files and documentation to implement web analytics on US federal websites
http://www.digital.gov/dap
102 stars 54 forks source link

Fixed the optional eventValue parameter. #42

Closed jpoika closed 1 year ago

jpoika commented 8 years ago

The Problem: Event transactions were being ignored by Google Analytics.

The Cause: Using Google Analytics Debugger (Google Chrome Browser Extension), we determined that the value NaN sent to Google Analytics causing a JavaScript warning.

When the fourth parameter (eventValue) is undefined, which is then passed as NaN into _sendEvent (eventValue), where it is eventually passed into ga function. This function expected eventValue to only be a number.

The JavaScript warning is "Expected a number value for the field: "eventValue", but found: "number".

The Solution: The changes to the _sendEvent line correctly identify when the parameter is undefined and will pass 0 to the function, insuring that only a number is passed to Google Analytics. I updated the fourth parameter on the gas function for events.

Testing: Use the following JavaScript function call in order to test. Observe the results on the console, where Google Analytics Debugger provides results"

If you are not using the debugger, look for "ev: NaN" under collect?... in your browsers Network log. Select "collect?...." and look under "Query String Parameters"

gas('send', 'event', 'test-category', 'test-action', 'test-label');

smarina04 commented 1 year ago

The DAP code has been updated since 2016. Closing this issue.