diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /app/assets/javascripts/tracking/tracking.js | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'app/assets/javascripts/tracking/tracking.js')
-rw-r--r-- | app/assets/javascripts/tracking/tracking.js | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/app/assets/javascripts/tracking/tracking.js b/app/assets/javascripts/tracking/tracking.js index a1f745bc172..657e0a79911 100644 --- a/app/assets/javascripts/tracking/tracking.js +++ b/app/assets/javascripts/tracking/tracking.js @@ -1,7 +1,14 @@ import { LOAD_ACTION_ATTR_SELECTOR, DEPRECATED_LOAD_EVENT_ATTR_SELECTOR } from './constants'; import { dispatchSnowplowEvent } from './dispatch_snowplow_event'; import getStandardContext from './get_standard_context'; -import { getEventHandlers, createEventPayload, renameKey, addExperimentContext } from './utils'; +import { + getEventHandlers, + createEventPayload, + renameKey, + addExperimentContext, + getReferrersCache, + addReferrersCacheEntry, +} from './utils'; export default class Tracking { static queuedEvents = []; @@ -159,6 +166,37 @@ export default class Tracking { } /** + * Replaces the URL and referrer for the default web context + * if the replacements are available. + * + * @returns {undefined} + */ + static setAnonymousUrls() { + const { snowplowPseudonymizedPageUrl: pageUrl } = window.gl; + + if (!pageUrl) { + return; + } + + const referrers = getReferrersCache(); + const pageLinks = Object.seal({ url: '', referrer: '', originalUrl: window.location.href }); + + pageLinks.url = `${pageUrl}${window.location.hash}`; + window.snowplow('setCustomUrl', pageLinks.url); + + if (document.referrer) { + const node = referrers.find((links) => links.originalUrl === document.referrer); + + if (node) { + pageLinks.referrer = node.url; + window.snowplow('setReferrerUrl', pageLinks.referrer); + } + } + + addReferrersCacheEntry(referrers, pageLinks); + } + + /** * Returns an implementation of this class in the form of * a Vue mixin. * |