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

How can I use the tracker in a model or service? #148

Closed ghost closed 4 years ago

ghost commented 4 years ago

Getting undefined method `tracker'

DonSchado commented 4 years ago

hm, can you explain what you want to achieve?

at the moment the tracker is only available in the controller layer, because there you have access to the request env. The actual tracking happens by rendering the javascript tracking snippet in the view.

What do you expect to happen in a model? 🤔

ghost commented 4 years ago

I have an e-commerce flow being handled in a service and want to send data to GA

DonSchado commented 4 years ago

You could calculate everything needed in the service and give everything to the tracker block in the controller so that the view can render the corresponding javascript. 🤷‍♂

If you want to track directly in your services, I believe then you might want to use their API directly and not the JS Snippet.