Deploy Google Analytics to all modern sites in your SharePoint Online tenant using a SharePoint Framework extension.
- App Catalog: Ensure the App Catalog is setup in your SharePoint Online tenant
- Download the SPFx package googleanalytics-tenant.sppkg file from Github (or clone the repo and build the package yourself)
- Upload sppkg file to the 'Apps for SharePoint' library in your Tenant App Catalog
- Click the 'Make this solution available to all sites in your organization' checkbox and then click Deploy
This solution is deployed using Tenant Wide Extensions. You can modify the JSON properties configuration via the item in the Tenant Wide Extensions list. The available properties are below.
| Extension Property Name | Default Value | Description |
|---|---|---|
| googleTrackingId | "" |
Required. Google Analytics Example: UA-111111111-1 Google Tag Manager Example: GTM-XXXX |
| useGoogleTagManager | false |
Optional. Use Google Tag Manager instead of Google Analytics. |
| propertyMappings | undefined |
Optional (Google Tag Manager only). Collection of user property mappings from the SharePoint User Profile service to the Google Tag Manager dataLayer. |
| disableCache | false |
Optional (Google Tag Manager only). Disable client-side caching of SharePoint User Profile when using Google Tag Manager with property mappings. |
| cacheLifetimeMins | 720(12 hours) |
Optional (Google Tag Manager only). Number of minutes the SharePoint User Profile should remain cached in browser localStorage before re-fetching. |
Specify a collection of mappings from SharePoint User Profile Properties to Google Tag Manager dataLayer properties.
| Mapped Property Name | Default Value | Description |
|---|---|---|
| spoUserPropertyName | undefined |
Required. Internal name of SharePoint User Profile property. |
| gtmPropertyName | undefined |
Required. Name of the property to map the User Profile Value into when sent to Google Tag Manager. |
| encryptSHA256 | false |
Optional. Encrypt with SHA256 and send masked hash value instead of plain text value. |
Example tenant wide extension configuration with property mappings below:
{
"googleTrackingId": "GTM-XXXX",
"useGoogleTagManager": true,
"propertyMappings": [
{ "spoUserPropertyName": "Title", "gtmPropertyName": "jobTitle" },
{ "spoUserPropertyName": "contosoEmployeeID", "gtmPropertyName": "employeeID", "encryptSHA256": true },
{ "spoUserPropertyName": "contosoBusGroup", "gtmPropertyName": "businessGroup" },
{ "spoUserPropertyName": "contosoBusSubGroup", "gtmPropertyName": "businessSubGroup" },
{ "spoUserPropertyName": "contosoManagerInd", "gtmPropertyName": "manager" },
{ "spoUserPropertyName": "contosoExemptStatus", "gtmPropertyName": "expemptStat" },
{ "spoUserPropertyName": "contosoFullTimeInd", "gtmPropertyName": "fullTime" },
{ "spoUserPropertyName": "contosoStartDate", "gtmPropertyName": "startDate" },
{ "spoUserPropertyName": "contosoCity", "gtmPropertyName": "city" },
{ "spoUserPropertyName": "contosoState", "gtmPropertyName": "state" }
]
}Follow the same steps as installation. Overwrite the existing package in the 'Apps for SharePoint' library when uploading the new package.
Tip #1: Be sure to check-in the sppkg file after the deployment if it is left checked-out.
Tip #2: Ensure there aren't duplicate entries in the Tenant Wide Extensions list after deploying an update. Delete any duplicates if there are any.
- Delete the entry in the Tenant Wide Extensions list on the Tenant App Catalog titled
GoogleAnalytics. - Delete the
googleanalytics-tenant.sppkgfile from the 'Apps for SharePoint' library in your Tenant App Catalog.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys' fees, that arise or result from the use or distribution of the Sample Code.
