Last active
July 18, 2016 15:05
-
-
Save vgrem/2884bdad94d450e0f869 to your computer and use it in GitHub Desktop.
Activate Google Analytics in SharePoint Online site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$SiteUrl, | |
[string]$UserName, | |
[string]$Password | |
) | |
. ".\UserCustomActions.ps1" | |
<# | |
.SYNOPSIS | |
Activate Google Analytics | |
.DESCRIPTION | |
Activate Google Analytics in Office 365/SharePoint Online site | |
.EXAMPLE | |
.\Activate-GoogleAnalytics.ps1 -SiteUrl "https://tenant-public.sharepoint.com" -UserName "username@tenant.onmicrosoft.com" -Password "password" | |
#> | |
Function Activate-GoogleAnalytics([string]$SiteUrl,[string]$UserName,[string]$Password) | |
{ | |
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) | |
$context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password | |
$sequenceNo = 1480 | |
#Insert your Tracking code here or specify valid Tracking ID | |
$TrackingCode = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-XXXXXXXX-X', 'auto'); | |
ga('send', 'pageview');" | |
Add-ScriptLinkAction -Context $Context -ScriptBlock $TrackingCode -Sequence $sequenceNo | |
$context.Dispose() | |
} | |
Activate-GoogleAnalytics -SiteUrl $SiteUrl -UserName $UserName -Password $Password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please confirm this is scoped so that any site or sub site has this JS injection.