summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/tracking.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/tracking.js')
-rw-r--r--app/assets/javascripts/tracking.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/assets/javascripts/tracking.js b/app/assets/javascripts/tracking.js
index cdfecceb78a..d2e69bc06cf 100644
--- a/app/assets/javascripts/tracking.js
+++ b/app/assets/javascripts/tracking.js
@@ -153,6 +153,21 @@ export default class Tracking {
return loadEvents;
}
+ 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);
+ }
+
static mixin(opts = {}) {
return {
computed: {