Update README with example of correct Ahoy event tracking?
Closed this issue · 2 comments
This project looks really cool, thanks for putting it out there!
The ahoy_captain README just points to the section in the Ahoy documents that show:
class ApplicationController < ActionController::Base
after_action :track_action
protected
def track_action
ahoy.track "Ran action", request.path_parameters
end
end
What's a properly working example configuration for capturing events they way they have been in the screenshot? Are we supposed to literally track an event with the name "$view", or is that supposed to be a substitution example?
Also think this would be helpful!
hi @johnmcdowall,
The code snippet you posted above from the ahoy documentation does, indeed, add the necessary information to tracking events in your application with the corresponding controller name#action
format.
On a fresh install, once you incorporate that into your application, you will see a screen like this:
That said, you may find yourself tracking more information than you want through this approach, as it is a catchall. In the event that you'd want to track specific events from only some controllers, you might consider creating a base controller class for tracked events and letting specific controllers inherit from that, e.g.,
class TrackedEventsController < ApplicationController
after_action :track_action, only: [:create, :update]
protected
def track_action
ahoy.track "Ran action", {user_id: current_user.id}.merge(request.path_parameters)
end
end
class StaticController < TrackedEventsController
def index
end
# ...
end
Would be curious if @joshmn has other thoughts.