Class: Landable::Traffic::Tracker
- Inherits:
-
Object
- Object
- Landable::Traffic::Tracker
show all
- Defined in:
- lib/landable/traffic/tracker.rb
Constant Summary
collapse
- TRACKING_PARAMS =
{
"ad_type" => %w[ad_type adtype],
"ad_group" => %w[ad_group adgroup ovadgrpid ysmadgrpid],
"bid_match_type" => %w[bidmatchtype bid_match_type bmt],
"campaign" => %w[campaign utm_campaign ovcampgid ysmcampgid],
"content" => %w[content utm_content],
"creative" => %w[creative adid ovadid],
"device_type" => %w[device_type devicetype device],
"click_id" => %w[gclid click_id clickid],
"experiment" => %w[experiment aceid],
"keyword" => %w[keyword kw utm_term ovkey ysmkey],
"match_type" => %w[match_type matchtype match ovmtc ysmmtc],
"medium" => %w[medium utm_medium],
"network" => %w[network],
"placement" => %w[placement],
"position" => %w[position adposition ad_position],
"search_term" => %w[search_term searchterm q querystring ovraw ysmraw],
"source" => %w[source utm_source],
"target" => %w[target],
}.freeze
- TRACKING_KEYS =
TRACKING_PARAMS.values.flatten.freeze
- ATTRIBUTION_KEYS =
TRACKING_PARAMS.except("click_id").keys
- TRACKING_PARAMS_TRANSFORM =
{
"ad_type" => { 'pe' => 'product_extensions',
'pla' => 'product_listing' },
"bid_match_type" => { 'bb' => 'bidded broad',
'bc' => 'bidded content',
'be' => 'bidded exact',
'bp' => 'bidded phrase' },
"device_type" => { 'c' => 'computer',
'm' => 'mobile',
't' => 'tablet' },
"match_type" => { 'b' => 'broad',
'c' => 'content',
'e' => 'exact',
'p' => 'phrase',
'std' => 'standard',
'adv' => 'advanced',
'cnt' => 'content' },
"network" => { 'g' => 'google_search',
's' => 'search_partner',
'd' => 'display_network' },
}.freeze
- UUID_REGEX =
/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\Z/
- UUID_REGEX_V4 =
/\A\h{8}-\h{4}-4\h{3}-[89aAbB]\h{3}-\h{12}\Z/
- KEYS =
Save space in the session by shortening names
{
visit_id: 'vid',
visitor_id: 'vsid',
visit_time: 'vt',
visitor_hash: 'vh',
attribution_hash: 'ah',
referer_hash: 'rh'
}.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(controller) ⇒ Tracker
Returns a new instance of Tracker.
86
87
88
89
90
91
|
# File 'lib/landable/traffic/tracker.rb', line 86
def initialize(controller)
raise NotImplementedError, "You must subclass Tracker" if self.class == Tracker
@controller = controller
@start_time = Time.now
end
|
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
70
71
72
|
# File 'lib/landable/traffic/tracker.rb', line 70
def controller
@controller
end
|
Class Method Details
.for(controller) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/landable/traffic/tracker.rb', line 76
def for(controller)
type = controller.request.user_agent.presence && Landable::Traffic::UserAgent[controller.request.user_agent].user_agent_type
type = 'noop' if Landable.configuration.traffic_enabled == :html and not controller.request.format.html?
type = 'user'if type.nil?
type = 'user'if controller.request.query_parameters.slice(*TRACKING_KEYS).any?
"Landable::Traffic::#{type.classify}Tracker".constantize.new(controller)
end
|
Instance Method Details
#create_event(type, meta = {}) ⇒ Object
102
103
104
105
106
|
# File 'lib/landable/traffic/tracker.rb', line 102
def create_event(type, meta = {})
return unless @visit_id
Event.create(visit_id: @visit_id, event_type: type, meta: meta)
end
|
#landing_path ⇒ Object
108
109
110
|
# File 'lib/landable/traffic/tracker.rb', line 108
def landing_path
@visit_id and PageView.where(visit_id: @visit_id).order(:page_view_id).first.try(:path)
end
|
#track ⇒ Object
93
94
95
|
# File 'lib/landable/traffic/tracker.rb', line 93
def track
raise NotImplementedError, "You must subclass Tracker" if self.class == Tracker
end
|
#visitor_id ⇒ Object
97
98
99
100
|
# File 'lib/landable/traffic/tracker.rb', line 97
def visitor_id
@visitor_id = visitor.id if visitor_changed?
@visitor_id
end
|