Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected dangling '_' in '_gaq' [duplicate]

I'm trying to validate my Google Analytics code using JSLint but I get a lot of error messages:

The code:

/*global document */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24389816-1']);
_gaq.push(['_trackPageview']);

(function () {
    var s,
        ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);
}());

Error messages:

Problem at line 2 character 5: Unexpected dangling '_' in '_gaq'.

var _gaq = _gaq || [];

Problem at line 2 character 12: Unexpected dangling '_' in '_gaq'.

var _gaq = _gaq || [];

Problem at line 3 character 1: Unexpected dangling '_' in '_gaq'.

_gaq.push(['_setAccount', 'UA-24389816-1']);

Problem at line 4 character 1: Unexpected dangling '_' in '_gaq'.

_gaq.push(['_trackPageview']);

What's wrong? Thank you.

like image 872
thom Avatar asked Jul 06 '11 13:07

thom


2 Answers

The jslint default settings do not allow an underscore at the beginning of variable names. This is because in other languages, it implies a private variable, something which JavaScript does not support.

To remove the warnings, you can add nomen: true to the options of jslint. Otherwise, you will have to tolerate the warnings.

As far as I'm aware, Google does not offer a way to rename this variable at this time.

like image 87
Pete Avatar answered Oct 21 '22 02:10

Pete


For JSLint or JSHint, set nomen: false to ignore this warning.

like image 1
deepwell Avatar answered Oct 21 '22 00:10

deepwell