kangguru / rack-google-analytics

Simple Rack middleware for implementing google analytics tracking in your Ruby-Rack based project. Supports synchronous and asynchronous insertion and configurable load options
MIT License
257 stars 53 forks source link

:if option that accepts lambdas added to skip middleware #38

Closed fddayan closed 9 years ago

fddayan commented 10 years ago

:if option added to skip google analytics if returns false.

A lambda might be used, so we can do something like

Rack::GoogleAnalytics, 
    :tracker => lambda { |env| return env[:ga_tracking_code] },
    :if => lambda { |env| return !env[:ga_tracking_code].nil? }

We can check for any of the variables of in env.

It would be possible to disabled GA for controllers or controllers actions using before_filter

mhuggins commented 9 years ago

+1

mhuggins commented 9 years ago

@kangguru Are you supporting this gem anymore? I see you've made some commits to railslove/rack-tracker, do you recommend switching to that?

kangguru commented 9 years ago

yes. please consider moving to Rack::Tracker

https://github.com/kangguru/rack-google-analytics#please-read

To skip adding the GA code to a page it should be sufficient when tracker evaluates to nil which will skip the initialization and page track.

you just should make sure that no events are published during that request

see: https://github.com/railslove/rack-tracker/blob/master/lib/rack/tracker/google_analytics/template/google_analytics.erb#L3

@fddayan @mhuggins will that work for you?