2

I have some code which calls a function like this :

function trackPDFSEClicks(){
        ahoy.track("Viewed Job Spec", {title: "Viewed Software Engineer Job Spec"});
        window.location.href = "/Software Engineer.pdf";
    }

However because this track call is asynchronous - sometimes it doesn't complete before the PDF has loaded - and therefore the event is not tracked.

I do not necessarily want to have to go and handle this tracking in the controller as it would be far simpler for me to use this method if possible - so is there any way I can force this ahoy.track call to be run synchronously?

RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130

1 Answers1

1

I decided after apneadiving's insight to just create an action in my controller for each of my downloadable links - and used the rails API from ahoy combined with the rails send_file method - which gives me the kind of behaviour I expect.

RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130