title: error TS2304: Cannot find name 'ga'
body: <p>I am using Angular4 and trying to get analytics installed.
  I followed this guide: </p>
  
  <p><a href="https://blog.thecodecampus.de/angular-2-include-google-analytics-event-tracking/" rel="noreferrer">https://blog.thecodecampus.de/angular-2-include-google-analytics-event-tracking/</a></p>
  
  <p>But when I try to build my project, I get the error:</p>
  
  <blockquote>
    <p>error TS2304: Cannot find name 'ga'.</p>
  </blockquote>
  
  <p>I have checked my package.json and I have <code>"@types/google.analytics": "0.0.38",</code> installed in my <strong>devDependencies</strong>.
  When I start typing I can see that intellisense knows it's a <code>UniversalAnalytics.ga</code> type, but I cannot get it to work.</p>
  
  <p>I tried changing my code to this:</p>
  
  <pre><code>this.router.events.subscribe(event =&gt; {
    if (event instanceof NavigationEnd) {
      let ga: Function;
      ga('set', 'page', event.urlAfterRedirects);
      ga('send', 'pageview');
    }
  });
  </code></pre>
  
  <p>It compiles, but in the console.log I get an error stating:</p>
  
  <blockquote>
    <p>Uncaught (in promise): TypeError: ga is not a function</p>
  </blockquote>
  
  <p>If I change to this:</p>
  
  <pre><code>this.router.events.subscribe(event =&gt; {
    if (event instanceof NavigationEnd) {
      let ga: any;
      ga('set', 'page', event.urlAfterRedirects);
      ga('send', 'pageview');
    }
  });
  </code></pre>
  
  <p>I get the same error.
  Does anyone know why?</p>
  
  <p>Here is the complete code:</p>
  
  <pre><code>import { Component, OnInit, AfterViewChecked, AfterViewInit } from "@angular/core";
  import { ActivatedRoute, Params, Router, NavigationEnd } from "@angular/router";
  
  import { ResultsService } from "./shared/results.service";
  import { HeightService } from "./shared/height.service";
  
  @Component({
    selector: 'bzRoot',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
  })
  export class AppComponent implements OnInit, AfterViewChecked, AfterViewInit {
    constructor(
      private _activatedRoute: ActivatedRoute,
      private _resultsService: ResultsService,
      private _heightService: HeightService,
      public router: Router) {
    }
  
    ngOnInit() {
      this._activatedRoute.queryParams.subscribe((params: Params) =&gt; {
        // Only update the elq if it changes (remember: changing a parameter causes the page to refresh)
        var elq = params['elqid'];
        if (elq) {
          this._resultsService.elq = elq;
        }
      });
    }
  
    ngAfterViewChecked() {
      this._heightService.resize();
    }
  
    ngAfterViewInit() {
      //this.router.events.subscribe(event =&gt; {
      //  if (event instanceof NavigationEnd) {
      //    let ga: Function;
      //    ga('set', 'page', event.urlAfterRedirects);
      //    ga('send', 'pageview');
      //  }
      //});
    }
  }
  </code></pre>