Skip to content

Commit

Permalink
Merge pull request HyperCable#38 from HyperCable/add_request_params
Browse files Browse the repository at this point in the history
add request query param
  • Loading branch information
hooopo authored Mar 12, 2021
2 parents 0577d55 + 93eaf60 commit e99ea85
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/models/hyper/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# referrer_source :string
# region :string
# request_number :integer
# request_params :jsonb
# screen_resolution :string
# session_count :integer
# session_engagement :boolean default(FALSE)
Expand Down
7 changes: 4 additions & 3 deletions config/initializers/traffic_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ class TrafficDetector
def self.detect(event)
result = {}
request_url = event["dl"]
request_uri = Addressable::URI.parse(request_url)
request_uri = Addressable::URI.parse(request_url).normalize
request_params = request_uri.query_values || {}

referrer_url = event["dr"]

result[:hostname] = request_uri.domain
result[:path] = request_uri.request_uri
result[:location_url] = request_uri.normalize.to_s
result[:path] = request_uri.path
result[:location_url] = request_uri.to_s
result[:request_params] = request_params

return result.merge!(
traffic_campaign: "adwords",
Expand Down
5 changes: 5 additions & 0 deletions db/hyper_migrate/20210312171927_add_request_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRequestParams < ActiveRecord::Migration[6.1]
def change
add_column :events, :request_params, :jsonb, default: '{}'
end
end
20 changes: 18 additions & 2 deletions db/hyper_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ CREATE TABLE public.events (
raw_event jsonb DEFAULT '{}'::jsonb,
traffic_campaign character varying,
traffic_medium character varying,
traffic_source character varying
traffic_source character varying,
request_params jsonb DEFAULT '"{}"'::jsonb
);


Expand Down Expand Up @@ -162,6 +163,13 @@ ALTER TABLE ONLY _timescaledb_internal._hyper_5_1_chunk ALTER COLUMN event_props
ALTER TABLE ONLY _timescaledb_internal._hyper_5_1_chunk ALTER COLUMN raw_event SET DEFAULT '{}'::jsonb;


--
-- Name: _hyper_5_1_chunk request_params; Type: DEFAULT; Schema: _timescaledb_internal; Owner: -
--

ALTER TABLE ONLY _timescaledb_internal._hyper_5_1_chunk ALTER COLUMN request_params SET DEFAULT '"{}"'::jsonb;


--
-- Name: _hyper_5_2_chunk event_name; Type: DEFAULT; Schema: _timescaledb_internal; Owner: -
--
Expand Down Expand Up @@ -211,6 +219,13 @@ ALTER TABLE ONLY _timescaledb_internal._hyper_5_2_chunk ALTER COLUMN event_props
ALTER TABLE ONLY _timescaledb_internal._hyper_5_2_chunk ALTER COLUMN raw_event SET DEFAULT '{}'::jsonb;


--
-- Name: _hyper_5_2_chunk request_params; Type: DEFAULT; Schema: _timescaledb_internal; Owner: -
--

ALTER TABLE ONLY _timescaledb_internal._hyper_5_2_chunk ALTER COLUMN request_params SET DEFAULT '"{}"'::jsonb;


--
-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -304,6 +319,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210311071834'),
('20210311151807'),
('20210311173212'),
('20210311175013');
('20210311175013'),
('20210312171927');


1 change: 1 addition & 0 deletions test/fixtures/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# referrer_source :string
# region :string
# request_number :integer
# request_params :jsonb
# screen_resolution :string
# session_count :integer
# session_engagement :boolean default(FALSE)
Expand Down

0 comments on commit e99ea85

Please sign in to comment.