1

As of now, when we open a modern page / hover on a page, we can see Views count and also Viewers. Also, when we go to the siteanalytics page, we can view Site level views / viewer reports in past 3 months

Our Communication team want analytics on the Site pages. They want monthly metrics about viewers and views. Do we have access to the data source? Is there a way for us to customize the reports?

I checked Search API, which provides views count, but its too hard to search for each page in the site and also I can't guarantee every page would be covered through it.

1 Answer 1

1

The View count on the side menu of the page is based on the property ViewsLifeTime.

We do not have access to the data source from UI, but we can get this value of each page using PowerShell.

Here’s a sample script for your reference.

#Paths to SDK. Please verify location on your computer.      
#Add-PSSnapin Microsoft.SharePoint.PowerShell
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll")      
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll")      
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Search.dll")   

function Get-SPOListView {  
    param(  
        [Parameter(Mandatory = $true, Position = 1)][string]$Username,  
        [Parameter(Mandatory = $true, Position = 2)]$AdminPassword,  
        [Parameter(Mandatory = $true, Position = 3)][string]$Url,  
        [Parameter(Mandatory = $true, Position = 4)][string]$ListTitle,
        [Parameter(Mandatory = $true, Position = 5)][string]$TenantUrl) 

    #Get the SharePoint List / Library.  
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url)  
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)  
    $ll = $ctx.Web.Lists.GetByTitle($ListTitle)  
    $ctx.load($ll)  
    $ctx.ExecuteQuery()  

    #Get all items from the List / Library.  
    $qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()  
    $items = $ll.GetItems($qry)  
    $ctx.Load($items)  
    $ctx.ExecuteQuery()  

    #CSV file location, to store the result  
    $exportlocation = $filepath
    Write-Output "Title `t Path `t ViewsLifeTime `t ViewsLifeTimeUniqueUsers" | Out-file $filepath

    foreach($listItem in $items) {  
        Write-Host "ID - ", $listItem["ID"]  
        "Title - "
        $listItem["Title"]  
        "EncodedAbsUrl - "
        $listItem["FileRef"]  
        $fileurl = $TenantUrl + $listItem["FileRef"]  

        #Using Search API - Create the instance of KeywordQuery and set the properties.  
        $keywordQuery = New-Object Microsoft.SharePoint.Client.Search.Query.KeywordQuery($ctx)  

        #Sample Query - To get the result of last year.  
        $queryText = "Path:" + $fileurl  
        $keywordQuery.QueryText = $queryText  
        $keywordQuery.TrimDuplicates = $false  
        $keywordQuery.SelectProperties.Add("ViewsLifeTime")  
        $keywordQuery.SelectProperties.Add("ViewsLifeTimeUniqueUsers")  
        $keywordQuery.SortList.Add("ViewsLifeTime", "Asc")  

        #Search API - Create the instance of SearchExecutor and get the result.  
        $searchExecutor = New-Object Microsoft.SharePoint.Client.Search.Query.SearchExecutor($ctx)  
        $results = $searchExecutor.ExecuteQuery($keywordQuery)  
        $ctx.ExecuteQuery()  

        #Result Count  
        Write-Host $results.Value[0].ResultRows.Count   
        foreach($result in $results.Value[0].ResultRows) {  
            $outputline = "$($result["Title"]) `t $($result["Path"]) `t $($result["ViewsLifeTime"]) `t $($result["ViewsLifeTimeUniqueUsers"])"
            Add-Content $exportlocation $outputline  
        }
    }  
}  

#Insert the credentials along with Admin & Tenant URLs and Call above Function.     
$Username = "<Admin>"      
$pass = "<Password>"
$Password = convertto-securestring $pass -asplaintext -force
#URL of the site collection      
$rootUrl = "<SiteURL>"      
$ListTitle = "Site Pages"      
$TenantUrl = "https://<tenant>.sharepoint.com"
$filepath = "C:\Temp\Pages_ViewsCount.csv" 

Get-SPOListView -Username $Username -AdminPassword $Password -Url $rootUrl -ListTitle $ListTitle -TenantUrl $TenantUrl

If you want monthly metrics on this report, I suggest you use audit log reports instead.

Reference (Careful with typos in the original sample):

Office 365/SharePoint Online - PowerShell Script to Get and Export Site Pages ViewsLifeTimeUniqueUsers & ViewsLifeTime Details.

How to Generate a Page View Report in SharePoint Online.

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.