Skip to content

Commit 2ae4e0f

Browse files
committed
Check to see if the mixpanel cookie value is present before passing to JSON
1 parent 39eedbd commit 2ae4e0f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

app/controllers/application_controller.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def current_user
4848

4949
def viewing_user
5050
@viewing_user ||= current_user || begin
51-
if cookies[:identity]
52-
User.with_username(cookies[:identity])
53-
end
51+
if cookies[:identity]
52+
User.with_username(cookies[:identity])
53+
end
5454
end
5555
end
5656

@@ -69,12 +69,17 @@ def sign_in(user)
6969
end
7070

7171
def mixpanel_cookie
72-
(cookies["mp_#{ENV['MIXPANEL_TOKEN']}_mixpanel"] && JSON.parse(cookies["mp_#{ENV['MIXPANEL_TOKEN']}_mixpanel"])) || {}
72+
mp_cookie = cookies["mp_#{ENV['MIXPANEL_TOKEN']}_mixpanel"]
73+
if mp_cookie.present?
74+
JSON.parse(mp_cookie)
75+
else
76+
{}
77+
end
7378
end
7479

7580
def ensure_and_reconcile_tracking_code
7681
if cookies[:trc].blank?
77-
session[:new_visit] = true
82+
session[:new_visit] = true
7883
cookies.permanent[:trc] = mixpanel_cookie['distinct_id']
7984
end
8085

@@ -233,7 +238,7 @@ def record_event(action_name, options = {})
233238
options.merge!({ 'signed in' => false,
234239
'member' => cookies[:identity] && User.exists?(username: cookies[:identity]),
235240
'first visit' => session[:new_visit]
236-
})
241+
})
237242
end
238243

239244
#options.merge!('signed up on' => current_user.created_at.to_formatted_s(:mixpanel),
@@ -265,9 +270,9 @@ def ajax_redirect_to(uri)
265270
respond_to do |format|
266271
format.json do
267272
render json: {
268-
status: :redirect,
269-
to: uri
270-
}.to_json
273+
status: :redirect,
274+
to: uri
275+
}.to_json
271276
end
272277
end
273278
end

0 commit comments

Comments
 (0)