-
Notifications
You must be signed in to change notification settings - Fork 119
Allow Option to Include JavaScript from a Seperate File #120
Comments
You can host it in your own domain as mentioned in this blog post. Hosting it on CDN wouldn't work as desired - see explanation of it here: Specifically this
|
So you can have a separate file, as long as it's in the same domain. I suppose you could also use the script hash or nonce to get inline scripts working with CSP securely. Either way is not great but worth it to get app insights working. |
In aspnet5 it's very easy to implement. Something like pseudocode:
and than just reference ai.0.js from the app's domain |
BTW, thanks for reporting the issue and using Application Insights! |
Even better you can read the instrumentation key from config.json in your gulpfile.js file, then use gulp-replace to inject the key into the app insights JavaScript file. I intend to add an app insights feature implemented as above to ASP.Net MVC Boilerplate this weekend. |
Cool. Send me a link BTW, in my example pseudo code I should have been using class |
Will do. The basic idea is:
The application-insights.js file under the scripts folder should look like this:
|
Consider using this package to get snippet from if possible.
|
That package has a prefix.html file with the script snippet in it. Is that what you mean? If so, being a .html file, it's not very easy to consume from Gulp. I would have to strip out the It would be nice to have a NuGet package that I can take the .js from, rather than having to keep it up to date myself. Could this package be updated to include this? |
Feel free to send PR for our NuGet. NuGet definition is here: https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/NuGet.JavaScript/Package.nuspec |
I don't mind raising a PR. Comments added to your new issue. |
@SergeyKanzhelev I've updated the ASP.NET MVC Boilerplate project template. You can now create a new project and enable Application Insights by selecting the feature below: It uses the gulp-replace method I explained above, so you can now try it out. I have taken a copy of your script and created an application-insights.js file but ideally this would be in Bower. |
FYI, I spotted an applicationinsights-js bower package with the snippet.js file in it. You can now use that file in ASP.NET Core. |
@SergeyKanzhelev In your early message you mentioned that hosting the app insights snippet on a CDN would not work but if I add the |
@RehanSaeed I think this would work. However we still want Application Insights API to work before scripts loaded. Like "appInsights.trackTrace()". So you can report that something happened during the loading time. So we still want a snippet to be part of a page and it's easier to include |
Talking of a blog post, I wrote 'Making Application Insights Fast and Secure'. |
For those using the Content-Security-Policy (CSP) HTTP header, including inline JavaScript is not allowed. Would it be possible for Microsoft to create and use a CDN which returns the client side JavaScript? The instrumentation key could be included in the query string portion of the URL. So something like this:
The text was updated successfully, but these errors were encountered: