Skip to content

Commit 4a48857

Browse files
app_download event now genereate
1 parent 0b9543e commit 4a48857

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

electron/src/main/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ let workingDirWatcher: fs.FSWatcher | null = null;
2323
let debounceTimer: NodeJS.Timeout | null = null;
2424

2525
const analyticsConfig = {
26-
measurementId:
27-
process.env.GA_MEASUREMENT_ID || __GA_MEASUREMENT_ID__ || "",
26+
measurementId: process.env.GA_MEASUREMENT_ID || __GA_MEASUREMENT_ID__ || "",
2827
apiSecret: process.env.GA_API_SECRET || __GA_API_SECRET__ || "",
2928
debug:
3029
process.env.GA_DEBUG === "1" ||

web/src/EventHandlersForDownloadButton.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
declare global {
22
interface Window {
33
gtag?: (...args: any[]) => void;
4+
dataLayer?: Array<Record<string, unknown>>;
45
}
56
}
67

7-
attachDownloadTracking();
8+
if (document.readyState === "loading") {
9+
window.addEventListener("DOMContentLoaded", attachDownloadTracking, {
10+
once: true,
11+
});
12+
} else {
13+
attachDownloadTracking();
14+
}
815

916
function attachDownloadTracking() {
10-
const downloadButtons = document.querySelectorAll<HTMLElement>(
11-
"[data-download-os]"
12-
);
17+
const downloadButtons =
18+
document.querySelectorAll<HTMLElement>("[data-download-os]");
1319

1420
if (downloadButtons.length === 0) {
1521
console.log("No download buttons found for tracking");
@@ -24,6 +30,15 @@ function attachDownloadTracking() {
2430
os,
2531
page_path: window.location.pathname,
2632
});
33+
} else if (
34+
window.dataLayer &&
35+
typeof window.dataLayer.push === "function"
36+
) {
37+
window.dataLayer.push({
38+
event: "app_download",
39+
os,
40+
page_path: window.location.pathname,
41+
});
2742
} else {
2843
console.log("gtag not available for download tracking");
2944
}

web/src/pages/download.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ import AppleLogo from "../images/apple_logo_download.png";
202202
</script>
203203
</div>
204204

205-
<script src="../EventHandlersForDownloadButton.ts"></script>
205+
<script type="module" src="../EventHandlersForDownloadButton.ts"></script>
206206
</div>
207207
</div>
208208
</section>

web/src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ import "../styles/mimic.css";
284284
}
285285
</style>
286286

287-
<script src="../EventHandlersForDownloadButton.ts"></script>
287+
<script type="module" src="../EventHandlersForDownloadButton.ts"></script>
288288

289289
<script is:inline>
290290
// Fade-in on scroll for Step 1, 2, 3 sections

web/src/pages/usinglivevisualisation.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,4 @@ import GraphWithBlobHidden from "../images/graphwithblobhidden.png";
292292
</section>
293293
</Layout>
294294

295-
<script src="../EventHandlersForDownloadButton.ts"></script>
295+
<script type="module" src="../EventHandlersForDownloadButton.ts"></script>

0 commit comments

Comments
 (0)