Commit 24e09184 authored by Alishan Ladhani's avatar Alishan Ladhani

Parse and save structured event fields in snowplow collector

- Add mappings for structured event params
- Update tests
parent 3f6b3993
...@@ -40,7 +40,12 @@ module ProductAnalytics ...@@ -40,7 +40,12 @@ module ProductAnalytics
domain_userid: params['duid'], domain_userid: params['duid'],
user_fingerprint: params['fp'], user_fingerprint: params['fp'],
page_referrer: params['refr'], page_referrer: params['refr'],
page_url: params['url'] page_url: params['url'],
se_category: params['se_ca'],
se_action: params['se_ac'],
se_label: params['se_la'],
se_property: params['se_pr'],
se_value: params['se_va']
} }
end end
......
...@@ -12,5 +12,10 @@ ...@@ -12,5 +12,10 @@
"lang":"en-US", "lang":"en-US",
"cookie":"1", "cookie":"1",
"tz":"America/Los_Angeles", "tz":"America/Los_Angeles",
"cs":"UTF-8" "cs":"UTF-8",
"se_ca": "category",
"se_ac": "action",
"se_la": "label",
"se_pr": "property",
"se_va": 12.34
} }
...@@ -23,7 +23,12 @@ RSpec.describe ProductAnalytics::EventParams do ...@@ -23,7 +23,12 @@ RSpec.describe ProductAnalytics::EventParams do
br_lang: 'en-US', br_lang: 'en-US',
br_cookies: true, br_cookies: true,
os_timezone: 'America/Los_Angeles', os_timezone: 'America/Los_Angeles',
doc_charset: 'UTF-8' doc_charset: 'UTF-8',
se_category: 'category',
se_action: 'action',
se_label: 'label',
se_property: 'property',
se_value: 12.34
} }
expect(subject).to include(expected_params) expect(subject).to include(expected_params)
......
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'ProductAnalytics::CollectorApp' do RSpec.describe 'ProductAnalytics::CollectorApp' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:params) { {} } let(:params) { {} }
let(:raw_event) { Gitlab::Json.parse(fixture_file('product_analytics/event.json')) }
subject { get '/-/collector/i', params: params } subject { get '/-/collector/i', params: params }
...@@ -17,24 +18,7 @@ RSpec.describe 'ProductAnalytics::CollectorApp' do ...@@ -17,24 +18,7 @@ RSpec.describe 'ProductAnalytics::CollectorApp' do
end end
context 'correct event params' do context 'correct event params' do
let(:params) do let(:params) { raw_event.merge(aid: project.id) }
{
aid: project.id,
p: 'web',
tna: 'sp',
tv: 'js-2.14.0',
eid: SecureRandom.uuid,
duid: SecureRandom.uuid,
sid: SecureRandom.uuid,
vid: 4,
url: 'http://example.com/products/1',
refr: 'http://example.com/products/1',
lang: 'en-US',
cookie: true,
tz: 'America/Los_Angeles',
cs: 'UTF-8'
}
end
it 'repond with 200' do it 'repond with 200' do
expect { subject }.to change { ProductAnalyticsEvent.count }.by(1) expect { subject }.to change { ProductAnalyticsEvent.count }.by(1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment