Track PDF views and downloads

Vote:
 

I am using EpiServer profile store to track page views which is all good. How would i go about tracking PDF's and its downloads using the profile store. 

#246460
Edited, Jan 06, 2021 16:45
Vote:
 

Hi Dileep,

To track views of PDFs, I think you'll need to call some custom tracking (as described here: https://world.episerver.com/documentation/developer-guides/tracking/custom-tracking/) when the PDF is requested. Assuming you have a content type to represent your PDF files, you could create a handler for that type and then call the tracking from that so that the tracking is called each time someone requests a PDF. Something like this:

[TemplateDescriptor(Inherited = true, TemplateTypeCategory = TemplateTypeCategories.HttpHandler, Default = true)]
public class PdfBlobHttpHandler : BlobHttpHandler, IRenderTemplate<MyPdfFileType>
{
    protected override Blob GetBlob(HttpContextBase httpContext)
    {
        var trackingService = ServiceLocator.Current.GetInstance<ITrackingService>();
        //Add custom tracking here

        //Load and return the file data
        var routeHelper = ServiceLocator.Current.GetInstance<IContentRouteHelper>();
        var binaryStorable = routeHelper.Content as IBinaryStorable;
        return binaryStorable?.BinaryData;
    }
}
#246507
Jan 07, 2021 21:22
Vote:
 

You could of course also do client side tracking to some controller you manage on click and delay before letting the PDF navigation through. Similar to how you usually set it up in Google Tag Manager.

#246816
Edited, Jan 14, 2021 10:09
Vote:
 

Great info.

#253350
Apr 16, 2021 10:48
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.