Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/react-native-adjust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ After installing this npm package, add the [config plugin](https://docs.expo.io/
}
```

## Configuration Options

### Android 12+ Support

If you are targeting Android 12 and above (API level 31), you need to add it in the options of the plugin:

```json
Expand All @@ -44,4 +48,38 @@ If you are targeting Android 12 and above (API level 31), you need to add it in

This will add the [appropriate permission](https://github.com/adjust/react_native_sdk#add-permission-to-gather-google-advertising-id) for you.

### Meta Install Referrer

If you need to track Meta (Facebook) install referrers, you can enable the Meta install referrer dependency:

```json
{
"plugins": [
["@config-plugins/react-native-adjust", { "metaInstallReferrer": true }]
]
}
```

This will add the `com.adjust.sdk:adjust-android-meta-referrer:5.4.0` dependency to your Android build.

Doc: https://dev.adjust.com/en/sdk/react-native/plugins/meta-referrer-plugin

### Combined Configuration

You can combine multiple options:

```json
{
"plugins": [
[
"@config-plugins/react-native-adjust",
{
"targetAndroid12": true,
"metaInstallReferrer": true
}
]
]
}
```

Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.
25 changes: 17 additions & 8 deletions packages/react-native-adjust/src/withReactNativeAdjust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,32 @@ const withXcodeLinkBinaryWithLibraries: ConfigPlugin<{
});
};

const addAndroidPackagingOptions = (src: string) => {
const addAndroidPackagingOptions = (src: string, includeMetaReferrer?: boolean) => {
const baseImplementations = `
implementation 'com.google.android.gms:play-services-analytics:18.0.1'
implementation 'com.android.installreferrer:installreferrer:2.2'`;

const metaImplementation = includeMetaReferrer
? `\n implementation 'com.adjust.sdk:adjust-android-meta-referrer:5.4.0'`
: '';

return mergeContents({
tag: "react-native-play-services-analytics",
src,
newSrc: `
implementation 'com.google.android.gms:play-services-analytics:18.0.1'
implementation 'com.android.installreferrer:installreferrer:2.2'
`,
newSrc: baseImplementations + metaImplementation,
anchor: /dependencies(?:\s+)?\{/,
// Inside the dependencies block.
offset: 1,
comment: "//",
});
};

const withGradle: ConfigPlugin = (config) => {
const withGradle: ConfigPlugin<{ metaInstallReferrer?: boolean }> = (config, { metaInstallReferrer }) => {
return withAppBuildGradle(config, (config) => {
if (config.modResults.language === "groovy") {
config.modResults.contents = addAndroidPackagingOptions(
config.modResults.contents,
metaInstallReferrer,
).contents;
} else {
throw new Error(
Expand All @@ -62,7 +68,10 @@ const withGradle: ConfigPlugin = (config) => {
/**
* Apply react-native-adjust configuration for Expo SDK +44 projects.
*/
const withAdjustPlugin: ConfigPlugin<void | { targetAndroid12?: boolean }> = (
const withAdjustPlugin: ConfigPlugin<void | {
targetAndroid12?: boolean;
metaInstallReferrer?: boolean;
}> = (
config,
_props,
) => {
Expand Down Expand Up @@ -99,7 +108,7 @@ const withAdjustPlugin: ConfigPlugin<void | { targetAndroid12?: boolean }> = (
]);
}

config = withGradle(config);
config = withGradle(config, { metaInstallReferrer: props.metaInstallReferrer });

// Return the modified config.
return config;
Expand Down