If you worked with Sitecore Analytics before, you must have come across Top downloads report under behavior tab, this report shows the assets that your contacts have downloaded the most from your website. but sometimes you may get a request from your client to get more information and control over this report, like as example, sort, filter, or maybe show all assets not only the top ones. In this case you would need to go with a custom approach, either built a custom analytics report or why not to export the report into a CSV and give your client a full control over it. In this post, I'll walk you through a step by step approach to pull these information from Analytics database into a csv format. excited?! keep reading!
First step is to access the reporting database and find out how to query the needed data, I've prepared the following query to pull the information that exactly match the downloads report under analytics, if you have seen a better approach, please comment on this post, here is my query:
Second step is to decide how to approach the new export functionality, in my case, I decided to add a conditional button in Sitecore Content Editor ribbon that shows when media folder is selected, notice that here you can scope the query to specific item and its Childs if needed, in my case I just wanted to export all media items with exact columns to match the analytics report.
In order to be add a condition button or contextual button in Content Editor ribbon, you need to switch to the Core database and navigate to the following path:
/sitecore/content/Applications/Content Editor/Ribbons/Contextual Ribbons/Media Folder/Media/Media
I added a large button and set the field [Click] to have this value, [media:exportdownloads]. Now this is what you will use in your config as below:
Third and last step, on the click of this button, you can open window of an aspx page that will simply execute your query, maybe use stored procedure, and then write your response string as a csv, here is a sample code:
On button click:
The target page sample code:
Hope this post be useful and help someone, please feel free to comment on this post for any questions or suggestions.
No comments:
Post a Comment