joshmn / ahoy_captain

A full-featured, mountable analytics dashboard for your Rails app, powered by the Ahoy gem.
MIT License
356 stars 18 forks source link

Update README with example of correct Ahoy event tracking? #35

Closed johnmcdowall closed 8 months ago

johnmcdowall commented 10 months ago

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?

arjun810 commented 10 months ago

Also think this would be helpful!

afogel commented 9 months ago

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:

Screenshot 2023-12-18 at 2 07 03 PM

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.