View Page Attachments Reports

View Page Attachments Reports

The other day I received a “simple” request to provide the number of times a PDF document has been downloaded. The PDF document was attached to a page. The PDF URL format looked like: http://MySite.com/getattachment/MyPDF.pdf

First thing, I headed over to Kentico Web Analytics, but no links showing up using /getattachment/ file structure.

Then I went to Configuration >> Reporting. I checked File downloads and Page views reports, and still nothing. No traces of any files preceded with /getattachment/.

Maybe Enable on-line marketing wasn’t checked in the Settings? Nope. It was checked.

Maybe I forgot to check the Enable web analytics to log the events? Nope. It was also checked.

As my last resort, I headed over to Google Analytics, but of course PDFs are not tracked by GA.

What now? So, I posted the question on Kentico DevNet: Is there an easy way to view page attachments reports?

I received few answers but not helpful at all. Apparently Kentico only supports the tracking of file downloads for the CMS.File page type. The system can track file downloads as Page visit activities for files stored as pages of the CMS.File type in the content tree of a website.

That means page attachments cannot be tracked by Kentico. The only way to have documents tracked is to use the CMS.File page type and give it a physical place in your content tree. Which was out of the question in my case.

So, the only option left was to use Google Tag Manager to track file downloads. Google Tag Manager uses trigger configurations to fire tags in response to events. (BTW, if you’re not using Google Tag Manager for you site this would be a good reason you should do it now.)

In order to track file downloads, go to your Google Tag Manager account, select your site and create a new Trigger and call it File Downloaded. Track Clicks (Just Links >> Same Link Clicks). For the trigger, select Click URL, matches RegEx, and plug this RegEx expression: \.(pdf|doc|docx|txt)$
Of course you can add your own file extensions to be tracked. Just follow the same format as above.
View Page Attachments Reports

Next create a new Tag called GA Downloaded File. For Tag Configuration select Universal Analytics, for Track Type select Event. Category Downloads. Action Downloaded File. Label select Click URL. Select your GA settings variable and Hit Save.
View Page Attachments Reports

Make sure you check if your new settings are triggered on your site using the Preview Mode and done! Now all the attached documents specified in the RegEx expression, will be automatically tracked by Google Analytics.

It might take few minutes for Google Analytics to register your new trigger configurations to fire tags in response to events.

To see the reports on downloaded attached files, go to your Google Analytics, select your site, set the date range and on the left navigation select Behaviour and then Events.

Here is a very useful tutorial on Tracking File Downloads in Google Tag Manager.