mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
Fixed cleaned URLs in link table on analytics page
fixes https://github.com/TryGhost/Team/issues/1963
This commit is contained in:
parent
87a242bada
commit
bba6a4dc84
@ -13,6 +13,7 @@ export default class AnalyticsController extends Controller {
|
||||
@service ghostPaths;
|
||||
@service settings;
|
||||
@service membersUtils;
|
||||
@service utils;
|
||||
|
||||
@tracked sources = null;
|
||||
@tracked links = null;
|
||||
@ -34,20 +35,6 @@ export default class AnalyticsController extends Controller {
|
||||
return this._fetchReferrersStats.perform();
|
||||
}
|
||||
|
||||
cleanURL(url, display = false) {
|
||||
// Remove our own querystring parameters and protocol
|
||||
const removeParams = ['rel', 'attribution_id', 'attribution_type'];
|
||||
const urlObj = new URL(url);
|
||||
for (const param of removeParams) {
|
||||
urlObj.searchParams.delete(param);
|
||||
}
|
||||
if (!display) {
|
||||
return urlObj.toString();
|
||||
}
|
||||
// Return URL without protocol
|
||||
return urlObj.host + (urlObj.pathname === '/' ? '' : urlObj.pathname) + (urlObj.search ? '?' + urlObj.search : '');
|
||||
}
|
||||
|
||||
async fetchLinks() {
|
||||
if (this._fetchLinks.isRunning) {
|
||||
return this._fetchLinks.last;
|
||||
@ -78,8 +65,8 @@ export default class AnalyticsController extends Controller {
|
||||
...link,
|
||||
link: {
|
||||
...link.link,
|
||||
to: this.cleanURL(link.link.to, false),
|
||||
title: this.cleanURL(link.link.to, true)
|
||||
to: this.utils.cleanTrackedUrl(link.link.to, false),
|
||||
title: this.utils.cleanTrackedUrl(link.link.to, true)
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -5,6 +5,7 @@ import {inject as service} from '@ember/service';
|
||||
|
||||
export default class ParseMemberEventHelper extends Helper {
|
||||
@service feature;
|
||||
@service utils;
|
||||
|
||||
compute([event, hasMultipleNewsletters]) {
|
||||
const subject = event.data.member.name || event.data.member.email;
|
||||
@ -227,11 +228,7 @@ export default class ParseMemberEventHelper extends Helper {
|
||||
if (event.type === 'click_event') {
|
||||
// Clean URL
|
||||
try {
|
||||
const parsedURL = new URL(event.data.link.to);
|
||||
|
||||
// Remove protocol, querystring and hash
|
||||
// + strip trailing /
|
||||
return parsedURL.host + (parsedURL.pathname === '/' ? '' : parsedURL.pathname);
|
||||
return this.utils.cleanTrackedUrl(event.data.link.to, true);
|
||||
} catch (e) {
|
||||
// Invalid URL
|
||||
}
|
||||
|
@ -13,4 +13,24 @@ export default class UtilsService extends Service {
|
||||
|
||||
iframe.setAttribute('src', url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove tracking parameters from a URL
|
||||
* @param {string} url
|
||||
* @param {boolean} [display] Set to true to remove protocol and hash from the URL
|
||||
* @returns
|
||||
*/
|
||||
cleanTrackedUrl(url, display = false) {
|
||||
// Remove our own querystring parameters and protocol
|
||||
const removeParams = ['rel', 'attribution_id', 'attribution_type'];
|
||||
const urlObj = new URL(url);
|
||||
for (const param of removeParams) {
|
||||
urlObj.searchParams.delete(param);
|
||||
}
|
||||
if (!display) {
|
||||
return urlObj.toString();
|
||||
}
|
||||
// Return URL without protocol
|
||||
return urlObj.host + (urlObj.pathname === '/' && !urlObj.search ? '' : urlObj.pathname) + (urlObj.search ? urlObj.search : '');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user