Pass referrer on native (with an opt out) (#6648)
* Pass referer on native * Add ChainLink3 * Add an opt out for sending utm * Remove noreferrer on links We do have <meta name="referrer" content="origin-when-cross-origin"> in HTML, should be sufficient. * Narrow down the condition slightly --------- Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
@@ -4,12 +4,14 @@ import * as WebBrowser from 'expo-web-browser'
|
||||
|
||||
import {
|
||||
createBskyAppAbsoluteUrl,
|
||||
isBskyAppUrl,
|
||||
isBskyRSSUrl,
|
||||
isRelativeUrl,
|
||||
} from '#/lib/strings/url-helpers'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useInAppBrowser} from '#/state/preferences/in-app-browser'
|
||||
import {useOptOutOfUtm} from '#/state/preferences/opt-out-of-utm'
|
||||
import {useTheme} from '#/alf'
|
||||
import {useSheetWrapper} from '#/components/Dialog/sheet-wrapper'
|
||||
|
||||
@@ -18,6 +20,7 @@ export function useOpenLink() {
|
||||
const enabled = useInAppBrowser()
|
||||
const t = useTheme()
|
||||
const sheetWrapper = useSheetWrapper()
|
||||
const optOutOfUtm = useOptOutOfUtm()
|
||||
|
||||
const openLink = useCallback(
|
||||
async (url: string, override?: boolean) => {
|
||||
@@ -26,6 +29,9 @@ export function useOpenLink() {
|
||||
}
|
||||
|
||||
if (isNative && !url.startsWith('mailto:')) {
|
||||
if (!optOutOfUtm && !isBskyAppUrl(url) && url.startsWith('http')) {
|
||||
url = addUtmSource(url)
|
||||
}
|
||||
if (override === undefined && enabled === undefined) {
|
||||
openModal({
|
||||
name: 'in-app-browser-consent',
|
||||
@@ -47,8 +53,24 @@ export function useOpenLink() {
|
||||
}
|
||||
Linking.openURL(url)
|
||||
},
|
||||
[enabled, openModal, t, sheetWrapper],
|
||||
[enabled, openModal, t, sheetWrapper, optOutOfUtm],
|
||||
)
|
||||
|
||||
return openLink
|
||||
}
|
||||
|
||||
function addUtmSource(url: string): string {
|
||||
let parsedUrl
|
||||
try {
|
||||
parsedUrl = new URL(url)
|
||||
} catch (e) {
|
||||
return url
|
||||
}
|
||||
if (!parsedUrl.searchParams.has('utm_source')) {
|
||||
parsedUrl.searchParams.set('utm_source', 'bluesky')
|
||||
if (!parsedUrl.searchParams.has('utm_medium')) {
|
||||
parsedUrl.searchParams.set('utm_medium', 'social')
|
||||
}
|
||||
}
|
||||
return parsedUrl.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user