Closed olimart closed 5 years ago
@DonSchado @bumi any suggestion? Thanks
Heja,
as rack-tracker uses the rack env hash your service class would need to have access to that object. So somehow you would need to pass it in from the rails controller.
I've never used it, but something like this could work:
class RackTracker
include Rack::Tracker::Controller
attr_accessor :env
def initialize(env)
@env = env
end
def call(event, opts = {})
tracker do |t|
t.facebook_pixel :track, { type: event, options: opts }
end
end
end
and in the controller:
RackTracker.new(request.env).call(...)
You can also access the env hash directly (without including the Rack::Tracker::Controller) as described here (end)
Thanks for the explanation. I’ll guve it a try. Thanks a lot
Le mer. 17 oct. 2018 à 09:15, Michael Bumann notifications@github.com a écrit :
Heja,
as rack-tracker uses the rack env https://www.rubydoc.info/github/rack/rack/master/file/SPEC#label-The+Environment hash your service class would need to have access to that object. So somehow you would need to pass it in from the rails controller.
I've never used it, but something like this could work:
class RackTracker include Rack::Tracker::Controller attr_accessor :env
def initialize(env) @env = env end
def call(event, opts = {}) tracker do |t| t.facebook_pixel :track, { type: event, options: opts } end endend
and in the controller:
RackTracker.new(request.env).call(...)
You can also access the env hash directly (without including the Rack::Tracker::Controller) as described here https://github.com/railslove/rack-tracker#sinatra--rack (end)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/railslove/rack-tracker/issues/124#issuecomment-430623563, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhbqn-B6Y35FlI9ZW8IbzFocnOv8eCcks5uly2BgaJpZM4XaY4l .
-- Regards,
Olivier SIMART
(819) 962-1981 Blog http://blog.yafoy.com/ | T•Surprise https://tsurprise.com/ | Les Bonbecs https://lesbonbecs.com/ | Yapay https://yapay.xyz/ | Formtastic https://formz.herokuapp.com/
great, please report how you've solved it and close this issue if it works. and maybe it is something that should be added to the readme? (a PR would be appreciated! ;)) thanks!
Thanks @bumi I haven't had the chance yet to make the change but appreciate your help.
Hi, Thanks for the great work. I'm wondering if we could track event from a service object. I'm calling the service in my controller and it looks like this.
However, it is raising the following error:
undefined local variable or method `env' for #<RackTracker:0x00007fb3796d3f88 @event="PageView", @options={}>
I guess I need to pass somehow current environment but how? Thanks