@cardsjd/portal 0.1.14 → 0.1.16
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/lib/BasePortal.js +4 -2
- package/lib/NextGenAdMobPortal.js +49 -14
- package/package.json +1 -1
package/lib/BasePortal.js
CHANGED
|
@@ -97,8 +97,10 @@ export class BasePortal {
|
|
|
97
97
|
console.log('readyToShowInterstitialAd: ' + readyToShowAd + ' : ' + secondsSinceLastAd + ' of ' + delayBetweenAds);
|
|
98
98
|
|
|
99
99
|
// show ad or just load ad (not load and show)
|
|
100
|
-
if (readyToShowAd) {
|
|
101
|
-
if
|
|
100
|
+
if (readyToShowAd) {
|
|
101
|
+
// showInterstitialAd returns true if the ad was shown or the show attempt failed;
|
|
102
|
+
// false means it only loaded or skipped the ad without attempting to show it.
|
|
103
|
+
if (await this.showInterstitialAd()) {
|
|
102
104
|
this.lastShownInterstitial = Date.now();
|
|
103
105
|
}
|
|
104
106
|
} else {
|
|
@@ -33,6 +33,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
33
33
|
this._consentInfoUpdated = false;
|
|
34
34
|
this._consentGathered = false;
|
|
35
35
|
this._canRequestAds = false;
|
|
36
|
+
this._limitedAdsFallback = false;
|
|
36
37
|
this._privacyOptionsRequired = false;
|
|
37
38
|
this.isTesting = false;
|
|
38
39
|
}
|
|
@@ -85,21 +86,55 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
85
86
|
async showPrivacyOptions() {
|
|
86
87
|
await this.loadUmp();
|
|
87
88
|
const consentInfo = await this._umpModule.showPrivacyOptions();
|
|
89
|
+
if (consentInfo.canRequestAds === true) {
|
|
90
|
+
this._limitedAdsFallback = false;
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
this.setConsentInfo(consentInfo);
|
|
89
94
|
return consentInfo;
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
async requestConsent(method) {
|
|
98
|
+
try {
|
|
99
|
+
await this.loadUmp();
|
|
100
|
+
return await this._umpModule[method]();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
// UMP may still allow ads using consent from a previous session.
|
|
103
|
+
let consentInfo;
|
|
104
|
+
try {
|
|
105
|
+
consentInfo = await this._umpModule.getConsentInfo();
|
|
106
|
+
} catch (statusError) {
|
|
107
|
+
console.warn('Unable to read UMP consent status:', statusError);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (consentInfo?.canRequestAds === true) {
|
|
111
|
+
console.warn('UMP consent request failed; using existing consent:', error);
|
|
112
|
+
return consentInfo;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Set Google's native limited-ad signal before allowing any ad requests.
|
|
116
|
+
await this.loadUmp();
|
|
117
|
+
await this._umpModule.enableLimitedAds();
|
|
118
|
+
this._limitedAdsFallback = true;
|
|
119
|
+
this._consentGathered = true;
|
|
120
|
+
console.warn('UMP consent request failed; requesting limited ads:', error);
|
|
121
|
+
return {
|
|
122
|
+
canRequestAds: true,
|
|
123
|
+
formShown: false,
|
|
124
|
+
privacyOptionsRequired: consentInfo?.privacyOptionsRequired ?? this._privacyOptionsRequired,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
92
129
|
async updateConsentInfo() {
|
|
93
|
-
await this.
|
|
94
|
-
const consentInfo = await this._umpModule.updateConsentInfo();
|
|
130
|
+
const consentInfo = await this.requestConsent('updateConsentInfo');
|
|
95
131
|
this._consentInfoUpdated = true;
|
|
96
132
|
this.setConsentInfo(consentInfo);
|
|
97
133
|
return consentInfo;
|
|
98
134
|
}
|
|
99
135
|
|
|
100
136
|
async gatherConsent() {
|
|
101
|
-
await this.
|
|
102
|
-
const consentInfo = await this._umpModule.gatherConsent();
|
|
137
|
+
const consentInfo = await this.requestConsent('gatherConsent');
|
|
103
138
|
this._consentInfoUpdated = true;
|
|
104
139
|
this._consentGathered = true;
|
|
105
140
|
this.setConsentInfo(consentInfo);
|
|
@@ -169,7 +204,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
169
204
|
};
|
|
170
205
|
}
|
|
171
206
|
|
|
172
|
-
const trackingPromptShown = await this.requestTrackingAuthorization(consentInfo);
|
|
207
|
+
const trackingPromptShown = !this._limitedAdsFallback && await this.requestTrackingAuthorization(consentInfo);
|
|
173
208
|
const promptShown = consentInfo?.formShown === true || trackingPromptShown;
|
|
174
209
|
|
|
175
210
|
if (consentInfo.canRequestAds !== true) {
|
|
@@ -195,7 +230,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
195
230
|
await this.setupAds();
|
|
196
231
|
}
|
|
197
232
|
|
|
198
|
-
if (!this._canRequestAds || !await this.canStartAdsWithoutPrompt()) {
|
|
233
|
+
if (!this._canRequestAds || (!this._limitedAdsFallback && !await this.canStartAdsWithoutPrompt())) {
|
|
199
234
|
return false;
|
|
200
235
|
}
|
|
201
236
|
|
|
@@ -219,7 +254,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
219
254
|
await AdMob.start();
|
|
220
255
|
|
|
221
256
|
await AdMob.addListener('interstitial.show', (info) => {
|
|
222
|
-
if (info.id === this._interstitialAd?.id) {
|
|
257
|
+
if ((info.id ?? info.adId) === this._interstitialAd?.id) {
|
|
223
258
|
this.isInterstitialAdReady = false;
|
|
224
259
|
if (this.onAdOpened) {
|
|
225
260
|
this.onAdOpened({
|
|
@@ -230,7 +265,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
230
265
|
}
|
|
231
266
|
});
|
|
232
267
|
await AdMob.addListener('interstitial.dismiss', (info) => {
|
|
233
|
-
if (info.id === this._interstitialAd?.id) {
|
|
268
|
+
if ((info.id ?? info.adId) === this._interstitialAd?.id) {
|
|
234
269
|
this.isInterstitialAdReady = false;
|
|
235
270
|
this._interstitialAd = null;
|
|
236
271
|
if (this.onAdClosed) {
|
|
@@ -242,7 +277,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
242
277
|
}
|
|
243
278
|
});
|
|
244
279
|
await AdMob.addListener('interstitial.loadfail', (info) => {
|
|
245
|
-
if (info.id === this._interstitialAd?.id) {
|
|
280
|
+
if ((info.id ?? info.adId) === this._interstitialAd?.id) {
|
|
246
281
|
this.isInterstitialAdReady = false;
|
|
247
282
|
this._interstitialAd = null;
|
|
248
283
|
if (this.onAdError) {
|
|
@@ -251,7 +286,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
251
286
|
}
|
|
252
287
|
});
|
|
253
288
|
await AdMob.addListener('interstitial.showfail', (info) => {
|
|
254
|
-
if (info.id === this._interstitialAd?.id) {
|
|
289
|
+
if ((info.id ?? info.adId) === this._interstitialAd?.id) {
|
|
255
290
|
this.isInterstitialAdReady = false;
|
|
256
291
|
this._interstitialAd = null;
|
|
257
292
|
if (this.onAdError) {
|
|
@@ -260,7 +295,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
260
295
|
}
|
|
261
296
|
});
|
|
262
297
|
await AdMob.addListener('rewarded.dismiss', (info) => {
|
|
263
|
-
if (info.id === this._rewardedAd?.id) {
|
|
298
|
+
if ((info.id ?? info.adId) === this._rewardedAd?.id) {
|
|
264
299
|
this._isRewardedAdLoaded = false;
|
|
265
300
|
this._rewardedAd = null;
|
|
266
301
|
if (this.onAdClosed) {
|
|
@@ -276,7 +311,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
276
311
|
}
|
|
277
312
|
});
|
|
278
313
|
await AdMob.addListener('rewarded.loadfail', (info) => {
|
|
279
|
-
if (info.id === this._rewardedAd?.id) {
|
|
314
|
+
if ((info.id ?? info.adId) === this._rewardedAd?.id) {
|
|
280
315
|
this._isRewardedAdLoaded = false;
|
|
281
316
|
this._rewardedAd = null;
|
|
282
317
|
if (this.onAdError) {
|
|
@@ -285,7 +320,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
285
320
|
}
|
|
286
321
|
});
|
|
287
322
|
await AdMob.addListener('rewarded.showfail', (info) => {
|
|
288
|
-
if (info.id === this._rewardedAd?.id) {
|
|
323
|
+
if ((info.id ?? info.adId) === this._rewardedAd?.id) {
|
|
289
324
|
this._isRewardedAdLoaded = false;
|
|
290
325
|
this._rewardedAd = null;
|
|
291
326
|
if (this.onAdError) {
|
|
@@ -294,7 +329,7 @@ export class NextGenAdMobPortal extends BasePortal {
|
|
|
294
329
|
}
|
|
295
330
|
});
|
|
296
331
|
await AdMob.addListener('rewarded.reward', (info) => {
|
|
297
|
-
if (info.id === this._rewardedAd?.id) {
|
|
332
|
+
if ((info.id ?? info.adId) === this._rewardedAd?.id) {
|
|
298
333
|
this._receivedReward = true;
|
|
299
334
|
this._rewardInfo = info.reward;
|
|
300
335
|
}
|