Google Analytics Autotrack and JS linter

I’m trying to use Google Analytics autotrack script and am following the instructions as per their site but when I try and compile it states ga is undefined in the linter error (3:1 error 'ga' is not defined no-undef).

// /resources/assets/scripts/autoload/Autotrack.js
import 'autotrack';

ga('create', 'UA-XXXX-1', 'auto');

I assume ga is defined in the autotrack file I’m importing but I’m guessing the linter doesn’t know this. Is there a way around this or a way of telling the linter what ga is?

I read the js lint documentation and just add global ga to the top of the file

/*global ga*/
/*eslint no-undef: "error"*/

import 'autotrack';
ga('create', 'UA-test-1', 'auto'); 

Open .eslintrc.js and add it to ga to globals:

  "globals": {
    "wp": true,
    "ga": true,
  },
4 Likes