diff --git a/app/models/hyper/event.rb b/app/models/hyper/event.rb index 04604d8..c21fb43 100644 --- a/app/models/hyper/event.rb +++ b/app/models/hyper/event.rb @@ -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) diff --git a/config/initializers/traffic_detector.rb b/config/initializers/traffic_detector.rb index d1e05f8..ce1707c 100644 --- a/config/initializers/traffic_detector.rb +++ b/config/initializers/traffic_detector.rb @@ -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", diff --git a/db/hyper_migrate/20210312171927_add_request_params.rb b/db/hyper_migrate/20210312171927_add_request_params.rb new file mode 100644 index 0000000..8298e4c --- /dev/null +++ b/db/hyper_migrate/20210312171927_add_request_params.rb @@ -0,0 +1,5 @@ +class AddRequestParams < ActiveRecord::Migration[6.1] + def change + add_column :events, :request_params, :jsonb, default: '{}' + end +end diff --git a/db/hyper_structure.sql b/db/hyper_structure.sql index dc01f1a..082f4fd 100644 --- a/db/hyper_structure.sql +++ b/db/hyper_structure.sql @@ -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 ); @@ -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: - -- @@ -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: - -- @@ -304,6 +319,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210311071834'), ('20210311151807'), ('20210311173212'), -('20210311175013'); +('20210311175013'), +('20210312171927'); diff --git a/test/fixtures/events.yml b/test/fixtures/events.yml index 6258492..442edd1 100644 --- a/test/fixtures/events.yml +++ b/test/fixtures/events.yml @@ -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)