Skip to content

Commit

Permalink
limited Google Analytics usage tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikPeters committed Nov 25, 2023
1 parent 321e9ba commit 255a7c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ document.getElementById('podloveButton').addEventListener('click', function () {
const container = document.getElementById('podlove');
container.classList.remove("d-none");
container.open = true;
gtag('event', 'podlove', {});
});

document.getElementById('copyPodloveButton').addEventListener('click', function () {
Expand Down
18 changes: 18 additions & 0 deletions src/FileExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ async function exportFileBasedOnOldTags(file, tags) {
isOrdered: true,
elements: [],
};
// collect coarse data for Google Analytics
const eventTag = {
durationMinutes: Math.round(window.chapters.duration / 60),
numChapters: window.chapters.getChapters().length,
usedImages: false,
usedURLs: false,
changedID3Fields: false,
changedCoverImage: false,
};
let chapterIndex = 0;
for (let chapter of window.chapters.getChapters()) {
if (!chapter.error) {
Expand All @@ -22,13 +31,15 @@ async function exportFileBasedOnOldTags(file, tags) {
chapterObject.tags.userDefinedUrl = {
url: chapter.url,
}
eventTag.usedURLs = true;
}
if (chapter.hasOwnProperty('imageId')) {
try {
chapterObject.tags.image = await encodeImage(window.chapterImages[chapter.imageId]);
} catch (error) {
console.error('Error encoding image:', error);
}
eventTag.usedImages = true;
}
chapterTag.push(chapterObject);
tocTag.elements.push(`chp${chapterIndex}`);
Expand All @@ -44,10 +55,12 @@ async function exportFileBasedOnOldTags(file, tags) {
if (input.value != input.dataset.oldValue) {
tags[field] = input.value;
}
eventTag.changedID3Fields = true;
}

if (window.coverImage != null) {
tags.image = await encodeImage(window.coverImage);
eventTag.changedCoverImage = true;
}

// Call the addTags function from your bundle
Expand All @@ -64,6 +77,11 @@ async function exportFileBasedOnOldTags(file, tags) {
downloadLink.download = window.currentFilename;
downloadLink.click();
});

if (window.currentFilename != "example.mp3") {
// send event to Google Analytics
gtag('event', 'export', eventTag);
}
}

export function exportFile(file) {
Expand Down

0 comments on commit 255a7c8

Please sign in to comment.