Skip to content

Commit 38cf32c

Browse files
committed
Remove error prone automatic property converting
This caused some weird errors, wasn't really used and didn't really follow the principe of least surprise :)
1 parent 6b1b463 commit 38cf32c

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

example/app/controllers/posts_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def index
1111
def show
1212
@post = Post.find(params[:id])
1313

14+
track_action '[visits] post', post_id: @post.id
15+
1416
respond_to do |format|
1517
format.html
1618
format.json { render json: @post }
1719
end
18-
19-
track_action '[visits] post', :post => :id
2020
end
2121

2222
def new
@@ -73,7 +73,7 @@ def destroy
7373
# Useful for testing if every event gets tracked when using persist: true.
7474
def redirect
7575
@post = Post.find(params[:id])
76-
track_action '[redirect] post', post_id: @post.id
76+
track_action '[redirects] post', post_id: @post.id
7777
redirect_to @post
7878
end
7979
end

lib/ab_panel/controller_additions.rb

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,19 @@ def initialize_ab_panel!(options = {})
7070
# Example:
7171
#
7272
# def show
73-
# track_action '[visits] Course', { :course => :id }
73+
# track_action '[visits] Course', { :course_id => @course.id }
7474
# end
7575
#
7676
# This will track the event with the given name on CoursesController#show
77-
# and assign an options hash:
78-
#
79-
# { 'course_id' => @course.id }
77+
# with the passed in attributes.
8078
def track_action(name, properties = {})
8179
AbPanel.add_funnel(properties.delete(:funnel))
8280

8381
options = {
8482
distinct_id: distinct_id,
8583
ip: request.remote_ip,
8684
time: Time.now.utc,
87-
}
85+
}.merge(properties)
8886

8987
AbPanel.funnels.each do |funnel|
9088
options["funnel_#{funnel}"] = true
@@ -94,22 +92,8 @@ def track_action(name, properties = {})
9492
options[exp] = AbPanel.conditions.send(exp).condition rescue nil
9593
end
9694

97-
properties.each do |key, val|
98-
if respond_to?(key)
99-
inst = send(key)
100-
elsif instance_variable_defined?("@#{key}")
101-
inst = instance_variable_get("@#{key}")
102-
else
103-
options[key] = val
104-
next
105-
end
106-
107-
val = *val
108-
109-
val.each do |m|
110-
options["#{key}_#{m}"] = inst.send(m)
111-
end
112-
end
95+
options.merge!(ab_panel_options)
96+
AbPanel.set_env(:properties, options)
11397

11498
AbPanel.identify(distinct_id)
11599
AbPanel.track(name, options.merge(ab_panel_options))

0 commit comments

Comments
 (0)