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
f8ff1969
Commit
f8ff1969
authored
Feb 23, 2021
by
Doug Stull
Committed by
Enrique Alcántara
Feb 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DOMContentLoaded event listener for snowplow tracking
- otherwise the mounted events will not fire correctly.
parent
2178384e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
13 deletions
+54
-13
app/assets/javascripts/pages/groups/show/index.js
app/assets/javascripts/pages/groups/show/index.js
+2
-4
app/assets/javascripts/tracking.js
app/assets/javascripts/tracking.js
+31
-9
spec/frontend/tracking_spec.js
spec/frontend/tracking_spec.js
+21
-0
No files found.
app/assets/javascripts/pages/groups/show/index.js
View file @
f8ff1969
import
leaveByUrl
from
'
~/namespaces/leave_by_url
'
;
import
initGroupDetails
from
'
../shared/group_details
'
;
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
leaveByUrl
(
'
group
'
);
initGroupDetails
();
});
leaveByUrl
(
'
group
'
);
initGroupDetails
();
app/assets/javascripts/tracking.js
View file @
f8ff1969
...
...
@@ -61,30 +61,51 @@ const eventHandlers = (category, func) => {
return
handlers
;
};
const
dispatchEvent
=
(
category
=
document
.
body
.
dataset
.
page
,
action
=
'
generic
'
,
data
=
{})
=>
{
// eslint-disable-next-line @gitlab/require-i18n-strings
if
(
!
category
)
throw
new
Error
(
'
Tracking: no category provided for tracking.
'
);
const
{
label
,
property
,
value
}
=
data
;
const
contexts
=
[
STANDARD_CONTEXT
];
if
(
data
.
context
)
{
contexts
.
push
(
data
.
context
);
}
return
window
.
snowplow
(
'
trackStructEvent
'
,
category
,
action
,
label
,
property
,
value
,
contexts
);
};
export
default
class
Tracking
{
static
queuedEvents
=
[];
static
initialized
=
false
;
static
trackable
()
{
return
!
[
'
1
'
,
'
yes
'
].
includes
(
window
.
doNotTrack
||
navigator
.
doNotTrack
||
navigator
.
msDoNotTrack
,
);
}
static
flushPendingEvents
()
{
this
.
initialized
=
true
;
while
(
this
.
queuedEvents
.
length
)
{
dispatchEvent
(...
this
.
queuedEvents
.
shift
());
}
}
static
enabled
()
{
return
typeof
window
.
snowplow
===
'
function
'
&&
this
.
trackable
();
}
static
event
(
category
=
document
.
body
.
dataset
.
page
,
action
=
'
generic
'
,
data
=
{}
)
{
static
event
(
...
eventData
)
{
if
(
!
this
.
enabled
())
return
false
;
// eslint-disable-next-line @gitlab/require-i18n-strings
if
(
!
category
)
throw
new
Error
(
'
Tracking: no category provided for tracking.
'
);
const
{
label
,
property
,
value
}
=
data
;
const
contexts
=
[
STANDARD_CONTEXT
];
if
(
data
.
context
)
{
contexts
.
push
(
data
.
context
);
if
(
!
this
.
initialized
)
{
this
.
queuedEvents
.
push
(
eventData
);
return
false
;
}
return
window
.
snowplow
(
'
trackStructEvent
'
,
category
,
action
,
label
,
property
,
value
,
contexts
);
return
dispatchEvent
(...
eventData
);
}
static
bindDocument
(
category
=
document
.
body
.
dataset
.
page
,
parent
=
document
)
{
...
...
@@ -143,6 +164,7 @@ export function initUserTracking() {
window
.
snowplow
(
'
newTracker
'
,
opts
.
namespace
,
opts
.
hostname
,
opts
);
document
.
dispatchEvent
(
new
Event
(
'
SnowplowInitialized
'
));
Tracking
.
flushPendingEvents
();
}
export
function
initDefaultTrackers
()
{
...
...
spec/frontend/tracking_spec.js
View file @
f8ff1969
...
...
@@ -149,6 +149,27 @@ describe('Tracking', () => {
});
});
describe
(
'
.flushPendingEvents
'
,
()
=>
{
it
(
'
flushes any pending events
'
,
()
=>
{
Tracking
.
initialized
=
false
;
Tracking
.
event
(
'
_category_
'
,
'
_eventName_
'
,
{
label
:
'
_label_
'
});
expect
(
snowplowSpy
).
not
.
toHaveBeenCalled
();
Tracking
.
flushPendingEvents
();
expect
(
snowplowSpy
).
toHaveBeenCalledWith
(
'
trackStructEvent
'
,
'
_category_
'
,
'
_eventName_
'
,
'
_label_
'
,
undefined
,
undefined
,
[
STANDARD_CONTEXT
],
);
});
});
describe
(
'
tracking interface events
'
,
()
=>
{
let
eventSpy
;
...
...
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