Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

referrers for all platforms #4514

Merged
merged 30 commits into from
Jul 12, 2024
Merged

referrers for all platforms #4514

merged 30 commits into from
Jul 12, 2024

Conversation

haileyok
Copy link
Contributor

@haileyok haileyok commented Jun 14, 2024

Relies on #4654

Why

We currently are not able to track referrers if the user is on native. This PR introduces a way for us to - when possible - see those referrals.

How

There's a little bit of native code needed on each platform.

iOS

On iOS, we can get the referrerURL from NSUserActivity. See https://developer.apple.com/documentation/foundation/nsuseractivity/2875762-referrerurl

This requires a little plugin to add some code to our AppDelegate.mm. Whenever a user opens the app through a Universal Link, we can - when it is provided by the browser - record the referrer URL here. To make things simple and reduce the scope of the plugin, I am just storing the URL to NSUserDefaults and then retrieving it in our module.

We also are able to get the same for deep links, also in the AppDelegate. See https://developer.apple.com/documentation/uikit/uiapplicationopenurloptionssourceapplicationkey

The same process is used here: save the value to NSUserDefaults and retrieve it through our module.

The build plugin in this PR adds the necessary lines to the AppDelegate.mm file to achieve this.

Android

On Android, we need to do two things to get this information:

  • Check incoming intents for Intent.EXTRA_REFERRER, which will be the URI of the website that the request is coming from - if it is coming from one.
  • Otherwise, check the current activity's referrer property, which will tell us the application the request was made from.

Since we can access these straight from the module code, all we do is store the intent whenever it comes in and return it to the JS side when calling getReferrerAsync().

