Commit 0bb663cc authored by Peter Hegman's avatar Peter Hegman

Merge branch '518-do-not-remove-note-and-diff-anchors' into 'master'

Do not anonymize #note and #diff anchors in URLs

See merge request gitlab-org/gitlab!82273
parents d85eee06 d74153ce
......@@ -10,6 +10,8 @@ import {
addReferrersCacheEntry,
} from './utils';
const ALLOWED_URL_HASHES = ['#diff', '#note'];
export default class Tracking {
static queuedEvents = [];
static initialized = false;
......@@ -183,7 +185,9 @@ export default class Tracking {
originalUrl: window.location.href,
});
window.snowplow('setCustomUrl', pageLinks.url);
const appendHash = ALLOWED_URL_HASHES.some((prefix) => window.location.hash.startsWith(prefix));
const customUrl = `${pageUrl}${appendHash ? window.location.hash : ''}`;
window.snowplow('setCustomUrl', customUrl);
if (document.referrer) {
const node = referrers.find((links) => links.originalUrl === document.referrer);
......
......@@ -255,6 +255,23 @@ describe('Tracking', () => {
expect(snowplowSpy).toHaveBeenCalledWith('setCustomUrl', TEST_HOST);
});
describe('allowed hashes/fragments', () => {
it.each`
hash | appends | description
${'note_abc_123'} | ${true} | ${'appends'}
${'diff-content-819'} | ${true} | ${'appends'}
${'first_heading'} | ${false} | ${'does not append'}
`('$description `$hash` hash', ({ hash, appends }) => {
window.gl.snowplowPseudonymizedPageUrl = TEST_HOST;
window.location.hash = hash;
Tracking.setAnonymousUrls();
const url = appends ? `${TEST_HOST}#${hash}` : TEST_HOST;
expect(snowplowSpy).toHaveBeenCalledWith('setCustomUrl', url);
});
});
it('does not set the referrer URL by default', () => {
window.gl.snowplowPseudonymizedPageUrl = TEST_HOST;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment