Hi @raulkabuto-
BP Docs serves attachments via BP_Docs_Attachments::catch_attachment_request() in includes/attachments.php. There’s no existing action hook; however, catch_attachment_request() is hooked to template_redirect at priority 20, so you could add your own action hooked to template_redirect at an earlier priority to fire your recording.
In general, though, and if BP Docs weren’t managing downloads the way it does, tracking http downloads of files via php is not easy. (WP doesn’t fire up if the link you click is a link directly to a “real” file.)
Best,
-David
Thanks David, I will mess around and see what I can do to get the result I need.
By the way, do you know a better way to do this on PHP instead of WP hooks, maybe a .js that works on the link click or trigger, or some suggestion at all so I can think of something?
Thanks a lot!
Best wishes,
Raul
Hi Raul-
Lots of services use click events for that task, like KissMetrics, but there are some downsides:
• If you’re measuring a click, how do you know that the user actually got the file (permissions, server problems whatever)?
• If you’re using an on-click event, you’ll have to add a delay so that your JS can run before the user navigates away from the page, and then use a JS redirect to send them where they were trying to go (ugly and unreliable, because browsers don’t all have the same behavior). http://www.ravelrumba.com/blog/tracking-links-with-javascript/
In the case of BP Docs attachments, adding a hook on template_redirect is probably the way to go, because it avoids the asynchronous problems of JS.
-David