Skip to content

Commit 6b1b463

Browse files
committed
Support multiple tracking calls
If you redirect and use event persisting, only the first event would get tracked. By setting rack.session correctly mixpanel will add extra events to the already existing queue.
1 parent 8f80f41 commit 6b1b463

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

example/app/controllers/posts_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,11 @@ def destroy
6969
format.json { head :no_content }
7070
end
7171
end
72+
73+
# Useful for testing if every event gets tracked when using persist: true.
74+
def redirect
75+
@post = Post.find(params[:id])
76+
track_action '[redirect] post', post_id: @post.id
77+
redirect_to @post
78+
end
7279
end

example/config/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Example::Application.routes.draw do
2-
resources :posts
2+
resources :posts do
3+
get :redirect, on: :member
4+
end
35

46
# The priority is based upon order of creation:
57
# first created -> highest priority.

lib/ab_panel/controller_additions.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def initialize_ab_panel!(options = {})
5555

5656
{
5757
'distinct_id' => distinct_id,
58-
'rack.session' => request['rack.session'],
58+
'rack.session' => request.env['rack.session'],
5959
'ip' => request.remote_ip
6060
}.each do |key, value|
6161
AbPanel.set_env(key, value)
@@ -113,8 +113,6 @@ def track_action(name, properties = {})
113113

114114
AbPanel.identify(distinct_id)
115115
AbPanel.track(name, options.merge(ab_panel_options))
116-
117-
session['mixpanel_events'] ||= AbPanel.env['rack.session']['mixpanel_events'] rescue []
118116
end
119117
end
120118
end

0 commit comments

Comments
 (0)