2014-01-25 23:48:17 +00:00
|
|
|
require 'bugsnag'
|
2012-08-31 02:09:02 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
2016-07-17 15:16:27 +00:00
|
|
|
#protect_from_forgery #XXX turn back on; but client needs to send X-CRSF-TOKEN intsead of COOKIE
|
2013-10-01 18:57:02 +00:00
|
|
|
include ApplicationHelper
|
2012-08-31 03:01:52 +00:00
|
|
|
include SessionsHelper
|
2014-05-19 21:57:08 +00:00
|
|
|
include ClientHelper
|
2013-09-22 01:25:20 +00:00
|
|
|
|
2015-05-11 21:52:58 +00:00
|
|
|
force_ssl port: Rails.application.config.external_port_ssl if Rails.application.config.force_ssl
|
|
|
|
|
|
2013-09-22 01:25:20 +00:00
|
|
|
# inject username/email into bugsnag data
|
|
|
|
|
before_bugsnag_notify :add_user_info_to_bugsnag
|
|
|
|
|
|
2014-05-19 21:57:08 +00:00
|
|
|
before_filter do
|
|
|
|
|
gon_setup
|
|
|
|
|
end
|
|
|
|
|
|
2015-03-12 01:55:11 +00:00
|
|
|
before_filter :set_tracking_cookie
|
2015-05-28 13:20:14 +00:00
|
|
|
before_filter :track_affiliate_visits
|
2016-05-23 17:26:32 +00:00
|
|
|
before_filter :track_origin
|
2015-03-12 01:55:11 +00:00
|
|
|
|
2016-06-02 14:04:56 +00:00
|
|
|
#before_filter do
|
|
|
|
|
# if params[AffiliatePartner::PARAM_REFERRAL].present? && current_user.nil?
|
|
|
|
|
# if cookies[AffiliatePartner::PARAM_COOKIE].blank?
|
|
|
|
|
# code = params[AffiliatePartner::PARAM_REFERRAL].downcase
|
|
|
|
|
# cookies[AffiliatePartner::PARAM_COOKIE] = code if AffiliatePartner.is_code?(code)
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
#end
|
2014-04-20 22:54:49 +00:00
|
|
|
|
2014-04-22 01:55:40 +00:00
|
|
|
def affiliate_code
|
2016-06-02 14:04:56 +00:00
|
|
|
#cookies[AffiliatePartner::PARAM_COOKIE]
|
2014-04-20 22:54:49 +00:00
|
|
|
end
|
|
|
|
|
|
2015-03-12 01:55:11 +00:00
|
|
|
|
|
|
|
|
# http://stackoverflow.com/questions/15807214/where-to-set-a-tracking-permanent-cookie-in-rails
|
|
|
|
|
def set_tracking_cookie
|
|
|
|
|
cookies.permanent[:user_uuid] = SecureRandom.uuid unless cookies[:user_uuid]
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-28 13:20:14 +00:00
|
|
|
def track_affiliate_visits
|
2015-10-17 11:30:45 +00:00
|
|
|
if params[:affiliate]
|
2015-05-28 13:20:14 +00:00
|
|
|
visit_cookie = cookies[:affiliate_visitor]
|
|
|
|
|
AffiliateReferralVisit.track(affiliate_id: params[:affiliate], visited: visit_cookie, remote_ip: request.remote_ip, visited_url: request.fullpath, referral_url: request.referer, current_user: current_user)
|
|
|
|
|
|
|
|
|
|
# set a cookie with the ID of the partner, and expires in 24 hours
|
|
|
|
|
cookies[:affiliate_visitor] = { :value => params[:affiliate], :expires => Time.now + 3600 * 24} # 1 day from now
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-05-23 17:26:32 +00:00
|
|
|
def origin_cookie
|
|
|
|
|
begin
|
2026-01-17 04:15:36 +00:00
|
|
|
data = JSON.parse(cookies[:origin]) if cookies[:origin]
|
2016-05-23 17:26:32 +00:00
|
|
|
rescue
|
2026-01-17 04:15:36 +00:00
|
|
|
data = nil
|
2016-05-23 17:26:32 +00:00
|
|
|
end
|
|
|
|
|
|
2026-01-17 04:15:36 +00:00
|
|
|
# Backfill with individual UTM cookies if present
|
|
|
|
|
# This supports cases where the frontend (jam-ui/web) set specific cookies
|
|
|
|
|
# or if the JSON cookie is missing/incomplete.
|
2026-02-05 03:53:19 +00:00
|
|
|
%w(utm_source utm_medium utm_campaign utm_term utm_content utm_id).each do |key|
|
2026-01-17 04:15:36 +00:00
|
|
|
if cookies[key].present?
|
|
|
|
|
data ||= {}
|
|
|
|
|
data[key] = cookies[key]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data
|
2016-05-23 17:26:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def track_origin
|
|
|
|
|
return if current_user
|
|
|
|
|
|
|
|
|
|
origin = cookies[:origin]
|
|
|
|
|
|
|
|
|
|
# if this is a 1st visit, or if we previously said this was a direct link, then we'll refresh the info
|
|
|
|
|
should_set = params[:utm_source] || origin.nil?
|
|
|
|
|
if should_set
|
|
|
|
|
if params[:utm_source]
|
2021-04-11 01:49:49 +00:00
|
|
|
|
2016-05-23 17:26:32 +00:00
|
|
|
cookies.permanent[:origin] = {utm_source: params[:utm_source], utm_medium: params[:utm_medium], utm_campaign: params[:utm_campaign], referrer: request.referrer }.to_json
|
|
|
|
|
|
|
|
|
|
elsif request.referer
|
|
|
|
|
begin
|
|
|
|
|
cookies.permanent[:origin] = {utm_source: "organic", utm_medium: "organic", utm_campaign: URI.parse(request.referer).host, referrer: request.referer}.to_json
|
|
|
|
|
rescue
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-15 17:34:35 +00:00
|
|
|
|
2013-09-22 01:25:20 +00:00
|
|
|
private
|
|
|
|
|
def add_user_info_to_bugsnag(notif)
|
|
|
|
|
# Add some app-specific data which will be displayed on a custom
|
|
|
|
|
# "User Info" tab on each error page on bugsnag.com
|
|
|
|
|
|
|
|
|
|
unless current_user.nil?
|
|
|
|
|
notif.add_tab(:user_info, {
|
|
|
|
|
name: current_user.name,
|
|
|
|
|
email: current_user.email
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-08-31 02:09:02 +00:00
|
|
|
end
|
2015-05-28 13:20:14 +00:00
|
|
|
|
|
|
|
|
class ControllerHelp
|
|
|
|
|
include Singleton
|
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
|
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
|
|
|
|
include ActionView::Helpers::JavaScriptHelper
|
|
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
|
include ActionView::Helpers::AssetTagHelper
|
|
|
|
|
end
|