referrers for all platforms (#4514)
This commit is contained in:
parent
83e8522e0a
commit
8b121af2e4
12 changed files with 213 additions and 34 deletions
|
@ -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 {Referrer} from '../../../modules/expo-bluesky-swiss-army'
|
||||
|
||||
type IntentType = 'compose'
|
||||
|
||||
|
@ -15,6 +18,16 @@ export function useIntentHandler() {
|
|||
|
||||
React.useEffect(() => {
|
||||
const handleIncomingURL = (url: string) => {
|
||||
Referrer.getReferrerInfoAsync().then(info => {
|
||||
if (info && info.hostname !== 'bsky.app') {
|
||||
logEvent('deepLink:referrerReceived', {
|
||||
to: url,
|
||||
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
|
||||
|
|
|
@ -25,6 +25,11 @@ export type LogEvents = {
|
|||
}
|
||||
'state:foreground:sampled': {}
|
||||
'router:navigate:sampled': {}
|
||||
'deepLink:referrerReceived': {
|
||||
to: string
|
||||
referrer: string
|
||||
hostname: string
|
||||
}
|
||||
|
||||
// Screen events
|
||||
'splash:signInPressed': {}
|
||||
|
|
|
@ -28,8 +28,6 @@ type StatsigUser = {
|
|||
bundleDate: number
|
||||
refSrc: string
|
||||
refUrl: string
|
||||
referrer: string
|
||||
referrerHostname: string
|
||||
appLanguage: string
|
||||
contentLanguages: string[]
|
||||
}
|
||||
|
@ -37,29 +35,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[]) {
|
||||
|
@ -222,8 +203,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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue