referrers for all platforms

This commit is contained in:
Hailey
2024-06-14 00:40:47 -07:00
parent bdeac28d74
commit 57de57ce6a
17 changed files with 379 additions and 23 deletions
+13 -1
View File
@@ -31,7 +31,7 @@ import {
} from 'lib/routes/types'
import {RouteParams, State} from 'lib/routes/types'
import {bskyTitle} from 'lib/strings/headings'
import {isAndroid, isNative} from 'platform/detection'
import {isAndroid, isNative, isWeb} from 'platform/detection'
import {PreferencesExternalEmbeds} from '#/view/screens/PreferencesExternalEmbeds'
import {AppPasswords} from 'view/screens/AppPasswords'
import {ModerationBlockedAccounts} from 'view/screens/ModerationBlockedAccounts'
@@ -43,6 +43,7 @@ import HashtagScreen from '#/screens/Hashtag'
import {ModerationScreen} from '#/screens/Moderation'
import {ProfileKnownFollowersScreen} from '#/screens/Profile/KnownFollowers'
import {ProfileLabelerLikedByScreen} from '#/screens/Profile/ProfileLabelerLikedBy'
import {GetReferrerModule} from '../modules/expo-get-referrer/src/ExpoGetReferrerModule'
import {init as initAnalytics} from './lib/analytics/analytics'
import {useWebScrollRestoration} from './lib/hooks/useWebScrollRestoration'
import {attachRouteToLogEvents, logEvent} from './lib/statsig/statsig'
@@ -728,6 +729,17 @@ function logModuleInitTime() {
initMs,
})
if (isWeb) {
GetReferrerModule.getReferrerInfoAsync().then(info => {
if (info && info.hostname !== 'bsky.app') {
logEvent('deepLink:referrerReceived', {
referrer: info?.referrer,
hostname: info?.hostname,
})
}
})
}
if (__DEV__) {
// This log is noisy, so keep false committed
const shouldLog = false
+15 -1
View File
@@ -1,9 +1,12 @@
import React from 'react'
import * as Linking from 'expo-linking'
import {logEvent} from 'lib/statsig/statsig'
import {isNative} from 'platform/detection'
import {useComposerControls} from 'state/shell'
import {useSession} from 'state/session'
import {useComposerControls} from 'state/shell'
import {useCloseAllActiveElements} from 'state/util'
import {GetReferrerModule} from '../../../modules/expo-get-referrer/src/ExpoGetReferrerModule'
type IntentType = 'compose'
@@ -15,6 +18,17 @@ export function useIntentHandler() {
React.useEffect(() => {
const handleIncomingURL = (url: string) => {
GetReferrerModule.getReferrerInfoAsync().then(info => {
console.log(info)
if (info && info.hostname !== 'bsky.app') {
logEvent('deepLink:referrerReceived', {
referrer: info?.referrer,
hostname: info?.hostname,
})
}
})
// We want to be able to support bluesky:// deeplinks. It's unnatural for someone to use a deeplink with three
// slashes, like bluesky:///intent/follow. However, supporting just two slashes causes us to have to take care
// of two cases when parsing the url. If we ensure there is a third slash, we can always ensure the first
+4
View File
@@ -25,6 +25,10 @@ export type LogEvents = {
}
'state:foreground:sampled': {}
'router:navigate:sampled': {}
'deepLink:referrerReceived': {
referrer: string
hostname: string
}
// Screen events
'splash:signInPressed': {}
-21
View File
@@ -26,8 +26,6 @@ type StatsigUser = {
bundleDate: number
refSrc: string
refUrl: string
referrer: string
referrerHostname: string
appLanguage: string
contentLanguages: string[]
}
@@ -35,29 +33,12 @@ 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 &&
document.referrer
) {
try {
const url = new URL(document.referrer)
if (url.hostname !== 'bsky.app') {
referrer = document.referrer
referrerHostname = url.hostname
}
} catch {}
}
export type {LogEvents}
function createStatsigOptions(prefetchUsers: StatsigUser[]) {
@@ -217,8 +198,6 @@ function toStatsigUser(did: string | undefined): StatsigUser {
custom: {
refSrc,
refUrl,
referrer,
referrerHostname,
platform: Platform.OS as 'ios' | 'android' | 'web',
bundleIdentifier: BUNDLE_IDENTIFIER,
bundleDate: BUNDLE_DATE,