Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
65ca5f71
Commit
65ca5f71
authored
Aug 11, 2020
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a client for the Product Analytics snowplow collector
parent
2d981327
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
1 deletion
+81
-1
lib/product_analytics/tracker.rb
lib/product_analytics/tracker.rb
+31
-0
spec/lib/product_analytics/tracker_spec.rb
spec/lib/product_analytics/tracker_spec.rb
+50
-1
No files found.
lib/product_analytics/tracker.rb
View file @
65ca5f71
...
...
@@ -7,5 +7,36 @@ module ProductAnalytics
# The collector URL minus protocol and /i
COLLECTOR_URL
=
Gitlab
.
config
.
gitlab
.
url
.
sub
(
/\Ahttps?\:\/\//
,
''
)
+
'/-/collector'
class
<<
self
include
Gitlab
::
Utils
::
StrongMemoize
def
event
(
category
,
action
,
label:
nil
,
property:
nil
,
value:
nil
,
context:
nil
)
return
unless
enabled?
snowplow
.
track_struct_event
(
category
,
action
,
label
,
property
,
value
,
context
,
(
Time
.
now
.
to_f
*
1000
).
to_i
)
end
private
def
enabled?
Gitlab
::
CurrentSettings
.
usage_ping_enabled?
end
def
project_id
Gitlab
::
CurrentSettings
.
self_monitoring_project_id
end
def
snowplow
strong_memoize
(
:snowplow
)
do
SnowplowTracker
::
Tracker
.
new
(
SnowplowTracker
::
AsyncEmitter
.
new
(
COLLECTOR_URL
,
protocol:
Gitlab
.
config
.
gitlab
.
protocol
),
SnowplowTracker
::
Subject
.
new
,
Gitlab
::
Tracking
::
SNOWPLOW_NAMESPACE
,
project_id
.
to_s
)
end
end
end
end
end
spec/lib/product_analytics/tracker_spec.rb
View file @
65ca5f71
# frozen_string_literal: true
require
"spec_helper"
require
'spec_helper'
RSpec
.
describe
ProductAnalytics
::
Tracker
do
it
{
expect
(
described_class
::
URL
).
to
eq
(
'http://localhost/-/sp.js'
)
}
it
{
expect
(
described_class
::
COLLECTOR_URL
).
to
eq
(
'localhost/-/collector'
)
}
describe
'.event'
do
after
do
described_class
.
clear_memoization
(
:snowplow
)
end
context
'when usage ping is enabled'
do
let
(
:tracker
)
{
double
}
let
(
:project_id
)
{
1
}
before
do
stub_application_setting
(
usage_ping_enabled:
true
,
self_monitoring_project_id:
project_id
)
end
it
'sends an event to Product Analytics snowplow collector'
do
expect
(
SnowplowTracker
::
AsyncEmitter
)
.
to
receive
(
:new
)
.
with
(
described_class
::
COLLECTOR_URL
,
{
protocol:
'http'
})
.
and_return
(
'_emitter_'
)
expect
(
SnowplowTracker
::
Tracker
)
.
to
receive
(
:new
)
.
with
(
'_emitter_'
,
an_instance_of
(
SnowplowTracker
::
Subject
),
'gl'
,
project_id
.
to_s
)
.
and_return
(
tracker
)
freeze_time
do
expect
(
tracker
)
.
to
receive
(
:track_struct_event
)
.
with
(
'category'
,
'action'
,
'_label_'
,
'_property_'
,
'_value_'
,
nil
,
(
Time
.
current
.
to_f
*
1000
).
to_i
)
described_class
.
event
(
'category'
,
'action'
,
label:
'_label_'
,
property:
'_property_'
,
value:
'_value_'
,
context:
nil
)
end
end
end
context
'when usage ping is disabled'
do
before
do
stub_application_setting
(
usage_ping_enabled:
false
)
end
it
'does not send an event'
do
expect
(
SnowplowTracker
::
Tracker
).
not_to
receive
(
:new
)
described_class
.
event
(
'category'
,
'action'
,
label:
'_label_'
,
property:
'_property_'
,
value:
'_value_'
,
context:
nil
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment