3

We are launching a big SharePoint Online project for 15000+ users, and the project owners want to know how end-users are using and behaving inside the SharePoint Online.

Are there OOTB features for these admins to see: Analytics, Usage, Statistics and Reports?

Of course, I am aware of the new-experience of the Site Contents page, But, Are there more advanced reporting capabilities that are displayed for Admins or site owners?

Please, Share your thoughts and suggestions to meet such requirements !

1 Answer 1

3

We are using a CustomAction comprised of Google Analytics code. All of the auditing and compliance functions are lacking to track basic page views easily. Adding a user dimension allows us to dive a little deeper into who is viewing what.

    <script>
  (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','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-123456789-0', 'auto');
  ga('send', 'pageview');

</script>

This JS file is stored in the site assets library. Then using PowerShell and CSOM, we add this file as a CustomAction to the site.

function New-CustomAction{
    <#
        .SYNOPSIS
            Creates a new custom action on the spicifed address
        .DESCRIPTION    
            Creates a new custom action on the spicifed address
        .PARAMETER Url
            The Url to add a custom action to
        .PARAMETER ActionType
            Site or web UserCustomActions to find
        .PARAMETER Title
            The title of the CustomAction
        .PARAMETER ScriptSrc
            The full URL to the path of the file to attach
        .PARAMETER Sequence
            The sequence number in which this is to be executed, lower numbers get executed first
        .PARAMETER Description
            A description of the custom action
        .EXAMPLE
            Creates a UserCustomAction with the specified parameters
            New-CustomAction -Url "https://tenant.sharepoint.com/teams/eric/subsite" -ActionType "Web" -Title "Acknowledge Script" -ScriptSrc "https://tenant.sharepoint.com/teams/eric/subsite/SiteAssets/testscript.js" -Sequence 0
        .NOTES
        .LINK
        https://msdn.microsoft.com/en-us/library/office/dn531432.aspx#bk_UserCustomAction

    #>
    Param(
        [Parameter(Mandatory=$true,HelpMessage="The URL of the site or web")][ValidateNotNull()]
        [string]$Url,
        [Parameter(Mandatory=$true,HelpMessage="The action type scope")][ValidateNotNull()]
        [string]$ActionType,
        [Parameter(Mandatory=$true,HelpMessage="The title of the CustomAction")][ValidateNotNull()]
        [string]$Title,
        [Parameter(Mandatory=$true,HelpMessage="The full URL to the path of the file to attach")][ValidateNotNull()]
        [string]$ScriptSrc,
        [Parameter(Mandatory=$true,HelpMessage="The sequence number in which this is to be executed")][ValidateNotNull()]
        [int]$Sequence,
        [Parameter(Mandatory=$false,HelpMessage="A description of the custom action")]
        [int]$Description
    )
    Begin{
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url) 
        $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)

        if($ActionType -eq "Site"){
            $site = $context.Site
        }
        else{
            $site = $context.Web
        }
        $context.Load($site)
        $context.ExecuteQuery()
    }
    Process{       
        $action = $site.UserCustomActions.Add()
        $action.Location = "ScriptLink"
        $action.ScriptSrc = $ScriptSrc
        $action.Title = $Title
        $action.Sequence = $Sequence
        if($Description){
            $action.Description = $Description
        }
        try{
            $action.Update()
            $context.ExecuteQuery()
            write-host -ForegroundColor Green "New UserCustomAction created successfully!" 
        }
        catch{
            Write-Host -ForegroundColor Red $_.Exception.Message
        }

    }
    End{
        $context.Dispose()
    }

}

New-CustomAction -Url "https://tenant.sharepoint.com/teams/eric" -ActionType "Site" -Title "Analytics Code" -ScriptSrc "https://tenant.sharepoint.com/teams/eric/subsite/SiteAssets/ga.js" -Sequence 0

This "Staples" the JS file to run on every page load in your site collection, reporting back to Google Analytics which you can the slice and dice as you want, or pull it into Power BI.

4
  • I love the idea of using Google Analytics, But, I am not sure I understood your text about "using a CustomAction comprised of Google Analytics code." Could you please elaborate a bit more on how your code snippet adds data into google analytics table ?
    – Alex
    Jun 24, 2016 at 22:53
  • Let me dig up my code, and I'll refine this answer Jun 25, 2016 at 0:51
  • Please do Eric, Thank you very much and I look forward to hearing from you soon !
    – Alex
    Jun 25, 2016 at 21:07
  • @Alex updated answer Jun 27, 2016 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.