SharePoint Analytics via the CSWP

Using the Content Search Web Part (CSWP) you can get analytics for the number of the different type of items (Files, Events, Discussions, Tasks, Pages, etc) that are in your SharePoint Farm.  The one caveat is that CSWP only display items that haven’t been removed from search (Deleted or setting library/list to not appear in Search in advanced settings) and that you have access to.  So ideally you would want to be logged in as a site collection or farm administrator to get an accurate count.

How CSWP’s can display analytics

Just add a CSWP to any page, edit the web part, and click on the Change query button.

1. Customize the Query text to return a specified item type and optionally add a time frame.
2. Click the Test query button
3.  The Search Result Preview panel on the right of the screen will show the number of Relevant Results.

CSWP Query Text Examples

The following are some examples of CSWP Query text that return a specific item type.  The (Created>={Today-90}) filter is optional, it limits the results to only items created in the last 90 days.  The reason to do a time filter, is ultimately you probably want to know how much new content is being created, not how much old content there is.  Just run these CSWP queries every 3 months to compare the new item generation from quarter to quarter.

# of files in document libraries, created in last 90 days

# of xml files (InfoPath), created in last 90 days

# of pages, created in last 90 days

This excludes the “How to Use This Library” page which is automatically created in every new Site Pages library (and rarely if ever used).

# of tasks, created in last 90 days

Were using the ContentType as contentclass returns all the workflow tasks as well.

# of ‘Custom List’ app items, created in last 90 days

# of events (calendar), created in last 90 days

# of discussion board posts & replies, created in last 90 days

Additional contentclass query text examples

Issues: contentclass:STS_ListItem_IssueTracking
Announcements: contentclass:STS_ListItem_Announcements
Blog Post: contentclass:STS_ListItem_Posts
Links List: contentclass:STS_ListItem_Links
Promoted Links: contentclass:STS_ListItem_170

Tracking the Analytics over time

Unfortunately the CSWP doesn’t track all the items that get deleted out of SharePoint, this makes it difficult to get analytics for past periods.  Your three options would be:

A.  Find the total number of items:
**Returns the total number of searchable tasks in SharePoint on the day the query is run.

B.  Query the total number of items created during a specific period:
ContentType=Task AND (Created>=1/1/2016 AND Created<4/1/2016)
**Returns the total number of searchable tasks in SharePoint created between January 1st and March 31st 2016.  The problem with this query is the number will go down over time as older tasks get deleted.

C. Query the total number of items during a recent period:
ContentType=Task AND (Created>={Today-90})
**Returns the total number of searchable tasks in SharePoint for the last 90 days, if you setup a recurring appt to re-run this query, you could then compare the amount of item creation over time.


About Nick Hurst (84 Articles)
SharePoint and Nintex developer who strives to find easy to deploy and maintain solutions for business problems.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: