From 255a7c8319929b4dc0e3a38662ca4a64efcc2032 Mon Sep 17 00:00:00 2001 From: Dominik Peters Date: Sat, 25 Nov 2023 18:25:56 +0100 Subject: [PATCH] limited Google Analytics usage tracking --- main.js | 1 + src/FileExport.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/main.js b/main.js index f77ac0a..5b175de 100644 --- a/main.js +++ b/main.js @@ -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 () { diff --git a/src/FileExport.js b/src/FileExport.js index 8d3ab17..b5f7ce4 100644 --- a/src/FileExport.js +++ b/src/FileExport.js @@ -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) { @@ -22,6 +31,7 @@ async function exportFileBasedOnOldTags(file, tags) { chapterObject.tags.userDefinedUrl = { url: chapter.url, } + eventTag.usedURLs = true; } if (chapter.hasOwnProperty('imageId')) { try { @@ -29,6 +39,7 @@ async function exportFileBasedOnOldTags(file, tags) { } catch (error) { console.error('Error encoding image:', error); } + eventTag.usedImages = true; } chapterTag.push(chapterObject); tocTag.elements.push(`chp${chapterIndex}`); @@ -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 @@ -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) {