emi-indo-cordova-plugin-admob 1.6.9 → 1.7.9
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/README.md +17 -9
- package/capacitor-hook-admob-ids.js +19 -17
- package/example/www/js/optionalFirebaseAnalytics.js +174 -0
- package/package.json +1 -1
- package/plugin.xml +2 -2
package/README.md
CHANGED
@@ -7,22 +7,35 @@
|
|
7
7
|
- AdManager
|
8
8
|
- AdSense New [example ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/www/js/adSense.js)
|
9
9
|
|
10
|
+
> [!NOTE]
|
11
|
+
> - To maintain this plugin in the long run,
|
12
|
+
> - for (regular maintenance),
|
13
|
+
> - just give me a cup of coffee.
|
14
|
+
|
15
|
+
## 💰Sponsor this project
|
16
|
+
[](https://paypal.me/emiindo)
|
17
|
+
[](https://ko-fi.com/F1F16NI8H)
|
18
|
+
## [Check all release notes:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/releases/)
|
19
|
+
|
10
20
|
|
11
21
|
### Mobile Ads SDK (Android: 23.6.0) [Release Notes:](https://developers.google.com/admob/android/rel-notes)
|
12
22
|
### User Messaging Platform (UMP Android: 3.1.0) [Release Notes:](https://developers.google.com/admob/android/privacy/release-notes)
|
13
23
|
|
14
|
-
### Mobile Ads SDK (IOS: 11.
|
24
|
+
### Mobile Ads SDK (IOS: 11.13.0) [Release Notes:](https://developers.google.com/admob/ios/rel-notes)
|
15
25
|
|
16
26
|
### User Messaging Platform (UMP IOS: 2.7.0) [Release Notes:](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/privacy/download)
|
17
|
-
### IAB Europe Transparency & Consent Framework (
|
27
|
+
### IAB Europe Transparency & Consent Framework (CMP: 2.2.0)
|
18
28
|
|
19
|
-
## New example
|
20
|
-
- https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/tree/main/example/www
|
21
29
|
|
22
30
|
|
23
31
|
## Documentation Capacitor example
|
24
32
|
- [Documentation Capacitor example: ](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/discussions/29)
|
25
33
|
|
34
|
+
### This is not a dependency, it's a separate plugin but highly recommended.
|
35
|
+
https://github.com/EMI-INDO/emi-indo-cordova-plugin-fanalytics
|
36
|
+
|
37
|
+
## New example
|
38
|
+
- https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/tree/main/example/www
|
26
39
|
|
27
40
|
|
28
41
|
## Minimum Cordova Engines
|
@@ -100,11 +113,6 @@ https://developers.google.com/admob/ios/quick-start
|
|
100
113
|
|
101
114
|
|
102
115
|
|
103
|
-
## 💰Sponsor this project
|
104
|
-
[](https://paypal.me/emiindo)
|
105
|
-
[](https://ko-fi.com/F1F16NI8H)
|
106
|
-
## [Check all release notes:](https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/releases/)
|
107
|
-
|
108
116
|
|
109
117
|
|
110
118
|
## Features
|
@@ -6,14 +6,12 @@ const configPath = path.join(process.cwd(), 'capacitor.config.json');
|
|
6
6
|
const androidPlatformPath = path.join(process.cwd(), 'android');
|
7
7
|
const iosPlatformPath = path.join(process.cwd(), 'ios');
|
8
8
|
const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
|
9
|
-
const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
|
10
|
-
|
9
|
+
const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
|
11
10
|
|
12
11
|
function fileExists(filePath) {
|
13
12
|
return fs.existsSync(filePath);
|
14
13
|
}
|
15
14
|
|
16
|
-
|
17
15
|
function getAdMobConfig() {
|
18
16
|
if (!fileExists(configPath)) {
|
19
17
|
throw new Error('capacitor.config.json not found. Ensure this is a Capacitor project.');
|
@@ -29,10 +27,10 @@ function getAdMobConfig() {
|
|
29
27
|
return {
|
30
28
|
APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
|
31
29
|
APP_ID_IOS: admobConfig.APP_ID_IOS,
|
30
|
+
USE_LITE_ADS: admobConfig.USE_LITE_ADS === "lite",
|
32
31
|
};
|
33
32
|
}
|
34
33
|
|
35
|
-
|
36
34
|
function updatePluginXml(admobConfig) {
|
37
35
|
if (!fileExists(pluginPath)) {
|
38
36
|
console.error('plugin.xml not found. Ensure the plugin is installed.');
|
@@ -45,11 +43,22 @@ function updatePluginXml(admobConfig) {
|
|
45
43
|
.replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
|
46
44
|
.replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
|
47
45
|
|
46
|
+
if (admobConfig.USE_LITE_ADS) {
|
47
|
+
pluginContent = pluginContent.replace(
|
48
|
+
/<framework src="com.google.android.gms:play-services-ads:.*?" \/>/,
|
49
|
+
`<framework src="com.google.android.gms:play-services-ads-lite:$PLAY_SERVICES_VERSION" />`
|
50
|
+
);
|
51
|
+
} else {
|
52
|
+
pluginContent = pluginContent.replace(
|
53
|
+
/<framework src="com.google.android.gms:play-services-ads-lite:.*?" \/>/,
|
54
|
+
`<framework src="com.google.android.gms:play-services-ads:$PLAY_SERVICES_VERSION" />`
|
55
|
+
);
|
56
|
+
}
|
57
|
+
|
48
58
|
fs.writeFileSync(pluginPath, pluginContent, 'utf8');
|
49
|
-
console.log('AdMob IDs successfully updated in plugin.xml');
|
59
|
+
console.log('AdMob IDs and framework dependency successfully updated in plugin.xml');
|
50
60
|
}
|
51
61
|
|
52
|
-
|
53
62
|
function updateInfoPlist(admobConfig) {
|
54
63
|
if (!fileExists(infoPlistPath)) {
|
55
64
|
console.error('Info.plist not found. Ensure you have built the iOS project.');
|
@@ -59,13 +68,8 @@ function updateInfoPlist(admobConfig) {
|
|
59
68
|
const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
|
60
69
|
const plistData = plist.parse(plistContent);
|
61
70
|
|
62
|
-
|
63
71
|
plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
|
64
|
-
|
65
|
-
|
66
72
|
plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
|
67
|
-
|
68
|
-
|
69
73
|
plistData.GADDelayAppMeasurementInit = true;
|
70
74
|
|
71
75
|
// https://developers.google.com/admob/ios/quick-start
|
@@ -114,15 +118,12 @@ function updateInfoPlist(admobConfig) {
|
|
114
118
|
{ SKAdNetworkIdentifier: '3qcr597p9d.skadnetwork' }, // Zucks
|
115
119
|
];
|
116
120
|
|
117
|
-
|
118
121
|
const updatedPlistContent = plist.build(plistData);
|
119
122
|
fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
|
120
123
|
console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
|
121
124
|
}
|
122
125
|
|
123
|
-
|
124
126
|
try {
|
125
|
-
|
126
127
|
if (!fileExists(configPath)) {
|
127
128
|
throw new Error('capacitor.config.json not found. Skipping setup.');
|
128
129
|
}
|
@@ -131,18 +132,19 @@ try {
|
|
131
132
|
throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
|
132
133
|
}
|
133
134
|
|
134
|
-
|
135
135
|
const admobConfig = getAdMobConfig();
|
136
136
|
|
137
|
-
|
138
137
|
if (fileExists(androidPlatformPath)) {
|
139
138
|
updatePluginXml(admobConfig);
|
140
139
|
}
|
141
140
|
|
142
|
-
|
143
141
|
if (fileExists(iosPlatformPath)) {
|
144
142
|
updateInfoPlist(admobConfig);
|
145
143
|
}
|
146
144
|
} catch (error) {
|
147
145
|
console.error(error.message);
|
148
146
|
}
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
@@ -0,0 +1,174 @@
|
|
1
|
+
|
2
|
+
// NOTE
|
3
|
+
// This is not a dependency, it's a separate plugin but highly recommended.
|
4
|
+
// https://github.com/EMI-INDO/emi-indo-cordova-plugin-fanalytics
|
5
|
+
|
6
|
+
// Just one example, for example Interstitial ads, the others just adjust it
|
7
|
+
|
8
|
+
// https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/blob/main/example/www/js/interstitialAd.js
|
9
|
+
|
10
|
+
let isInterstitialLoadAd = false;
|
11
|
+
|
12
|
+
function loadInterstitialAd() {
|
13
|
+
|
14
|
+
if (typeof cordova !== 'undefined') {
|
15
|
+
|
16
|
+
cordova.plugins.emiAdmobPlugin.loadInterstitialAd({ adUnitId: Interstitial_ID, autoShow: false });
|
17
|
+
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
function showInterstitialAd() {
|
24
|
+
|
25
|
+
if (typeof cordova !== 'undefined') {
|
26
|
+
|
27
|
+
if (isInterstitialLoadAd) {
|
28
|
+
cordova.plugins.emiAdmobPlugin.showInterstitialAd();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
/*
|
35
|
+
|
36
|
+
on.interstitial.loaded
|
37
|
+
on.interstitial.failed.load
|
38
|
+
on.interstitial.click
|
39
|
+
on.interstitial.dismissed
|
40
|
+
on.interstitial.failed.show
|
41
|
+
on.interstitial.impression
|
42
|
+
on.interstitial.show
|
43
|
+
|
44
|
+
// New event plugin v1.5.5 or higher
|
45
|
+
|
46
|
+
on.interstitial.revenue
|
47
|
+
on.interstitialAd.responseInfo
|
48
|
+
|
49
|
+
*/
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
let interstitialErrMsg = "";
|
55
|
+
|
56
|
+
const adEventData = {
|
57
|
+
// NOTE: no spaces, underline is recommended _
|
58
|
+
on_interstitial_loaded: "on_interstitial_loaded",
|
59
|
+
on_interstitial_failed_load: interstitialErrMsg,
|
60
|
+
on_interstitial_click: "on_interstitial_click",
|
61
|
+
on_interstitial_dismissed: "on_interstitial_dismissed",
|
62
|
+
on_interstitial_failed_show: "on_interstitial_failed_show",
|
63
|
+
on_interstitial_impression: "on_interstitial_impression",
|
64
|
+
on_interstitial_show: "on_interstitial_show",
|
65
|
+
on_interstitial_revenue: "on_interstitial_revenue"
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
// EVENT For example
|
71
|
+
|
72
|
+
document.addEventListener('on.interstitial.loaded', () => {
|
73
|
+
isInterstitialLoadAd = true;
|
74
|
+
console.log("on interstitial Ad loaded");
|
75
|
+
|
76
|
+
if (typeof cordova !== 'undefined') {
|
77
|
+
|
78
|
+
cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_loaded });
|
79
|
+
|
80
|
+
}
|
81
|
+
|
82
|
+
});
|
83
|
+
|
84
|
+
|
85
|
+
// all events that contain the keyword dismissed there is a block to load the ad after it is closed by the user.
|
86
|
+
document.addEventListener('on.interstitial.dismissed', () => {
|
87
|
+
isInterstitialLoadAd = false;
|
88
|
+
console.log("on interstitial Ad dismissed");
|
89
|
+
console.log("you can load ads automatically after the ads are closed by users");
|
90
|
+
|
91
|
+
loadInterstitialAd();
|
92
|
+
|
93
|
+
if (typeof cordova !== 'undefined') {
|
94
|
+
|
95
|
+
cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_dismissed });
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
});
|
100
|
+
|
101
|
+
|
102
|
+
document.addEventListener('on.interstitial.failed.load', (error) => {
|
103
|
+
isInterstitialLoadAd = false;
|
104
|
+
console.log("on.interstitial.failed.load" + JSON.stringify(error));
|
105
|
+
|
106
|
+
/*
|
107
|
+
error.code
|
108
|
+
error.message
|
109
|
+
error.domain
|
110
|
+
error.responseInfoId
|
111
|
+
error.responseInfoExtras
|
112
|
+
error.responseInfoAdapter
|
113
|
+
error.responseInfoMediationAdapterClassName
|
114
|
+
error.responseInfoAdapterResponses
|
115
|
+
*/
|
116
|
+
|
117
|
+
interstitialErrMsg = error.message;
|
118
|
+
|
119
|
+
if (typeof cordova !== 'undefined') {
|
120
|
+
|
121
|
+
cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_failed_load });
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
});
|
127
|
+
|
128
|
+
|
129
|
+
document.addEventListener('on.interstitial.failed.show', (error) => {
|
130
|
+
isInterstitialLoadAd = false;
|
131
|
+
console.log("on.interstitial.failed.show" + JSON.stringify(error));
|
132
|
+
|
133
|
+
|
134
|
+
if (typeof cordova !== 'undefined') {
|
135
|
+
|
136
|
+
cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_failed_show });
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
});
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
/*
|
148
|
+
https://support.google.com/admob/answer/11322405
|
149
|
+
|
150
|
+
Turn on the setting for impression-level ad revenue in your AdMob account:
|
151
|
+
Sign in to your AdMob account at https://apps.admob.com.
|
152
|
+
Click Settings in the sidebar.
|
153
|
+
Click the Account tab.
|
154
|
+
In the Account controls section, click the Impression-level ad revenue toggle to turn on this setting.
|
155
|
+
*/
|
156
|
+
|
157
|
+
document.addEventListener('on.interstitial.revenue', (data) => {
|
158
|
+
|
159
|
+
let adRevenuePaid = {
|
160
|
+
value: data.value,
|
161
|
+
currencyCode: data.currencyCode,
|
162
|
+
precision: data.precision,
|
163
|
+
adUnitId: data.adUnitId
|
164
|
+
}
|
165
|
+
|
166
|
+
if (typeof cordova !== 'undefined') {
|
167
|
+
|
168
|
+
cordova.plugins.EmiFirebaseAnalyticsPlugin.setAdMobRevenuePaid({ data: adRevenuePaid });
|
169
|
+
|
170
|
+
cordova.plugins.EmiFirebaseAnalyticsPlugin.logEvent({ name: "interstitial_Ad", params: adEventData.on_interstitial_revenue });
|
171
|
+
|
172
|
+
}
|
173
|
+
|
174
|
+
});
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
2
2
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
-
id="emi-indo-cordova-plugin-admob" version="1.
|
3
|
+
id="emi-indo-cordova-plugin-admob" version="1.7.9">
|
4
4
|
|
5
5
|
<name>emiAdmobPlugin</name>
|
6
6
|
<description>Cordova Plugin Admob Android IOS</description>
|
@@ -300,7 +300,7 @@
|
|
300
300
|
<pods use-frameworks="true">
|
301
301
|
<!--minimum macOS 14.4 > Xcode 15.3 -->
|
302
302
|
<pod name="GoogleUserMessagingPlatform" spec="~> 2.7.0" />
|
303
|
-
<pod name="Google-Mobile-Ads-SDK" spec="~> 11.
|
303
|
+
<pod name="Google-Mobile-Ads-SDK" spec="~> 11.13.0" />
|
304
304
|
|
305
305
|
</pods>
|
306
306
|
</podspec>
|