railslove / rack-tracker

Tracking made easy: Don’t fool around with adding tracking and analytics partials to your app and concentrate on the things that matter.
https://www.railslove.com/open-source
MIT License
647 stars 121 forks source link

Render templates directly for JS responses #133

Closed jaryl closed 4 years ago

jaryl commented 5 years ago

On a legacy codebase, I would like to spit out tracking code with a JavaScript response. However, rack tracker does not conveniently expose the templates for rendering such responses.

At present, I am pushing the params I need to the session in order for rack-tracker to pick up on the next request. However, there is no guarantee that the user will navigate to a next page, nor will all next-requests be a regular non-xhr request.

The closest issue I could find on this is here: https://github.com/railslove/rack-tracker/issues/79

Also, I've looked through the code base a bit, but it seems like it would necessitate quite a lot of hacking to get right. Is there an easy way to pass the params I need to the relevant templates for rendering?

DonSchado commented 4 years ago

Currently not supported :/

jclusso commented 4 years ago

@DonSchado as I mentioned in #152, I really think this would be the best approach long term for solving the issue I essentially monkey patched. While it allows the tracker to eventually get called it seems like it would be far more ideal to have JS template support so that the tracker doesn't have to wait until the next HTML request.

Is there a reason this issue was closed? If it has to do with the time investment to update all of the templates then I completely understand.

What are your thoughts on code that sets up the ability for JS templates and the documentation could specify which trackers support JS and HTML. Then it could be left up to developers that need them to implement them over time.

DonSchado commented 4 years ago

@jclusso This would be a neat feature, definitely. But at the moment I'm not using this gem in production at all... so that's maybe my main problem.

If you already have an idea how to achieve this, don't hesitate to prototype something and then we can discuss this further. :)