-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore visits to Active Storage endpoints #465
Comments
P.S. This doesn't seem to work, a visit to # config/initializers/ahoy.rb:8
Ahoy.exclude_method = lambda do |controller, request|
request.path.starts_with?("/rails")
end |
Hey @joemasilotti, I believe that should work. I'd try adding debugging to see what's going on. |
FWIW, I was able to get this working by monkey patching # app/controllers/active_storage/base_controller.rb
# frozen_string_literal: true
# The base class for all Active Storage controllers.
class ActiveStorage::BaseController < ActionController::Base
include ActiveStorage::SetCurrent
skip_before_action :track_ahoy_visit
protect_from_forgery with: :exception
self.etag_with_template_digest = false
private
def stream(blob)
blob.download do |chunk|
response.stream.write chunk
end
ensure
response.stream.close
end
end # spec/requests/ahoy_spec.rb
require "rails_helper"
describe "Ahoy tracking" do
it "tracks an Ahoy visit for the homepage" do
expect { get "/" }.to change { Ahoy::Visit.count }.by(1)
end
it "doesn't track an Ahoy visit for Active Storage routes" do
path = "/rails/active_storage/disk/efX0=--bb4/mugshot.jpeg"
expect { get path }.to_not change { Ahoy::Visit.count }
end
end # spec/rails_helper.rb
Ahoy.track_bots = true |
Thanks for sharing. I'd encourage people to try the |
But If it helps I could throw together two test cases tomorrow. |
Howdy, Folks. I can confirm that def track_ahoy_visit
defer = Ahoy.server_side_visits != true
if defer && !Ahoy.cookies
# avoid calling new_visit?, which triggers a database call
elsif ahoy.new_visit?
ahoy.track_visit(defer: defer)
end
end The call to |
Could this issue be reopened? I can confirm that |
Hey @ankane, any news on this? Thanks! |
anyone come across a way of getting this working without monkey patching? with the following configuration: # config/initializers/ahoy.rb
class Ahoy::Store < Ahoy::DatabaseStore
end
Ahoy.api = false
Ahoy.geocode = false
Ahoy.exclude_method = lambda do |controller, request|
request.path.starts_with?("/rails")
end cookies are still being set by ahoy:
this prevents me from being able to cache images on a CDN using active storage's proxy mode. |
for anyone else running into this, a workaround that worked for me is rack-strip-cookies with the following config: # config/application.rb
config.middleware.insert_before(ActionDispatch::Cookies, Rack::StripCookies, paths: %w[/rails/active_storage/representations/proxy]) |
@schpet Brilliant, I would add |
Is it possible to ignore Ahoy visits to the Active Storage endpoints, e.g.
/rails/active_storage/blobs/:id
? There doesn't seem to be any hooks available from Active Storage.The text was updated successfully, but these errors were encountered: