diff --git a/web/docusaurus.config.js b/web/docusaurus.config.js
index beec065a5ad..1d7d82b5685 100755
--- a/web/docusaurus.config.js
+++ b/web/docusaurus.config.js
@@ -244,6 +244,7 @@ module.exports = {
},
],
],
+ scripts: [{ src: '/scripts/telemetry.js' }],
// plugins: [
// // [
// // '@docusaurus/plugin-content-docs',
diff --git a/web/static/scripts/telemetry.js b/web/static/scripts/telemetry.js
new file mode 100644
index 00000000000..852a55f680e
--- /dev/null
+++ b/web/static/scripts/telemetry.js
@@ -0,0 +1,18 @@
+function telemetry() {
+ return fetch('https://app.supabase.io/api/telemetry/page', {
+ mode: 'no-cors', // 'cors' by default,
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json',
+ },
+ body: JSON.stringify({
+ referrer: document.referrer,
+ title: document.title,
+ }),
+ }).catch((error) => {
+ console.error('Error at telemetry - post:', error)
+ })
+}
+
+telemetry()
diff --git a/www/lib/fetchWrapper.ts b/www/lib/fetchWrapper.ts
new file mode 100644
index 00000000000..763c9d4c50b
--- /dev/null
+++ b/www/lib/fetchWrapper.ts
@@ -0,0 +1,19 @@
+interface DataProps {
+ referrer?: string
+ title: string
+}
+
+export const post = (url: string, data: DataProps, options = {}) => {
+ return fetch(url, {
+ mode: 'no-cors', // 'cors' by default,
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json',
+ },
+ body: JSON.stringify(data),
+ ...options,
+ }).catch((error) => {
+ console.error('Error at fetchWrapper - post:', error)
+ })
+}
diff --git a/www/pages/_app.tsx b/www/pages/_app.tsx
index 6ac887c0430..890778ceeeb 100644
--- a/www/pages/_app.tsx
+++ b/www/pages/_app.tsx
@@ -1,6 +1,39 @@
import { AppProps } from 'next/app'
+import { useRouter } from 'next/router'
+import { useEffect } from 'react'
import '../styles/index.css'
+import { post } from './../lib/fetchWrapper'
export default function MyApp({ Component, pageProps }: AppProps) {
+ const router = useRouter()
+
+ function telemetry() {
+ return post(`https://app.supabase.io/api/telemetry/page`, {
+ referrer: document.referrer,
+ title: document.title,
+ })
+ }
+
+ useEffect(() => {
+ // `routeChangeComplete` won't run for the first page load unless the query string is
+ // hydrated later on, so here we log a page view if this is the first render and
+ // there's no query string
+ if (!router.asPath.includes('?')) {
+ telemetry()
+ }
+ }, [])
+
+ useEffect(() => {
+ function handleRouteChange() {
+ telemetry()
+ }
+
+ // Listen for page changes after a navigation or when the query changes
+ router.events.on('routeChangeComplete', handleRouteChange)
+ return () => {
+ router.events.off('routeChangeComplete', handleRouteChange)
+ }
+ }, [router.events])
+
return