about summary refs log tree commit diff
path: root/plugins
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-07-11 18:43:10 -0700
committerGitHub <noreply@github.com>2024-07-11 18:43:10 -0700
commit8b121af2e438ca77cc5f5b1715516107c18aff6f (patch)
treec7f1a28b63226c79e07aef4d2e88898358a62ec6 /plugins
parent83e8522e0a89be28b1733f4c50dbd4379d98d03b (diff)
downloadvoidsky-8b121af2e438ca77cc5f5b1715516107c18aff6f.tar.zst
referrers for all platforms (#4514)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/withAppDelegateReferrer.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/plugins/withAppDelegateReferrer.js b/plugins/withAppDelegateReferrer.js
new file mode 100644
index 000000000..de773df07
--- /dev/null
+++ b/plugins/withAppDelegateReferrer.js
@@ -0,0 +1,41 @@
+const {withAppDelegate} = require('@expo/config-plugins')
+const {mergeContents} = require('@expo/config-plugins/build/utils/generateCode')
+const path = require('path')
+const fs = require('fs')
+
+module.exports = config => {
+  // eslint-disable-next-line no-shadow
+  return withAppDelegate(config, async config => {
+    const delegatePath = path.join(
+      config.modRequest.platformProjectRoot,
+      'AppDelegate.mm',
+    )
+
+    let newContents = config.modResults.contents
+    newContents = mergeContents({
+      src: newContents,
+      anchor: '// Linking API',
+      newSrc: `
+  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+  [defaults setObject:options[UIApplicationOpenURLOptionsSourceApplicationKey] forKey:@"referrerApp"];\n`,
+      offset: 2,
+      tag: 'referrer info - deep links',
+      comment: '//',
+    }).contents
+
+    newContents = mergeContents({
+      src: newContents,
+      anchor: '// Universal Links',
+      newSrc: `
+  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+  [defaults setURL:userActivity.referrerURL forKey:@"referrer"];\n`,
+      offset: 2,
+      tag: 'referrer info - universal links',
+      comment: '//',
+    }).contents
+
+    config.modResults.contents = newContents
+
+    return config
+  })
+}