Explore: Remove click tracking for external links (#66801)

Remove click tracking for external links
This commit is contained in:
Kristina 2023-04-19 10:40:25 -05:00 committed by GitHub
parent 035bf29146
commit d1a918489e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 33 deletions

View File

@ -57,15 +57,7 @@ describe('explore links utils', () => {
expect(links[0].href).toBe('http://regionalhost');
expect(links[0].title).toBe('external');
expect(links[0].onClick).toBeDefined();
links[0].onClick!({});
expect(reportInteraction).toBeCalledWith('grafana_data_link_clicked', {
app: CoreApp.Explore,
internal: false,
origin: DataLinkConfigOrigin.Datasource,
});
expect(links[0].onClick).not.toBeDefined();
});
it('returns generates title for external link', () => {

View File

@ -122,30 +122,6 @@ export const getFieldLinksForExplore = (options: {
if (!linkModel.title) {
linkModel.title = getTitleFromHref(linkModel.href);
}
// Take over the onClick to report the click, then either call the original onClick or navigate to the URL
// Note: it is likely that an external link that opens in the same tab will not be reported, as the browser redirect might cancel reporting the interaction
const origOnClick = linkModel.onClick;
linkModel.onClick = (...args) => {
reportInteraction(DATA_LINK_USAGE_KEY, {
origin: link.origin || DataLinkConfigOrigin.Datasource,
app: CoreApp.Explore,
internal: false,
});
if (origOnClick) {
origOnClick?.apply(...args);
} else {
// for external links without an onClick, we want to duplicate default href behavior since onClick stops it
if (linkModel.target === '_blank') {
window.open(linkModel.href);
} else {
window.location.href = linkModel.href;
}
}
};
return linkModel;
} else {
let internalLinkSpecificVars: ScopedVars = {};