Question

Basically, I want to fire some JavaScript event/script when someone accesses/downloads a PDF item using a link from outside the website. This PDF is stored in the Sitecore Media Library.

Example -

Say I have a Sitecore based website called www.xyz.com And in that, I have a PDF file stored in the Sitecore Media Library which can be accessed with a url say - www.xyz.com/pdf1.ashx or www.xyz.com/pdf1.pdf.

So this item can be accessed in two ways -

  1. By a link within the website pointing to the PDF file.
  2. Directly via a link from some external source. Example some email, social media refer etc.

I found this link (How can I apply GA download tracking with Sitecore?) which wanted to do similar thing, but didn't get my answer.

One approach that comes to mind is to add something to the Sitecore pipeline process that would fire when someone accesses the Media Library items, and checking if the previous page was one of my website page and if the item is PDF and then based on that I can fire some event. But not sure how to implement this. I am using Sitecore 6.4.1.

So my aim is to fire an event when this file is accessed from external source.

Was it helpful?

Solution

Sitecore's MediaRequestHandler can be customized so that you can do something server side whenever a media request occurs.

You haven't said exactly what action you want to take so I can't be more specific, but these links should show you how to manipulate the media request handler:

If you really need to fire javascript you could ensure that all requests for PDF's get diverted to a specific webpage witch contains the JS on it. You would then need to redirect to the actual PDF item. This would be achieved with the MediaRequestHandler as mentioned above.

I realise this is really messy, but without more detail about what you need to achieve I can't think of a better solution.

OTHER TIPS

Just Create Httphandler for your pdf request , so whenever request comes for pdf that particular handler gets activate and fired event and so whatever you want in this file

you can find out handlers in webconfig for more details on module and handlers see the below link. http://www.codeproject.com/Articles/544289/Restricting-files-download-using-HTTP-Handler-base

otherwise you can directly inject the code in pipeline or use this

 <customHandlers>
      <handler trigger="~/media/" handler="sitecore_media.ashx" />
      <handler trigger="~/api/" handler="sitecore_api.ashx" />
      <handler trigger="~/xaml/" handler="sitecore_xaml.ashx" />
      <handler trigger="~/icon/" handler="sitecore_icon.ashx" />
      <handler trigger="~/feed/" handler="sitecore_feed.ashx" />
    </customHandlers>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top