• Resolved raulkabuto

    (@raulkabuto)


    Hello,

    I am working with a plugin that records user activity based on hooks and actions and would be nice to know when a user download a document from Buddy Docs, but I can’t find the hook that triggers when “user clicks on the attachment link to download”.

    Is that possible to know? Is there a way to track the downloads of specific file/folder?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author David Cavins

    (@dcavins)

    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

    Thread Starter raulkabuto

    (@raulkabuto)

    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

    Plugin Author David Cavins

    (@dcavins)

    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

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Action Hooks’ is closed to new replies.