Application Insightes in SharePoint

%3CLINGO-SUB%20id%3D%22lingo-sub-185761%22%20slang%3D%22en-US%22%3EApplication%20Insightes%20in%20SharePoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-185761%22%20slang%3D%22en-US%22%3E%3CP%3EHey%2C%3C%2FP%3E%3CP%3EI%20need%20to%20put%20the%20first%20two%20lines%20with%20in%20the%20script%20block.%20How%20I%20can%20do%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20like%20to%20bring%20the%20code%20Add-PnPJavaScriptLink%20in%20all%20SP%20sites%20in%20the%20sitecollection.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSCRIPTLINK%20id%3D%22%26quot%3BScriptLink1%26quot%3B%22%20name%3D%22%26quot%3BSP.js%26quot%3B%22%20runat%3D%22%26quot%3Bserver%26quot%3B%22%20localizable%3D%22%26quot%3Bfalse%26quot%3B%22%20loadafterui%3D%22%26quot%3Btrue%26quot%3B%22%3E%3C%2FSCRIPTLINK%3E%3C%2FP%3E%3CP%3E%3CSCRIPTLINK%20id%3D%22%26quot%3BScriptLink2%26quot%3B%22%20name%3D%22%26quot%3BSP.UserProfiles.js%26quot%3B%22%20runat%3D%22%26quot%3Bserver%26quot%3B%22%20localizable%3D%22%26quot%3Bfalse%26quot%3B%22%20loadafterui%3D%22%26quot%3Btrue%26quot%3B%22%3E%3C%2FSCRIPTLINK%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Evar%20personProperties%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2F%20Ensure%20that%20the%20SP.UserProfiles.js%20file%20is%20loaded%20before%20the%20custom%20code%20runs.%3C%2FP%3E%3CP%3ESP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties%2C%20'SP.UserProfiles.js')%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Efunction%20getUserProperties()%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Get%20the%20current%20client%20context%20and%20PeopleManager%20instance.%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20clientContext%20%3D%20new%20SP.ClientContext.get_current()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20peopleManager%20%3D%20new%20SP.UserProfiles.PeopleManager(clientContext)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Get%20user%20properties%20for%20the%20target%20user.%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20To%20get%20the%20PersonProperties%20object%20for%20the%20current%20user%2C%20use%20the%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20getMyProperties%20method.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20personProperties%20%3D%20peopleManager.getMyProperties()%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Load%20the%20PersonProperties%20object%20and%20send%20the%20request.%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20clientContext.load(personProperties)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20clientContext.executeQueryAsync(onRequestSuccess%2C%20onRequestFail)%3B%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2F%20This%20function%20runs%20if%20the%20executeQueryAsync%20call%20succeeds.%3C%2FP%3E%3CP%3Efunction%20onRequestSuccess()%20%7B%3C%2FP%3E%3CP%3Evar%20appInsights%3Dwindow.appInsights%7C%7Cfunction(config)%7B%3C%2FP%3E%3CP%3Efunction%20s(config)%7Bt%5Bconfig%5D%3Dfunction()%7Bvar%20i%3Darguments%3Bt.queue.push(function()%7Bt%5Bconfig%5D.apply(t%2Ci)%7D)%7D%7Dvar%20t%3D%7Bconfig%3Aconfig%7D%2Cr%3Ddocument%2Cf%3Dwindow%2Ce%3D%22script%22%2Co%3Dr.createElement(e)%2Ci%2Cu%3Bfor(o.src%3Dconfig.url%7C%7C%22%2F%2Faz416426.vo.msecnd.net%2Fscripts%2Fa%2Fai.0.js%22%2Cr.getElementsByTagName(e)%5B0%5D.parentNode.appendChild(o)%2Ct.cookie%3Dr.cookie%2Ct.queue%3D%5B%5D%2Ci%3D%5B%22Event%22%2C%22Exception%22%2C%22Metric%22%2C%22PageView%22%2C%22Trace%22%5D%3Bi.length%3B)s(%22track%22%2Bi.pop())%3Breturn%20config.disableExceptionTracking%7C%7C(i%3D%22onerror%22%2Cs(%22_%22%2Bi)%2Cu%3Df%5Bi%5D%2Cf%5Bi%5D%3Dfunction(config%2Cr%2Cf%2Ce%2Co)%7Bvar%20s%3Du%26amp%3B%26amp%3Bu(config%2Cr%2Cf%2Ce%2Co)%3Breturn%20s!%3D%3D!0%26amp%3B%26amp%3Bt%5B%22_%22%2Bi%5D(config%2Cr%2Cf%2Ce%2Co)%2Cs%7D)%2Ct%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D(%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20instrumentationKey%3A%22XXXX%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20window.appInsights%3DappInsights%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20appInsights.trackPageView(document.title%2Cwindow.location.href%2C%20%7BUser%3A%20personProperties.get_displayName()%7D)%3B%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2F%20This%20function%20runs%20if%20the%20executeQueryAsync%20call%20fails.%3C%2FP%3E%3CP%3Efunction%20onRequestFail(sender%2C%20args)%20%7B%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3EStefan%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-185761%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Regular 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