Donnerstag, 27. Februar 2014

Query SharePoint Search Analytics using PowerShell

Analytics have been completely revised in SharePoint 2013. Some of the core tech in the previous FAST release has been fused together with SharePoint enterprise search to create a new and powerful analytics engine.
The Analytics Engine is based on two main parts. We have Search Analytics and we have Usage Analytics features. Both parts have own reports which can be found under Site setting and as part of the Search Service Application in Central Admin.
Usage Analytics out-of-the-box report:
Search Analytics out-of-the-box report:

By using PowerShell we can query both Analytics parts and get custom reports.

Usage Analytics:

First of all we have to set the Search Service Application:
 $searchApp = Get-SPEnterpriseSearchServiceApplication

Next step is setting up a site scope for the report:

Now we can execute the request:
$result = $searchApp.GetRollupAnalyticsItemData(1,[System.Guid]::Empty,$Site.ID,[System.Guid]::Empty)

If the report should not have a site focus we had to replace the “$Site.ID” part with “[System.Guid]::Empty”.

To focus the report data to a specific day or month we can use the GetHitCountForDay and the GetHitCountForMonth method.
First we had set up the data to which we want to focus:
$FilterDate = Get-Date "2014-01-20"

Then we can use the $FilterDate variable together with both methods:
$result.GetHitCountForDay($FilterDate)
$result.GetHitCountForMonth($FilterDate)

Search Reports:

Search Analytics cmdlets follows a different syntax. To get data from that engine we also had to setup the 

Search Service Application:
$searchApp = Get-SPEnterpriseSearchServiceApplication

Also in this case we can focus to a specific site using a variable:

The difference now is that we had to set up a date time value for the report. Leaving it blank is no option here:
$searchApp.GetSearchReport(1,[System.Guid]::Empty,[System.Guid]::Empty,[System.DateTime]::Now,$false,100)
That command gets the report data for the actual month: [System.DateTime]::Now . 

The next parameter which is set to “false” is the switch for getting data for the month = false or the day = true.
If we want the data for another month than the we have to set up a date variable and use it instead of [System.DateTime]::Now :
$FilterDate = Get-Date "2014-01-20"
$searchApp.GetSearchReport(1,[System.Guid]::Empty,$site.ID,$FilterDate,$false,100)

Getting farm wide data we also had to replace the $site.ID variable with “[System.Guid]::Empty”:
$searchApp.GetSearchReport(1,[System.Guid]::Empty,[System.Guid]::Empty,$FilterDate,$false,100)
The first parameter with the value “1” is setting the Event Type. Event Type 1 = views. The next parameter is the TenantID, followed by SiteID, date value, month / day switch and the max result value (100 means show me the top 100 search terms).

4 Kommentare:

  1. Hi Nicki! This post was incredibly helpful! I've taken things a bit further and have created a CodePlex project with a PowerShell script to retrieves this data and exports it to a CSV file. Hopefully this is useful to some of your readers.

    SharePoint 2013 Web Analytics Data Export to CSV using PowerShell
    https://sp2013wade.codeplex.com

    AntwortenLöschen
  2. The article clearly separates Search Analytics from Usage Analytics in SharePoint 2013 and shows how PowerShell can retrieve information that is not always exposed through the standard reporting interface. The examples using Get-SPEnterpriseSearchServiceApplication, Get-SPSite, and the analytics methods make the process concrete rather than purely conceptual.

    The Usage Analytics example is particularly useful because GetRollupAnalyticsItemData can work with a specific site or across the farm using Guid::Empty, while GetHitCountForDay and GetHitCountForMonth provide ways to examine activity over different time periods. This kind of structured examination of reporting data connects naturally with Data Analytics Course concepts.

    AntwortenLöschen
  3. The Search Analytics section also explains the parameters required by GetSearchReport, including the event type, tenant ID, site ID, date, day or month selection, and maximum result count. Turning these returned metrics into understandable charts or reports would make the results more useful, which is where Data Visualization Training becomes relevant.

    AntwortenLöschen
  4. Another useful aspect is the distinction between site-specific and farm-wide reporting, since the same approach can support different levels of analysis. For students interested in applying analytics concepts to practical software projects, these reporting scenarios can also provide ideas for Data Science Projects For Final Year involving dashboards, usage metrics, and data-driven reporting.

    AntwortenLöschen