return a promise for getReferrerInfo
This commit is contained in:
@@ -8,27 +8,29 @@ export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getReferrerInfoAsync(): Promise<ReferrerInfo | null> {
|
export function getReferrerInfoAsync(): Promise<ReferrerInfo | null> {
|
||||||
if (
|
// Returning a promise to match the functionality on native
|
||||||
Platform.OS === 'web' &&
|
return new Promise(resolve => {
|
||||||
// for ssr
|
if (
|
||||||
typeof document !== 'undefined' &&
|
Platform.OS === 'web' &&
|
||||||
document != null &&
|
// for ssr
|
||||||
document.referrer
|
typeof document !== 'undefined' &&
|
||||||
) {
|
document != null &&
|
||||||
try {
|
document.referrer
|
||||||
const url = new URL(document.referrer)
|
) {
|
||||||
if (url.hostname !== 'bsky.app') {
|
try {
|
||||||
return {
|
const url = new URL(document.referrer)
|
||||||
referrer: url.href,
|
if (url.hostname !== 'bsky.app') {
|
||||||
hostname: url.hostname,
|
resolve({
|
||||||
|
referrer: url.href,
|
||||||
|
hostname: url.hostname,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// If something happens to the URL parsing, we don't want to actually cause any problems for the user. Just
|
||||||
|
// log the error so we might catch it
|
||||||
|
console.error('Failed to parse referrer URL')
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
// If something happens to the URL parsing, we don't want to actually cause any problems for the user. Just
|
|
||||||
// log the error so we might catch it
|
|
||||||
console.error('Failed to parse referrer URL')
|
|
||||||
}
|
}
|
||||||
}
|
resolve(null)
|
||||||
|
})
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user