Skip to content

Commit

Permalink
fix: more analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperorb committed Mar 10, 2024
1 parent 2aa1300 commit b16406e
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
<meta name="viewport" content="width=device-width" />
<meta
name="description"
content=" Intl Explorer is an interactive tool for experimenting and trying out the ECMAScript Internationalization API."
content="Intl Explorer is an interactive tool for experimenting and trying out the ECMAScript Internationalization API."
/>
<meta
property="og:description"
content="Intl Explorer is an interactive tool for experimenting and trying out the ECMAScript Internationalization API." />
<meta property="og:title" content="Intl Explorer" />
<title>Intl Explorer</title>
%sveltekit.head%
</head>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { selectedLocale } from '$lib/store/selected-locale';
import { testIds } from '$lib/utils/dom-utils';
import Spacing from '$lib/components/ui/Spacing.svelte';
import OpenInNewTab from '$lib/components/ui/icons/OpenInNewTab.svelte';
const matchMedia = browser ? window.matchMedia('(min-width: 900px)') : null;
const locale = browser ? $selectedLocale : getLocaleForSSR($page);
Expand Down Expand Up @@ -97,7 +98,8 @@
class="github"
href="https://github.com/jesperorb/intl-explorer"
target="_blank"
rel="noopener noreferrer">GitHub</a
data-umami-event="GitHub Link"
rel="noopener noreferrer">GitHub <OpenInNewTab /></a
>
</li>
</ul>
Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/Collator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import ComboBoxContext from '$lib/components/ui/ComboBox/ComboBoxContext.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -23,6 +24,11 @@
await copyToClipboard(
`[].sort(new Intl.Collator("${locale}", ${JSON.stringify(options)}).compare)`
);
trackEvent("Copy Code", {
method: "Collator",
options: JSON.stringify(options),
locale,
})
};
</script>

Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/DateTimeFormat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import Spacing from '$lib/components/ui/Spacing.svelte';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -33,6 +34,11 @@
options
)}).format(new Date("${dateTimeString}"))`
);
trackEvent("Copy Code", {
method: "DateTimeFormat",
options: JSON.stringify(options),
locale,
})
};
</script>

Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/ListFormat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import Spacing from '$lib/components/ui/Spacing.svelte';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -28,6 +29,11 @@
await copyToClipboard(
`new Intl.ListFormat("${locale}", ${JSON.stringify(options)}).format([])`
);
trackEvent("Copy Code", {
method: "ListFormat",
options: JSON.stringify(options),
locale,
})
};
const style = listFormatOptions.style ?? [];
Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/NumberFormat.Currency.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import ComboBoxContext from '$lib/components/ui/ComboBox/ComboBoxContext.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import Spacing from '$lib/components/ui/Spacing.svelte';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -35,6 +36,11 @@
await copyToClipboard(
`new Intl.NumberFormat("${locale}", ${JSON.stringify(options)}).format(${number})`
);
trackEvent("Copy Code", {
method: "NumberFormat",
options: JSON.stringify(options),
locale,
})
};
</script>

Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/NumberFormat.Unit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import Spacing from '$lib/components/ui/Spacing.svelte';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -35,6 +36,11 @@
await copyToClipboard(
`new Intl.NumberFormat("${locale}", ${JSON.stringify(options)}).format(${number})`
);
trackEvent("Copy Code", {
method: "NumberFormat",
options: JSON.stringify(options),
locale,
})
};
</script>

Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/NumberFormat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import Spacing from '$lib/components/ui/Spacing.svelte';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -32,6 +33,11 @@
await copyToClipboard(
`new Intl.NumberFormat("${locale}", ${JSON.stringify(options)}).format(${number})`
);
trackEvent("Copy Code", {
method: "NumberFormat",
options: JSON.stringify(options),
locale,
})
};
</script>

Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/PluralRules.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ComboBoxContext from '$lib/components/ui/ComboBox/ComboBoxContext.svelte';
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import Spacing from '$lib/components/ui/Spacing.svelte';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -23,6 +24,11 @@
Object.assign({}, options, { value: undefined })
)}).select(${options.value})`
);
trackEvent("Copy Code", {
method: "PluralRules",
options: JSON.stringify(options),
locale,
})
};
</script>

Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/RelativeTimeFormat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ComboBoxContext from '$lib/components/ui/ComboBox/ComboBoxContext.svelte';
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import { trackEvent } from '$lib/utils/analytics';
export let locale: string;
export let browserCompatData: BrowserCompatData | null;
Expand All @@ -23,6 +24,11 @@
Object.assign({}, options, { value: undefined })
)}).format(${dayValue}, "${options.value}")`
);
trackEvent("Copy Code", {
method: "RelativeTimeFormat",
options: JSON.stringify(options),
locale,
})
};
let dayValue = 2;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/components/pages/Segmenter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte';
import { selectedLocale } from '$lib/store/selected-locale';
import Spacing from '$lib/components/ui/Spacing.svelte';
import { trackEvent } from '$lib/utils/analytics';
let sentence = 'This is a sentence.';
export let locale: string;
Expand All @@ -25,6 +26,11 @@
options
)}).segment("${sentence}"))`
);
trackEvent("Copy Code", {
method: "Segmenter",
options: JSON.stringify(options),
locale,
})
};
const getOutput = (options: OptionValues) => {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/ui/MDNLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
header
)}"
target="_blank"
data-umami-event="MDN Link"
data-umami-event-method="{header}"
rel="noopener noreferrer">MDN<OpenInNewTab /></a
>
4 changes: 4 additions & 0 deletions src/lib/store/selected-locale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { browser } from '$app/environment';
import { trackEvent } from '$lib/utils/analytics';
import { getLocaleFromParams, localeFallback, localeKey } from '$lib/utils/get-locale';
import { writable } from 'svelte/store';

Expand All @@ -8,6 +9,9 @@ selectedLocale.subscribe((value) => {
if (browser) {
const params = new URLSearchParams(window.location.search);
params.set(localeKey, value);
trackEvent("Change Locale", {
locale: value,
})
window.history.replaceState(
{},
'',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type AnalyticEvents = 'Change Schema'
| 'Copy Code'
| 'Change Option'
| 'Parse Schema'
| 'View Browser Support'
| 'Change Locale'

export const trackEvent = (
name: AnalyticEvents,
Expand Down
3 changes: 3 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type { Page } from '@sveltejs/kit';
import { dev } from '$app/environment';
import type { FormatMethodsKeys } from '$lib/format-methods';
import { page, navigating } from '$app/stores';
Expand All @@ -18,7 +19,9 @@

<svelte:head>
<title>{routeId ?? 'Intl Explorer'}</title>
{#if !dev}
<script defer src="https://umami-xi-eosin.vercel.app/script.js" data-website-id="a1ca3232-d4d8-44ac-92f0-656a91ceb36c"></script>
{/if}
</svelte:head>

<SkipLink />
Expand Down

0 comments on commit b16406e

Please sign in to comment.