Application Insightes in SharePoint

Iron Contributor

Hey,

I need to put the first two lines with in the script block. How I can do this?

 

I like to bring the code Add-PnPJavaScriptLink in all SP sites in the sitecollection.

 

<SharePoint:ScriptLink ID="ScriptLink1" name="SP.js" runat="server" localizable="false" loadafterui="true" />

<SharePoint:ScriptLink ID="ScriptLink2" name="SP.UserProfiles.js" runat="server" localizable="false" loadafterui="true" />

 

 

var personProperties;

 

// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.

SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');

 

function getUserProperties() {

    // Get the current client context and PeopleManager instance.

    var clientContext = new SP.ClientContext.get_current();

    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

 

    // Get user properties for the target user.

    // To get the PersonProperties object for the current user, use the

    // getMyProperties method.

 

    personProperties = peopleManager.getMyProperties();

 

    // Load the PersonProperties object and send the request.

    clientContext.load(personProperties);

    clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);

}

 

// This function runs if the executeQueryAsync call succeeds.

function onRequestSuccess() {

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:"XXXX"

    });

    window.appInsights=appInsights;

    appInsights.trackPageView(document.title,window.location.href, {User: personProperties.get_displayName()});

}

 

// This function runs if the executeQueryAsync call fails.

function onRequestFail(sender, args) {

}

 

Regards

Stefan

0 Replies