Skip to content

Instantly share code, notes, and snippets.

AppInsights.trackPageView(
"", /* (optional) page name */
"", /* (optional) page url if available */
{ }, /* (optional) dimension dictionary */
{ }, /* (optional) metric dictionary */
0 /* page view duration in milliseconds */
);
@chrisobriensp
chrisobriensp / COBSPFxApplicationCustomizer_AppInsights_Simple.ts
Created August 9, 2017 22:00
Adds Azure App Insights to every page as part of an SPFx Application Customizer.
export default class AppInsightsCustomizerApplicationCustomizer
extends BaseApplicationCustomizer<IAppInsightsCustomizerApplicationCustomizerProperties> {
@override
public onInit(): Promise<void> {
/* update with YOUR App Insights key: */
let appInsightsKey: string = "bd755e10-2e26-4580-8d58-446c0dd329fe";
AppInsights.downloadAndSetup({ instrumentationKey: appInsightsKey });
@chrisobriensp
chrisobriensp / COBSPFxApplicationCustomizer_GoogleAnalytics.ts
Last active August 9, 2017 22:02
Adds Google Analytics to every page as part of an SPFx Application Customizer.
export default class CobSpFxGaApplicationCustomizer
extends BaseApplicationCustomizer<ICobSpFxGaApplicationCustomizerProperties> {
@override
public onInit(): Promise<void> {
/* update with YOUR Google Analytics tracking code: */
let trackingCode: string = "UA-104299656-1";
let scriptTagGA: HTMLScriptElement = document.createElement("script");
scriptTagGA.text = `
@chrisobriensp
chrisobriensp / AppCustomizer.module.scss
Last active September 2, 2017 10:54
Corresponding SCSS file for an SPFx Application Customizer which provides a global page header/footer.
.app {
.header {
height:60px;
text-align:center;
line-height:2.5;
font-weight:bold;
display: flex;
align-items: center;
justify-content: center;
background-color: goldenrod;
@chrisobriensp
chrisobriensp / COBSPFxApplicationCustomizer_PageHeaderFooter.ts
Last active February 20, 2018 16:44
An SPFx Application Customizer which adds some simple text to the header/footer of modern pages.
import { override } from '@microsoft/decorators';
import { Log } from '@microsoft/sp-core-library';
import {
BaseApplicationCustomizer, PlaceholderContent, PlaceholderName, PlaceholderProvider
} from '@microsoft/sp-application-base';
import * as strings from 'Cob12ApplicationCustomizerStrings';
import styles from './AppCustomizer.module.scss';
import { escape } from '@microsoft/sp-lodash-subset';
@chrisobriensp
chrisobriensp / COBSPFxApplicationCustomizer_GlobalJS.ts
Last active June 11, 2017 19:28
Adds some JS to every page as part of an SPFx Application Customizer.
export default class CobGlobalJsApplicationCustomizer
extends BaseApplicationCustomizer<ICobGlobalJsApplicationCustomizerProperties> {
private _externalJsUrl: string = "https://sharepointnutsandbolts.azurewebsites.net/scripts/SPFxGlobalScript.js";
@override
public onInit(): Promise<void> {
console.log(`CobGlobalJsApplicationCustomizer.onInit(): Entered.`);
let scriptTag: HTMLScriptElement = document.createElement("script");
.helloWorld {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.result {
margin-top: 10px;
}
@chrisobriensp
chrisobriensp / CobSpFxAzureFunctionWebPart.ts
Last active April 13, 2021 02:16
A SharePoint Framework (SPFx) web part which calls an Azure function and processes the response.
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { HttpClient, SPHttpClient, HttpClientConfiguration, HttpClientResponse, ODataVersion, IHttpClientConfiguration, IHttpClientOptions, ISPHttpClientOptions } from '@microsoft/sp-http';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './CobSpFxAzureFunction.module.scss';
import * as strings from 'cobSpFxAzureFunctionStrings';
@chrisobriensp
chrisobriensp / run.csx
Last active April 20, 2017 13:01
An Azure Function which uses SharePoint PnP Core component to create a modern page.
using System;
using System.Net;
using Newtonsoft.Json;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using OfficeDevPnP.Core.Pages;
private static readonly string ADMIN_USER_CONFIG_KEY = "SharePointAdminUser";
private static readonly string ADMIN_PASSWORD_CONFIG_KEY = "SharePointAdminPassword";
@chrisobriensp
chrisobriensp / project.json
Last active April 18, 2017 16:22
Shows the project.json file for an Azure Function which uses the SharePoint PnP core component (via NuGet support in Azure Functions).
{
"frameworks": {
"net46":{
"dependencies": {
"SharePointPnPCoreOnline": "2.14.1704"
}
}
}
}