diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /app/assets/javascripts/tracking | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) | |
download | gitlab-ce-e8d2c2579383897a1dd7f9debd359abe8ae8373d.tar.gz |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'app/assets/javascripts/tracking')
-rw-r--r-- | app/assets/javascripts/tracking/index.js | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/app/assets/javascripts/tracking/index.js b/app/assets/javascripts/tracking/index.js index e0ba7dba97f..3714cac3fba 100644 --- a/app/assets/javascripts/tracking/index.js +++ b/app/assets/javascripts/tracking/index.js @@ -34,6 +34,12 @@ const addExperimentContext = (opts) => { return options; }; +const renameKey = (o, oldKey, newKey) => { + const ret = {}; + delete Object.assign(ret, o, { [newKey]: o[oldKey] })[oldKey]; + return ret; +}; + const createEventPayload = (el, { suffix = '' } = {}) => { const { trackAction, @@ -186,15 +192,18 @@ export default class Tracking { (context) => context.schema !== standardContext.schema, ); - const mappedConfig = { - forms: { whitelist: config.forms?.allow || [] }, - fields: { whitelist: config.fields?.allow || [] }, - }; + const mappedConfig = {}; + if (config.forms) mappedConfig.forms = renameKey(config.forms, 'allow', 'whitelist'); + if (config.fields) mappedConfig.fields = renameKey(config.fields, 'allow', 'whitelist'); const enabler = () => window.snowplow('enableFormTracking', mappedConfig, userProvidedContexts); - if (document.readyState !== 'loading') enabler(); - else document.addEventListener('DOMContentLoaded', enabler); + if (document.readyState === 'complete') enabler(); + else { + document.addEventListener('readystatechange', () => { + if (document.readyState === 'complete') enabler(); + }); + } } static mixin(opts = {}) { |