The getGooglePlayReferrerInfoAsync() call uses the Google Play Install Referrer API (see https://developer.android.com/google/play/installreferrer) to retrieve the URL that referred the user to the app store. This will be used for starter packs. I've already added this code to the starter packs PR, but once we merge that in and later review this, I'll just migrate the code to use this single module instead.

Web

Same process as what exists in the app right now, but just made to follow the same API as iOS and Android.

Sending to Statsig

On iOS and Android, we will send this info to Statsig in the useIntentHandler hook, whenever we receive a new link into the app.

On web, I've moved this from being a custom user property to being it's own event - again to align with how we handle this on iOS and Android. Whenever send the init event to Statsig, we will also send this event if needed.

Test Plan

  1. Ensure the build plugin functions. Check the AppDelegate.mm to make sure it looks good (there are commented blocks that signify where code is being added). App should still build on iOS.
  2. Test web:
  • You can do this with a little console log and inspect-elementing a URL on another site to lead to Bluesky.
  1. Test Android:
  • You can add a console log into useIntentHandler to check the status
    Screenshot 2024-06-13 at 10 35 22 PM
    Screenshot 2024-06-13 at 10 35 40 PM
  1. Test iOS:
  • A good bit harder to test this one since you need to be using a physical device - or at least have it built with the correct provisioning profile - to test universal links. We should verify through Statsig that we are receiving good info from iOS devices.

Copy link

render bot commented Jun 14, 2024

Copy link

github-actions bot commented Jun 14, 2024

The Pull Request introduced fingerprint changes against the base commit:

Fingerprint diff
[{"type":"dir","filePath":"modules/expo-bluesky-swiss-army/android","reasons":["expoAutolinkingAndroid"],"hash":"7dab4983b0c8c39ed00de86fe163d32d93f5dc39"},{"type":"contents","id":"expoConfig","contents":"{\"android\":{\"adaptiveIcon\":{\"backgroundColor\":\"#1185FE\",\"backgroundImage\":\"./assets/icon-android-background.png\",\"foregroundImage\":\"./assets/icon-android-foreground.png\",\"monochromeImage\":\"./assets/icon-android-foreground.png\"},\"googleServicesFile\":\"./google-services.json\",\"icon\":\"./assets/icon.png\",\"intentFilters\":[{\"action\":\"VIEW\",\"autoVerify\":true,\"category\":[\"BROWSABLE\",\"DEFAULT\"],\"data\":[false,{\"host\":\"bsky.app\",\"scheme\":\"https\"}]}],\"package\":\"xyz.blueskyweb.app\",\"splash\":{\"backgroundColor\":\"#0c7cff\",\"dark\":{\"backgroundColor\":\"#0f141b\",\"image\":\"./assets/splash-dark.png\",\"resizeMode\":\"cover\"},\"image\":\"./assets/splash.png\",\"resizeMode\":\"cover\"}},\"androidNavigationBar\":{\"backgroundColor\":\"#0f141b\",\"barStyle\":\"light-content\"},\"androidStatusBar\":{\"backgroundColor\":\"#00000000\",\"barStyle\":\"light-content\"},\"extra\":{\"eas\":{\"build\":{\"experimental\":{\"ios\":{\"appExtensions\":[{\"bundleIdentifier\":\"xyz.blueskyweb.app.AppClip\",\"targetName\":\"BlueskyClip\"},{\"bundleIdentifier\":\"xyz.blueskyweb.app.BlueskyNSE\",\"entitlements\":{\"com.apple.security.application-groups\":[\"group.app.bsky\"]},\"targetName\":\"BlueskyNSE\"},{\"bundleIdentifier\":\"xyz.blueskyweb.app.Share-with-Bluesky\",\"entitlements\":{\"com.apple.security.application-groups\":[\"group.app.bsky\"]},\"targetName\":\"Share-with-Bluesky\"}]}}},\"projectId\":\"55bd077a-d905-4184-9c7f-94789ba0f302\"}},\"hooks\":{\"postPublish\":[{\"config\":{\"dist\":\"undefined.1.89.0.\",\"organization\":\"blueskyweb\",\"project\":\"react-native\",\"release\":\"1.89.0\"},\"file\":\"sentry-expo/upload-sourcemaps\"}]},\"icon\":\"./assets/icon.png\",\"ios\":{\"associatedDomains\":[\"appclips:bsky.app\",\"appclips:go.bsky.app\",\"applinks:bsky.app\",\"applinks:staging.bsky.app\"],\"bundleIdentifier\":\"xyz.blueskyweb.app\",\"config\":{\"usesNonExemptEncryption\":false},\"entitlements\":{\"com.apple.security.application-groups\":\"group.app.bsky\"},\"infoPlist\":{\"NSCameraUsageDescription\":\"Used for profile pictures, posts, and other kinds of content.\",\"NSMicrophoneUsageDescription\":\"Used for posts and other kinds of content.\",\"NSPhotoLibraryAddUsageDescription\":\"Used to save images to your library.\",\"NSPhotoLibraryUsageDescription\":\"Used for profile pictures, posts, and other kinds of content\",\"UIBackgroundModes\":[\"remote-notification\"]},\"privacyManifests\":{\"NSPrivacyAccessedAPITypes\":[{\"NSPrivacyAccessedAPIType\":\"NSPrivacyAccessedAPICategoryDiskSpace\",\"NSPrivacyAccessedAPITypeReasons\":[\"85F4.1\",\"E174.1\"]},{\"NSPrivacyAccessedAPIType\":\"NSPrivacyAccessedAPICategoryFileTimestamp\",\"NSPrivacyAccessedAPITypeReasons\":[\"0A2A.1\",\"3B52.1\",\"C617.1\"]},{\"NSPrivacyAccessedAPIType\":\"NSPrivacyAccessedAPICategorySystemBootTime\",\"NSPrivacyAccessedAPITypeReasons\":[\"35F9.1\"]},{\"NSPrivacyAccessedAPIType\":\"NSPrivacyAccessedAPICategoryUserDefaults\",\"NSPrivacyAccessedAPITypeReasons\":[\"1C8F.1\",\"CA92.1\"]}]},\"splash\":{\"backgroundColor\":\"#ffffff\",\"dark\":{\"backgroundColor\":\"#001429\",\"image\":\"./assets/splash-dark.png\",\"resizeMode\":\"cover\"},\"image\":\"./assets/splash.png\",\"resizeMode\":\"cover\"},\"supportsTablet\":false},\"name\":\"Bluesky\",\"orientation\":\"portrait\",\"owner\":\"blueskysocial\",\"platforms\":[\"android\",\"ios\",\"web\"],\"plugins\":[\"./plugins/notificationsExtension/withNotificationsExtension.js\",\"./plugins/shareExtension/withShareExtensions.js\",\"./plugins/starterPackAppClipExtension/withStarterPackAppClip.js\",\"./plugins/withAndroidManifestFCMIconPlugin.js\",\"./plugins/withAndroidManifestPlugin.js\",\"./plugins/withAndroidSplashScreenStatusBarTranslucentPlugin.js\",\"./plugins/withAndroidStylesAccentColorPlugin.js\",\"./plugins/withAndroidStylesWindowBackgroundPlugin.js\",\"expo-localization\",\"expo-video\",\"react-native-compressor\",[\"expo-build-properties\",{\"android\":{\"buildToolsVersion\":\"34.0.0\",\"compileSdkVersion\":34,\"kotlinVersion\":\"1.8.0\",\"newArchEnabled\":false,\"targetSdkVersion\":34},\"ios\":{\"deploymentTarget\":\"14.0\",\"newArchEnabled\":false}}],[\"expo-notifications\",{\"color\":\"#1185fe\",\"icon\":\"./assets/icon-android-notification.png\",\"sounds\":[\"assets/dm.mp3\"]}]],\"primaryColor\":\"#1083fe\",\"runtimeVersion\":{\"policy\":\"appVersion\"},\"scheme\":\"bluesky\",\"sdkVersion\":\"51.0.0\",\"slug\":\"bluesky\",\"splash\":{\"backgroundColor\":\"#ffffff\",\"image\":\"./assets/splash.png\",\"resizeMode\":\"cover\"},\"updates\":{\"checkAutomatically\":\"NEVER\",\"enabled\":false,\"fallbackToCacheTimeout\":30000,\"url\":\"https://updates.bsky.app/manifest\"},\"userInterfaceStyle\":\"automatic\",\"version\":\"1.89.0\",\"web\":{\"favicon\":\"./assets/favicon.png\"}}","reasons":["expoConfig"],"hash":"2a729a89ae75af14e7d718523967b0afe2f93b9a"}]

Generated by PR labeler 🤖

Copy link

github-actions bot commented Jun 14, 2024

Old size New size Diff
6.62 MB 6.62 MB 0 B (0.00%)

@haileyok haileyok marked this pull request as ready for review June 14, 2024 18:42
@haileyok haileyok mentioned this pull request Jun 17, 2024
29 tasks
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gonna wait with this until after sp

@pfrazee pfrazee self-assigned this Jun 20, 2024
@haileyok haileyok marked this pull request as draft June 28, 2024 19:04
@haileyok haileyok changed the base branch from main to hailey/shared-preferences July 2, 2024 01:20
@haileyok haileyok marked this pull request as ready for review July 2, 2024 01:33
Comment on lines 45 to 48
// referrer could become null here. `.toString()` though can be called on null
val res = mapOf(
"referrer" to activityReferrer.toString(),
"hostname" to (activityReferrer?.host ?: ""),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haileyok haileyok changed the base branch from hailey/shared-preferences to main July 12, 2024 01:38
@haileyok haileyok merged commit 8b121af into main Jul 12, 2024
6 checks passed
@mary-ext
Copy link
Contributor

mary-ext commented Jul 12, 2024

seems like this broke web?

getReferrerInfoAsync() is returning null

if (isWeb) {
Referrer.getReferrerInfoAsync().then(info => {
if (info && info.hostname !== 'bsky.app') {

haileyok added a commit that referenced this pull request Aug 1, 2024
haileyok added a commit that referenced this pull request Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants