Closed leoplct closed 3 years ago
Hey @leoplct, you should be able to add an ahoy
method to ApplicationReflex
.
class ApplicationReflex < StimulusReflex::Reflex
def ahoy
@ahoy ||= Ahoy::Tracker.new(request: request)
end
end
Thanks, it's better now.
Do you know how to get the current_user (devise) too?
Must supply either user_id or anonymous_id
If you use master, you can now do:
Ahoy.user_method = lambda do |controller, request|
controller.try(:current_user) || request.env["warden"].user
end
(place in config/initializers/ahoy.rb
)
Cleaning up issues
This worked for me:
class ApplicationReflex < StimulusReflex::Reflex
delegate :current_user, to: :connection
after_reflex :track_action
protected
def ahoy
@ahoy ||= Ahoy::Tracker.new(user: current_user)
end
def track_action
ahoy.track "Ran reflex action", reflex_name: self.class.name, reflex_params: params.to_unsafe_h
end
end
I haven't found the information in the doc about how to use Ahoy with a StimulusReflex controller. ahoy is not defined. How can I use it?
undefined local variable or method `ahoy'