about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-06-13 14:31:19 -0700
committerGitHub <noreply@github.com>2024-06-13 23:31:19 +0200
commitd9066a6beb4a84ab42d638810d25c002601678a4 (patch)
tree1adc97bdde83bd21845336827a821842069eb11e /src
parentd20c59e19d457ee2c57496f00dc962ea0c19a691 (diff)
downloadvoidsky-d9066a6beb4a84ab42d638810d25c002601678a4.tar.zst
add `document.referrer` to statsig custom (#4509)
* add referrer to statsig custom

dont include referrer if hostname is bsky.app

save

add `document.referrer` to statsig custom

* add a hostname field

* account for ssr

* account for ssr
Diffstat (limited to 'src')
-rw-r--r--src/lib/statsig/statsig.tsx14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx
index 166d468a1..d57f1c0aa 100644
--- a/src/lib/statsig/statsig.tsx
+++ b/src/lib/statsig/statsig.tsx
@@ -26,6 +26,8 @@ type StatsigUser = {
     bundleDate: number
     refSrc: string
     refUrl: string
+    referrer: string
+    referrerHostname: string
     appLanguage: string
     contentLanguages: string[]
   }
@@ -33,12 +35,22 @@ type StatsigUser = {
 
 let refSrc = ''
 let refUrl = ''
+let referrer = ''
+let referrerHostname = ''
 if (isWeb && typeof window !== 'undefined') {
   const params = new URLSearchParams(window.location.search)
   refSrc = params.get('ref_src') ?? ''
   refUrl = decodeURIComponent(params.get('ref_url') ?? '')
 }
 
+if (isWeb && typeof document !== 'undefined' && document != null) {
+  const url = new URL(document.referrer)
+  if (url.hostname !== 'bsky.app') {
+    referrer = document.referrer
+    referrerHostname = url.hostname
+  }
+}
+
 export type {LogEvents}
 
 function createStatsigOptions(prefetchUsers: StatsigUser[]) {
@@ -198,6 +210,8 @@ function toStatsigUser(did: string | undefined): StatsigUser {
     custom: {
       refSrc,
       refUrl,
+      referrer,
+      referrerHostname,
       platform: Platform.OS as 'ios' | 'android' | 'web',
       bundleIdentifier: BUNDLE_IDENTIFIER,
       bundleDate: BUNDLE_DATE,