Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into darkyzhou-blog
Browse files Browse the repository at this point in the history
  • Loading branch information
darkyzhou committed Mar 3, 2024
2 parents ad95c60 + d5aafe9 commit 2df3501
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/Analytics.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import basicConfiguration from '../../config/basic-configuration.yml';
import { browser } from '$app/environment';
import { afterNavigate } from '$app/navigation';
export let gaMeasurementId;
export let baiduId;
Expand All @@ -21,12 +22,22 @@
const userAgent = navigator.userAgent.toLocaleLowerCase();
return basicConfiguration.analytics.blockedUAs?.some((ua) => userAgent.includes(ua));
}
afterNavigate(() => {
if (!enabled) {
return;
}
if (window.umami) {
window.umami.track();
}
});
</script>
<svelte:head>
{#if enabled}
{#if gaMeasurementId}
<script src="https://www.googletagmanager.com/gtag/js?id=${gaMeasurementId}" async></script>
<script src="https://www.googletagmanager.com/gtag/js?id={gaMeasurementId}" async></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
Expand All @@ -37,12 +48,12 @@
</script>
{/if}
{#if baiduId}
<script src="https://hm.baidu.com/hm.js?${baiduId}" async></script>
<script src="https://hm.baidu.com/hm.js?{baiduId}" async></script>
{/if}
{#if umamiId}
<script
src="https://analytics.us.umami.is/script.js"
data-website-id="${umamiId}"
data-website-id={umamiId}
async
></script>
{/if}
Expand Down

0 comments on commit 2df3501

Please sign in to comment.