Skip to content

Commit 1de01f5

Browse files
hassankhanhuextratkenanteyoussef eddibili
authored
chore(react-native-adjust): update react-native-adjust (#301)
* feat(react-native-adjust): remove iAd.framework as it's legacy * feat(react-native-adjust): update Google Play Services implementation * feat(react-native-adjust): add support for SDK signature * feat(adjust): add meta install referrer --------- Co-authored-by: Hugo EXTRAT <extrat.h@gmail.com> Co-authored-by: kenan.tendzo <kenan.tendzo@gmail.com> Co-authored-by: youssef eddibili <youssef.eddibili@typology.com>
1 parent 69c2af5 commit 1de01f5

File tree

2 files changed

+226
-20
lines changed

2 files changed

+226
-20
lines changed

packages/react-native-adjust/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ After installing this npm package, add the [config plugin](https://docs.expo.io/
3333
}
3434
```
3535

36+
## Configuration Options
37+
38+
### Android 12+ Support
39+
3640
If you are targeting Android 12 and above (API level 31), you need to add it in the options of the plugin:
3741

3842
```json
@@ -43,6 +47,60 @@ If you are targeting Android 12 and above (API level 31), you need to add it in
4347
}
4448
```
4549

50+
### SDK Signature
51+
4652
This will add the [appropriate permission](https://github.com/adjust/react_native_sdk#add-permission-to-gather-google-advertising-id) for you.
4753

54+
To set up Adjust [SDK Signature](https://github.com/adjust/react_native_sdk/blob/master/README.md#sdk-signature) you need to specify the path for the xcframework and the aar file.
55+
```json
56+
{
57+
"expo": {
58+
"plugins": [
59+
"@config-plugins/react-native-adjust",
60+
{
61+
"targetAndroid12": true ,
62+
"sdkSignature" : {
63+
"android" : "./path/to.aar",
64+
"ios" : "./path/to.xcframework"
65+
}
66+
}
67+
]
68+
}
69+
}
70+
```
71+
72+
### Meta Install Referrer
73+
74+
If you need to track Meta (Facebook) install referrers, you can enable the Meta install referrer dependency:
75+
76+
```json
77+
{
78+
"plugins": [
79+
["@config-plugins/react-native-adjust", { "metaInstallReferrer": true }]
80+
]
81+
}
82+
```
83+
84+
This will add the `com.adjust.sdk:adjust-android-meta-referrer:5.4.0` dependency to your Android build.
85+
86+
Doc: https://dev.adjust.com/en/sdk/react-native/plugins/meta-referrer-plugin
87+
88+
### Combined Configuration
89+
90+
You can combine multiple options:
91+
92+
```json
93+
{
94+
"plugins": [
95+
[
96+
"@config-plugins/react-native-adjust",
97+
{
98+
"targetAndroid12": true,
99+
"metaInstallReferrer": true
100+
}
101+
]
102+
]
103+
}
104+
```
105+
48106
Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.

packages/react-native-adjust/src/withReactNativeAdjust.ts

Lines changed: 168 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
IOSConfig,
77
withAppBuildGradle,
88
withXcodeProject,
9+
withDangerousMod,
910
} from "expo/config-plugins";
11+
import fs from "fs";
12+
import path from "path";
1013

1114
const withXcodeLinkBinaryWithLibraries: ConfigPlugin<{
1215
library: string;
@@ -29,49 +32,179 @@ const withXcodeLinkBinaryWithLibraries: ConfigPlugin<{
2932
});
3033
};
3134

32-
const addAndroidPackagingOptions = (src: string) => {
35+
const addAndroidPackagingOptions = (
36+
src: string,
37+
includeMetaReferrer?: boolean,
38+
) => {
39+
const baseImplementations = `
40+
implementation 'com.google.android.gms:play-services-analytics:18.0.1'
41+
implementation 'com.android.installreferrer:installreferrer:2.2'`;
42+
43+
const metaImplementation = includeMetaReferrer
44+
? `\n implementation 'com.adjust.sdk:adjust-android-meta-referrer:5.4.0'`
45+
: "";
46+
3347
return mergeContents({
3448
tag: "react-native-play-services-analytics",
3549
src,
36-
newSrc: `
37-
implementation 'com.google.android.gms:play-services-analytics:18.0.1'
38-
implementation 'com.android.installreferrer:installreferrer:2.2'
39-
`,
50+
newSrc: baseImplementations + metaImplementation,
51+
anchor: /dependencies(?:\s+)?\{/,
52+
// Inside the dependencies block.
53+
offset: 1,
54+
comment: "//",
55+
});
56+
};
57+
58+
const addSdkSignatureDependency = (src: string) => {
59+
return mergeContents({
60+
tag: "react-native-adjust arr dependency",
61+
src,
62+
newSrc: "implementation files('libs/adjust-lib.aar')",
4063
anchor: /dependencies(?:\s+)?\{/,
4164
// Inside the dependencies block.
4265
offset: 1,
4366
comment: "//",
4467
});
4568
};
4669

47-
const withGradle: ConfigPlugin = (config) => {
70+
const addNdkAbiFilters = (src: string) => {
71+
return mergeContents({
72+
tag: "react-native-adjust NDK abi filters",
73+
src,
74+
newSrc: "ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'",
75+
anchor: /defaultConfig(?:\s+)?\{/,
76+
// Inside the dependencies block.
77+
offset: 1,
78+
comment: "//",
79+
});
80+
};
81+
82+
const withGradle: ConfigPlugin<{
83+
isSdkSignatureSupported: boolean;
84+
metaInstallReferrer?: boolean;
85+
}> = (config, { isSdkSignatureSupported, metaInstallReferrer }) => {
4886
return withAppBuildGradle(config, (config) => {
49-
if (config.modResults.language === "groovy") {
50-
config.modResults.contents = addAndroidPackagingOptions(
51-
config.modResults.contents,
52-
).contents;
53-
} else {
87+
if (config.modResults.language !== "groovy") {
5488
throw new Error(
5589
"Cannot add Play Services maven gradle because the project build.gradle is not groovy",
5690
);
5791
}
92+
93+
if (isSdkSignatureSupported) {
94+
config.modResults.contents = addNdkAbiFilters(
95+
config.modResults.contents,
96+
).contents;
97+
98+
config.modResults.contents = addSdkSignatureDependency(
99+
config.modResults.contents,
100+
).contents;
101+
}
102+
103+
config.modResults.contents = addAndroidPackagingOptions(
104+
config.modResults.contents,
105+
metaInstallReferrer,
106+
).contents;
107+
58108
return config;
59109
});
60110
};
61111

112+
const withAndroidSdkSignature: ConfigPlugin<{ sdkSignaturePath: string }> = (
113+
config,
114+
props,
115+
) => {
116+
return withDangerousMod(config, [
117+
"android",
118+
async (config) => {
119+
const projectRoot = config.modRequest.projectRoot;
120+
const libPath = path.join(projectRoot, props.sdkSignaturePath);
121+
122+
if (!fs.existsSync(libPath)) {
123+
throw new Error("Cannot find Adjust Android sdk signature library !");
124+
}
125+
126+
const libsDirectoryPath = path.join(projectRoot, "android/app/libs");
127+
128+
if (!fs.existsSync(libsDirectoryPath)) {
129+
fs.mkdirSync(libsDirectoryPath);
130+
}
131+
132+
fs.cpSync(libPath, path.join(libsDirectoryPath, "adjust-lib.aar"));
133+
134+
return config;
135+
},
136+
]);
137+
};
138+
139+
const withIosSdkSignature: ConfigPlugin<{ sdkSignaturePath: string }> = (
140+
config,
141+
props,
142+
) => {
143+
return withXcodeProject(config, (config) => {
144+
const projectRoot = config.modRequest.projectRoot;
145+
const libPath = path.join(projectRoot, props.sdkSignaturePath);
146+
147+
if (!fs.existsSync(libPath)) {
148+
throw new Error("Cannot find Adjust iOS sdk signature library !");
149+
}
150+
151+
const newLibPath = path.join(
152+
projectRoot,
153+
"ios",
154+
config.modRequest.projectName!,
155+
path.basename(libPath),
156+
);
157+
const target = IOSConfig.XcodeUtils.getApplicationNativeTarget({
158+
project: config.modResults,
159+
projectName: config.modRequest.projectName!,
160+
});
161+
162+
fs.cpSync(libPath, newLibPath, { recursive: true });
163+
164+
const embedFrameworksBuildPhase =
165+
config.modResults.pbxEmbedFrameworksBuildPhaseObj(target.uuid);
166+
167+
if (!embedFrameworksBuildPhase) {
168+
config.modResults.addBuildPhase(
169+
[],
170+
"PBXCopyFilesBuildPhase",
171+
"Embed Frameworks",
172+
target.uuid,
173+
"frameworks",
174+
);
175+
}
176+
177+
config.modResults.addFramework(newLibPath, {
178+
target: target.uuid,
179+
embed: true,
180+
sign: true,
181+
customFramework: true,
182+
});
183+
184+
return config;
185+
});
186+
};
187+
188+
type Props = {
189+
metaInstallReferrer?: boolean;
190+
targetAndroid12?: boolean;
191+
sdkSignature?: {
192+
ios?: string;
193+
android?: string;
194+
};
195+
};
196+
62197
/**
63198
* Apply react-native-adjust configuration for Expo SDK +44 projects.
64199
*/
65-
const withAdjustPlugin: ConfigPlugin<void | { targetAndroid12?: boolean }> = (
66-
config,
67-
_props,
68-
) => {
200+
const withAdjustPlugin: ConfigPlugin<void | Props> = (config, _props) => {
69201
const props = _props || {};
70202

71-
config = withXcodeLinkBinaryWithLibraries(config, {
72-
library: "iAd.framework",
73-
status: "optional",
74-
});
203+
const androidSdkSignaturePath = props.sdkSignature?.android ?? "";
204+
const iosSdkSignaturePath = props.sdkSignature?.ios ?? "";
205+
const isAndroidSdkSignatureSupported = androidSdkSignaturePath !== "";
206+
const isIosSdkSignatureSupported = iosSdkSignaturePath !== "";
207+
const metaInstallReferrer = props.metaInstallReferrer ?? false;
75208

76209
config = withXcodeLinkBinaryWithLibraries(config, {
77210
library: "AdServices.framework",
@@ -93,13 +226,28 @@ const withAdjustPlugin: ConfigPlugin<void | { targetAndroid12?: boolean }> = (
93226
status: "optional",
94227
});
95228

229+
if (isIosSdkSignatureSupported) {
230+
config = withIosSdkSignature(config, {
231+
sdkSignaturePath: iosSdkSignaturePath,
232+
});
233+
}
234+
96235
if (props.targetAndroid12) {
97236
config = AndroidConfig.Permissions.withPermissions(config, [
98237
"com.google.android.gms.permission.AD_ID",
99238
]);
100239
}
101240

102-
config = withGradle(config);
241+
config = withGradle(config, {
242+
isSdkSignatureSupported: isAndroidSdkSignatureSupported,
243+
metaInstallReferrer,
244+
});
245+
246+
if (isAndroidSdkSignatureSupported) {
247+
config = withAndroidSdkSignature(config, {
248+
sdkSignaturePath: androidSdkSignaturePath,
249+
});
250+
}
103251

104252
// Return the modified config.
105253
return config;

0 commit comments

Comments
 (0)