Skip to content

Commit

Permalink
fix(analytics-browser): should track file download when with url params
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Oct 18, 2024
1 parent 29aec29 commit e11756e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const fileDownloadTracking = (): EnrichmentPlugin => {
};

const ext =
/\.(pdf|xlsx?|docx?|txt|rtf|csv|exe|key|pp(s|t|tx)|7z|pkg|rar|gz|zip|avi|mov|mp4|mpe?g|wmv|midi?|mp3|wav|wma)$/;
/\.(pdf|xlsx?|docx?|txt|rtf|csv|exe|key|pp(s|t|tx)|7z|pkg|rar|gz|zip|avi|mov|mp4|mpe?g|wmv|midi?|mp3|wav|wma)(\?.+)?$/;

// Adds listener to existing anchor tags
const links = Array.from(document.getElementsByTagName('a'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ describe('fileDownloadTracking', () => {
expect(amplitude.track).toHaveBeenCalledTimes(0);
});

test('should track file_download event', async () => {
test.each([
'https://analytics.amplitude.com/files/my-file.pdf',
'https://analytics.amplitude.com/files/my-file.pdf?foo=bar',
])('should track file_download event', async (value) => {
// setup
document.getElementById('my-link-id')?.setAttribute('href', 'https://analytics.amplitude.com/files/my-file.pdf');
document.getElementById('my-link-id')?.setAttribute('href', value);
const config = createConfigurationMock();
const plugin = fileDownloadTracking();
await plugin.setup?.(config, amplitude);
Expand All @@ -54,7 +57,7 @@ describe('fileDownloadTracking', () => {
[FILE_NAME]: '/files/my-file.pdf',
[LINK_ID]: 'my-link-id',
[LINK_TEXT]: 'my-link-text',
[LINK_URL]: 'https://analytics.amplitude.com/files/my-file.pdf',
[LINK_URL]: value,
});

// stop observer and listeners
Expand Down

0 comments on commit e11756e

Please sign in to comment.