@cardsjd/portal 0.1.14 → 0.1.15

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 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 (await this.showInterstitialAd()) {
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.loadUmp();
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.loadUmp();
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cardsjd/portal",
3
3
  "private": false,
4
- "version": "0.1.14",
4
+ "version": "0.1.15",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "publishConfig": {