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
c5398a33
Commit
c5398a33
authored
Apr 22, 2021
by
jejacks0n
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable form event tracking without a whitelist
parent
cbc32912
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
app/assets/javascripts/tracking.js
app/assets/javascripts/tracking.js
+6
-1
spec/frontend/tracking_spec.js
spec/frontend/tracking_spec.js
+14
-0
No files found.
app/assets/javascripts/tracking.js
View file @
c5398a33
...
...
@@ -156,11 +156,16 @@ export default class Tracking {
static
enableFormTracking
(
config
,
contexts
=
[])
{
if
(
!
this
.
enabled
())
return
;
if
(
!
config
?.
forms
?.
whitelist
?.
length
&&
!
config
?.
fields
?.
whitelist
?.
length
)
{
// eslint-disable-next-line @gitlab/require-i18n-strings
throw
new
Error
(
'
Unable to enable form event tracking without whitelist rules.
'
);
}
contexts
.
unshift
(
STANDARD_CONTEXT
);
const
enabler
=
()
=>
window
.
snowplow
(
'
enableFormTracking
'
,
config
,
contexts
);
if
(
document
.
readyState
!==
'
loading
'
)
enabler
();
else
document
.
addEventListener
(
'
DOMContentLoaded
'
,
enabler
)
//
else document.addEventListener('DOMContentLoaded', enabler)
}
static
mixin
(
opts
=
{})
{
...
...
spec/frontend/tracking_spec.js
View file @
c5398a33
...
...
@@ -165,6 +165,20 @@ describe('Tracking', () => {
'
_passed_context_
'
,
]);
});
it
(
'
throws an error if no whitelist rules are provided
'
,
()
=>
{
const
expectedError
=
new
Error
(
'
Unable to enable form event tracking without whitelist rules.
'
,
);
expect
(()
=>
Tracking
.
enableFormTracking
()).
toThrow
(
expectedError
);
expect
(()
=>
Tracking
.
enableFormTracking
({
fields
:
{
whitelist
:
[]
}
})).
toThrow
(
expectedError
,
);
expect
(()
=>
Tracking
.
enableFormTracking
({
fields
:
{
whitelist
:
[
1
]
}
})).
not
.
toThrow
(
expectedError
,
);
});
});
describe
(
'
.flushPendingEvents
'
,
()
=>
{
...
...
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