@rediads/react-native-ads-gam 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +201 -0
- package/README.md +182 -2
- package/android/build.gradle +24 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMBannerSlot.kt +99 -0
- package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMModule.kt +306 -0
- package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMRenderedModule.kt +233 -0
- package/app.plugin.js +2 -0
- package/build/RediadsGAM.d.ts +46 -0
- package/build/RediadsGAM.js +66 -0
- package/build/RediadsGAMBanner.d.ts +26 -0
- package/build/RediadsGAMBanner.js +40 -0
- package/build/RediadsGAMBannerBiddingOnly.d.ts +23 -0
- package/build/RediadsGAMBannerBiddingOnly.js +39 -0
- package/build/RediadsGAMBiddingOnlyFullScreenAd.d.ts +59 -0
- package/build/RediadsGAMBiddingOnlyFullScreenAd.js +120 -0
- package/build/RediadsGAMFullScreenAd.d.ts +70 -0
- package/build/RediadsGAMFullScreenAd.js +132 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +7 -0
- package/build/native.d.ts +45 -0
- package/build/native.js +18 -0
- package/build/renderedNative.d.ts +34 -0
- package/build/renderedNative.js +15 -0
- package/build/types.d.ts +77 -0
- package/build/types.js +1 -0
- package/expo-module.config.json +18 -0
- package/ios/RediadsAdsGAM.podspec +32 -0
- package/ios/RediadsGAMModule.swift +341 -0
- package/ios/RediadsGAMRenderedModule.swift +195 -0
- package/package.json +56 -4
- package/plugin/withRediadsGAM.js +141 -0
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rediads/react-native-ads-gam",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "Rediads bids in Google Ad Manager for React Native apps: SDK-rendered (GAM decides, the Rediads SDK draws a Rediads win) or bidding only (the hb_ keys for your GAM requests, GAM draws).",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*.js",
|
|
9
|
+
"build/**/*.d.ts",
|
|
10
|
+
"ios/*.podspec",
|
|
11
|
+
"ios/*.swift",
|
|
12
|
+
"android/build.gradle",
|
|
13
|
+
"android/src/main/",
|
|
14
|
+
"plugin/",
|
|
15
|
+
"app.plugin.js",
|
|
16
|
+
"expo-module.config.json",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"CHANGELOG.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p .",
|
|
23
|
+
"clean": "rm -rf build",
|
|
24
|
+
"lint": "eslint src/ plugin/ app.plugin.js",
|
|
25
|
+
"prepack": "tsc -p ."
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"react-native",
|
|
29
|
+
"expo",
|
|
30
|
+
"ads",
|
|
31
|
+
"advertising",
|
|
32
|
+
"rediads",
|
|
33
|
+
"google-ad-manager",
|
|
34
|
+
"gam",
|
|
35
|
+
"header-bidding",
|
|
36
|
+
"prebid"
|
|
37
|
+
],
|
|
38
|
+
"author": "Rediads (https://rediads.com)",
|
|
39
|
+
"license": "Apache-2.0",
|
|
40
|
+
"homepage": "https://rediads.com",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@rediads/react-native-ads": "0.1.0-beta.1",
|
|
43
|
+
"@types/react": "~19.3.0",
|
|
44
|
+
"eslint": "~9.39.4",
|
|
45
|
+
"eslint-config-universe": "^16.1.2",
|
|
46
|
+
"expo": "^58.0.21",
|
|
47
|
+
"prettier": "^3.0.0",
|
|
48
|
+
"react": "19.3.0",
|
|
49
|
+
"react-native": "0.88.1",
|
|
50
|
+
"typescript": "~6.0.3"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@rediads/react-native-ads": "0.1.0-beta.1",
|
|
54
|
+
"expo": ">=58.0.0",
|
|
55
|
+
"react": "*",
|
|
56
|
+
"react-native": "*"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expo config plugin of @rediads/react-native-ads-gam. It runs during `npx expo prebuild` (and
|
|
3
|
+
* `expo run:ios|android`, EAS Build) and sets up Google's Mobile Ads SDK and the Rediads GAM pods:
|
|
4
|
+
*
|
|
5
|
+
* plugins: [
|
|
6
|
+
* '@rediads/react-native-ads',
|
|
7
|
+
* ['@rediads/react-native-ads-gam', {
|
|
8
|
+
* // Optional: the app's IDs from Ad Manager (Inventory → Apps) or AdMob, "ca-app-pub-XXXX~YYYY".
|
|
9
|
+
* // Without them, the app is marked as an Ad Manager app (GADIsAdManagerApp /
|
|
10
|
+
* // com.google.android.gms.ads.AD_MANAGER_APP), which Google's SDK accepts instead.
|
|
11
|
+
* iosAppId: 'ca-app-pub-XXXX~YYYY',
|
|
12
|
+
* androidAppId: 'ca-app-pub-XXXX~ZZZZ',
|
|
13
|
+
* // SDK development only: the same local iOS SDK checkout as for @rediads/react-native-ads.
|
|
14
|
+
* // iosSdkPath: '../rediads-ios-sdk',
|
|
15
|
+
* }],
|
|
16
|
+
* ]
|
|
17
|
+
*
|
|
18
|
+
* - iOS: the app ID (or the Ad Manager flag) and Google's SKAdNetwork ID in Info.plist. The pods are
|
|
19
|
+
* binaries from Rediads' pod list, which this plugin adds as a Podfile source (as
|
|
20
|
+
* @rediads/react-native-ads does); with iosSdkPath, the RediadsGAM and RediadsGAMEventHandlers pods
|
|
21
|
+
* come from that checkout.
|
|
22
|
+
* - Android: the app ID (or the Ad Manager flag) meta-data in AndroidManifest.xml. The SDK comes
|
|
23
|
+
* from Maven Central (or @rediads/react-native-ads's androidMavenRepo option).
|
|
24
|
+
*
|
|
25
|
+
* Other plugins that set the app ID (react-native-google-mobile-ads, @rediads/react-native-ads-admob)
|
|
26
|
+
* must use the same value; give it here too, so this plugin doesn't mark the app as Ad Manager only.
|
|
27
|
+
*/
|
|
28
|
+
const { addSources } = require('@rediads/react-native-ads/app.plugin');
|
|
29
|
+
const {
|
|
30
|
+
AndroidConfig,
|
|
31
|
+
createRunOncePlugin,
|
|
32
|
+
withAndroidManifest,
|
|
33
|
+
withInfoPlist,
|
|
34
|
+
withPodfile,
|
|
35
|
+
} = require('expo/config-plugins');
|
|
36
|
+
const fs = require('fs');
|
|
37
|
+
const path = require('path');
|
|
38
|
+
|
|
39
|
+
const pkg = require('../package.json');
|
|
40
|
+
|
|
41
|
+
const TAG = '@rediads/react-native-ads-gam';
|
|
42
|
+
const PODS = ['RediadsGAM', 'RediadsGAMEventHandlers'];
|
|
43
|
+
const APP_ID = /^ca-app-pub-\d+~\d+$/;
|
|
44
|
+
const GOOGLE_SKADNETWORK = 'cstr6suwn9.skadnetwork';
|
|
45
|
+
const ANDROID_APP_ID = 'com.google.android.gms.ads.APPLICATION_ID';
|
|
46
|
+
const ANDROID_AD_MANAGER_APP = 'com.google.android.gms.ads.AD_MANAGER_APP';
|
|
47
|
+
|
|
48
|
+
function escapeRegExp(text) {
|
|
49
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Removes the block an earlier prebuild added, so a changed path replaces it. */
|
|
53
|
+
function removeBlock(contents) {
|
|
54
|
+
const begin = escapeRegExp(`# @generated begin ${TAG}`);
|
|
55
|
+
const end = escapeRegExp(`# @generated end ${TAG}`);
|
|
56
|
+
return contents.replace(new RegExp(`[ \\t]*${begin} [\\s\\S]*?${end}\\n`), '');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function addPods(podfile, sdkPath) {
|
|
60
|
+
const contents = removeBlock(podfile);
|
|
61
|
+
// The app's own target; extension targets come after it.
|
|
62
|
+
const anchor = /^target '[^']+' do\n([ \t]*)use_expo_modules![^\n]*\n/m;
|
|
63
|
+
const match = contents.match(anchor);
|
|
64
|
+
if (!match) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`${TAG}: could not find the app target's \`use_expo_modules!\` in ios/Podfile, so the Rediads GAM pods could not be added.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const indent = match[1];
|
|
70
|
+
const text = [
|
|
71
|
+
`${indent}# @generated begin ${TAG} - Rediads GAM pods from a local checkout`,
|
|
72
|
+
...PODS.map((name) => `${indent}pod '${name}', :path => ${JSON.stringify(sdkPath)}`),
|
|
73
|
+
`${indent}# @generated end ${TAG}`,
|
|
74
|
+
'',
|
|
75
|
+
].join('\n');
|
|
76
|
+
return contents.replace(anchor, (found) => `${found}${text}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function checkAppId(name, value) {
|
|
80
|
+
if (value && !APP_ID.test(value)) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`${TAG}: ${name} "${value}" is not an app ID. It looks like "ca-app-pub-XXXX~YYYY" (with "~"; ad unit IDs have "/").`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {import('expo/config').ExpoConfig} config
|
|
89
|
+
* @param {{ iosAppId?: string, androidAppId?: string, iosSdkPath?: string } | undefined} options
|
|
90
|
+
*/
|
|
91
|
+
function withRediadsGAM(config, options = {}) {
|
|
92
|
+
const { iosAppId, androidAppId, iosSdkPath } = options ?? {};
|
|
93
|
+
checkAppId('iosAppId', iosAppId);
|
|
94
|
+
checkAppId('androidAppId', androidAppId);
|
|
95
|
+
|
|
96
|
+
config = withInfoPlist(config, (config) => {
|
|
97
|
+
const plist = config.modResults;
|
|
98
|
+
if (iosAppId) {
|
|
99
|
+
plist.GADApplicationIdentifier = iosAppId;
|
|
100
|
+
} else if (!plist.GADApplicationIdentifier) {
|
|
101
|
+
plist.GADIsAdManagerApp = true;
|
|
102
|
+
}
|
|
103
|
+
const items = Array.isArray(plist.SKAdNetworkItems) ? plist.SKAdNetworkItems : [];
|
|
104
|
+
if (!items.some((item) => item?.SKAdNetworkIdentifier === GOOGLE_SKADNETWORK)) {
|
|
105
|
+
items.push({ SKAdNetworkIdentifier: GOOGLE_SKADNETWORK });
|
|
106
|
+
}
|
|
107
|
+
plist.SKAdNetworkItems = items;
|
|
108
|
+
return config;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
config = withPodfile(config, (config) => {
|
|
112
|
+
if (iosSdkPath) {
|
|
113
|
+
const folder = path.resolve(config.modRequest.projectRoot, iosSdkPath);
|
|
114
|
+
if (!fs.existsSync(path.join(folder, 'RediadsGAM.podspec'))) {
|
|
115
|
+
throw new Error(`${TAG}: iosSdkPath ${folder} has no RediadsGAM.podspec.`);
|
|
116
|
+
}
|
|
117
|
+
config.modResults.contents = addPods(config.modResults.contents, folder);
|
|
118
|
+
} else {
|
|
119
|
+
// Published pods: Rediads' pod list as a source (the same block @rediads/react-native-ads
|
|
120
|
+
// adds, so listing that plugin too doesn't add it twice); drop local pods of an earlier prebuild.
|
|
121
|
+
config.modResults.contents = addSources(removeBlock(config.modResults.contents));
|
|
122
|
+
}
|
|
123
|
+
return config;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
config = withAndroidManifest(config, (config) => {
|
|
127
|
+
const { Manifest } = AndroidConfig;
|
|
128
|
+
const application = Manifest.getMainApplicationOrThrow(config.modResults);
|
|
129
|
+
if (androidAppId) {
|
|
130
|
+
Manifest.addMetaDataItemToMainApplication(application, ANDROID_APP_ID, androidAppId);
|
|
131
|
+
} else if (!Manifest.getMainApplicationMetaDataValue(config.modResults, ANDROID_APP_ID)) {
|
|
132
|
+
Manifest.addMetaDataItemToMainApplication(application, ANDROID_AD_MANAGER_APP, 'true');
|
|
133
|
+
}
|
|
134
|
+
return config;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return config;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = createRunOncePlugin(withRediadsGAM, pkg.name, pkg.version);
|
|
141
|
+
module.exports.addPods = addPods;
|