Skip to content

Commit 62d59a8

Browse files
authored
Merge pull request #342 from vincent-paing/feat/android_referrer
[Android] Add includeReferrer to allow adding android package name as referrer for website to track
2 parents dfeadbc + 4a3be53 commit 62d59a8

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Property | Description
176176
`hasBackButton` (Boolean) | Sets a back arrow instead of the default `X` icon to close the custom tab. [`true`/`false`]
177177
`browserPackage` (String) | Package name of a browser to be used to handle Custom Tabs.
178178
`showInRecents` (Boolean) | Determining whether browsed website should be shown as separate entry in Android recents/multitasking view. [`true`/`false`]
179+
`includeReferrer` (Boolean) | Determining whether to include your package name as referrer for the website to track. [`true`/`false`]
179180
180181
### Demo
181182

android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.proyecto26.inappbrowser;
22

3-
import android.R.anim;
43
import android.net.Uri;
4+
import android.os.Build;
55
import android.os.Bundle;
66
import android.text.TextUtils;
77
import android.app.Activity;
@@ -31,7 +31,6 @@
3131
import java.util.Arrays;
3232
import java.util.regex.Pattern;
3333
import java.util.List;
34-
3534
public class RNInAppBrowser {
3635
private final static String ERROR_CODE = "InAppBrowser";
3736
private static final String KEY_TOOLBAR_COLOR = "toolbarColor";
@@ -51,6 +50,7 @@ public class RNInAppBrowser {
5150
private static final String KEY_HAS_BACK_BUTTON = "hasBackButton";
5251
private static final String KEY_BROWSER_PACKAGE = "browserPackage";
5352
private static final String KEY_SHOW_IN_RECENTS = "showInRecents";
53+
private static final String KEY_INCLUDE_REFERRER = "includeReferrer";
5454

5555
private static final String ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService";
5656
private static final String CHROME_PACKAGE_STABLE = "com.android.chrome";
@@ -181,7 +181,7 @@ public void open(Context context, final ReadableMap options, final Promise promi
181181
}
182182

183183
registerEventBus();
184-
184+
185185
intent.setData(Uri.parse(url));
186186
if (options.hasKey(KEY_SHOW_PAGE_TITLE)) {
187187
builder.setShowTitle(options.getBoolean(KEY_SHOW_PAGE_TITLE));
@@ -190,6 +190,12 @@ public void open(Context context, final ReadableMap options, final Promise promi
190190
intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);
191191
}
192192

193+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && options.hasKey(KEY_INCLUDE_REFERRER)
194+
&& options.getBoolean(KEY_INCLUDE_REFERRER)) {
195+
intent.putExtra(Intent.EXTRA_REFERRER,
196+
Uri.parse("android-app://" + context.getApplicationContext().getPackageName()));
197+
}
198+
193199
currentActivity.startActivity(
194200
ChromeTabsManagerActivity.createStartIntent(currentActivity, intent),
195201
customTabsIntent.startAnimationBundle);

example/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const openLink = async (url, statusBarStyle, animated = true) => {
4343
hasBackButton: true,
4444
browserPackage: null,
4545
showInRecents: false,
46+
includeReferrer: true,
4647
});
4748
// A delay to show an alert when the browser is closed
4849
await sleep(800);

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ declare module 'react-native-inappbrowser-reborn' {
5858
hasBackButton?: boolean,
5959
browserPackage?: string,
6060
showInRecents?: boolean
61+
includeReferrer?: boolean,
6162
}
6263

6364
export type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions;

types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export type InAppBrowserAndroidOptions = {|
6262
hasBackButton?: boolean,
6363
browserPackage?: string,
6464
showInRecents?: boolean,
65+
includeReferrer?: boolean,
6566
|};
6667

6768
export type InAppBrowserOptions = {

0 commit comments

Comments
 (0)