title: Integrating Instana error tracking into an Angular 2 application
body: <p>I'm trying to integrate Instana into an application. More specifically I'm trying to send errors from my Angular app to Instana. I have my code 'working' so this is kind of a question about best practice.</p>
  
  <p>Instana's <a href="https://docs.instana.io/products/website_monitoring/backendCorrelation/#page-load-backend-correlation" rel="nofollow noreferrer">Backend Correlation documentation</a> defines functions in 'window' from what I understand. I've set something similar to this in my index.html.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script&gt;
    (function(i,s,o,g,r,a,m){i['InstanaEumObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//eum.instana.io/eum.min.js','ineum');
  
    ineum('apiKey', 'someKey');
    ineum('traceId', 'backendTraceId'); //replace 'backendTraceId with the appropriate expression for retrieval
  &lt;/script&gt;
  </code></pre>
  
  <p>The issue I have is when I try to follow Instana's guide for <a href="https://docs.instana.io/products/website_monitoring/api/#angular-2-integration" rel="nofollow noreferrer">Angular 2+ Integration</a> regarding error tracking, where they call one of the methods that I can access from window. The guide just straight up calls the function <code>ineum(...)</code> by itself. When I try to do this, my project wouldn't compile.</p>
  
  <pre><code>class CustomErrorHandler implements ErrorHandler {
    handleError(error) {
      ineum('reportError', error);
  
      // Continue to log caught errors to the console
      console.error(error);
    }
  }
  </code></pre>
  
  <p>My current fix is: <strong><code>(&lt;any&gt;window).ineum('reportError', errorContext);</code></strong> But I was looking at <a href="https://stackoverflow.com/questions/10156474/javascript-calling-a-function-on-window-object">another stack overflow question</a> where they accessed window differently in their javascript. </p>
  
  <ol>
  <li>Is typecasting window to 'any' a bad practice?</li>
  <li>Is it better to try <code>window['ineum'](...)</code> or is that just a syntax preference?</li>
  <li>Is it better to try to define functions in another file, say an Instana service of sorts, and then use that service in the index.html script and CustomErrorHandler or keep it in the window? (Though this one may be a little tricker for me to figure out)</li>
  </ol>
  
  <p>Sorry for my confusion as this may not be an actual issue because my code is 'working' but I just want clarification on this. I'm not sure if I just didn't follow Instana's guides correctly but this was the best of what I could find. I tried reaching out via their contact page but I haven't received a response quite yet. </p>