railslove / rack-tracker

Tracking made easy: Don’t fool around with adding tracking and analytics partials to your app and concentrate on the things that matter.
https://www.railslove.com/open-source
MIT License
647 stars 121 forks source link

google global: better empty tracker handling #142

Closed glaszig closed 4 years ago

glaszig commented 5 years ago

i'm using the following code:

use Rack::Tracker do
  handler :google_global, trackers: [ { id: ENV["GA_ID"] } ], anonymize_ip: true
end

which throws up the following way if GA_ID is empty:

NoMethodError:
  undefined method `[]' for nil:NilClass
# ./lib/rack/tracker/google_global/template/google_global.erb:2:in `block in singleton class'
# ./lib/rack/tracker/google_global/template/google_global.erb:-2:in `instance_eval'
# ./lib/rack/tracker/google_global/template/google_global.erb:-2:in `singleton class'
# ./lib/rack/tracker/google_global/template/google_global.erb:-5:in `__tilt_70324565778440'
# ./lib/rack/tracker/handler.rb:37:in `render'
# ./lib/rack/tracker/handler.rb:50:in `block in inject'
# ./lib/rack/tracker/handler.rb:49:in `inject'
# ./lib/rack/tracker.rb:67:in `block in inject'
# ./lib/rack/tracker.rb:100:in `each'
# ./lib/rack/tracker.rb:100:in `each'
# ./lib/rack/tracker.rb:66:in `inject'
# ./lib/rack/tracker.rb:54:in `block in call'
# ./lib/rack/tracker.rb:54:in `call'
# ./spec/integration/google_global_integration_spec.rb:36:in `block (3 levels) in <top (required)>'

this patch properly handles the case of empty trackers in the templates and deals with a few other cases which should be considered "empty". also caches collected trackers in an ivar to save a few iterations and cleans up the integration test a little.

bumi commented 5 years ago

thanks for the PR! :+1:

DonSchado commented 4 years ago

ping @glaszig :) is this still relevant?

glaszig commented 4 years ago

just added the warning.

glaszig commented 4 years ago

still a blocker? needs improvements? shall i squash the commits?

DonSchado commented 4 years ago

thanks for the reminder! :)