locked
Loading JS from an external file RRS feed

  • Question

  • Hi,

    for specific reasons I can't modify the source code of the aspx page. I can only add a link to an external JS file. After trying to to that, in IE i see the following traces:

    Failed to send telemetry:
    {"itemsRecieved":1,"itemsAccepted":1,"errors":[]}

    So the tracking code kicks in, but for some reason, loading a source code from external JS file prevents it from sending events.

    Any ideas about the correct way to load AppInsight JS from the file? 

    Thanks,

    Andrei

    Wednesday, January 7, 2015 11:26 AM

Answers

  • Try to insert your external js file as like this ....It worked for me...

    <script type="text/javascript" src="<%= Page.ResolveClientUrl("~/siteassets/Insightanalytics.js")%>"></script>

    If it works fine don't forget to mark it has answer.....


    Thanks & Regards RAJENDRAN M

    • Proposed as answer by Alex Bulankou Thursday, January 8, 2015 4:42 PM
    • Marked as answer by Alex Bulankou Monday, January 12, 2015 6:20 PM
    Wednesday, January 7, 2015 12:58 PM

All replies

  • Hi,

      Could you please show me the line how you are linked external JS file in .aspx page...So that i can suggest you......


    Thanks & Regards RAJENDRAN M

    Wednesday, January 7, 2015 12:08 PM
  • <script type="text/javascript" src="/siteassets/insightanalytics.js"></script>

    the content of the file

    var appInsights=window.appInsights||function(config){ function s(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},r=document,f=window,e="script",o=r.createElement(e),i,u;for(o.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",r.getElementsByTagName(e)[0].parentNode.appendChild(o),t.cookie=r.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)s("track"+i.pop());return config.disableExceptionTracking||(i="onerror",s("_"+i),u=f[i],f[i]=function(config,r,f,e,o){var s=u&&u(config,r,f,e,o);return s!==!0&&t["_"+i](config,r,f,e,o),s}),t
        }({
            instrumentationKey:"SKIPED"
        });
        
    window.appInsights = appInsights;
    // executed when SP load completes
    SP.SOD.executeOrDelayUntilEventNotified(function () {
         window.appInsights.trackPageView();
    }, "sp.bodyloaded");

    BTW, after the page is loaded, if I open IE Dev tools, and try to manually trigger 

    window.appInsights.trackPageView();
    I see the same message. Basically 
    window.appInsights
    is defined correctly. I can imagine it has something to do with the telemetry proxy, and perhaps the order of loading.



    Wednesday, January 7, 2015 12:21 PM
  • Try to insert your external js file as like this ....It worked for me...

    <script type="text/javascript" src="<%= Page.ResolveClientUrl("~/siteassets/Insightanalytics.js")%>"></script>

    If it works fine don't forget to mark it has answer.....


    Thanks & Regards RAJENDRAN M

    • Proposed as answer by Alex Bulankou Thursday, January 8, 2015 4:42 PM
    • Marked as answer by Alex Bulankou Monday, January 12, 2015 6:20 PM
    Wednesday, January 7, 2015 12:58 PM