forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartAd.js
More file actions
56 lines (44 loc) · 1.43 KB
/
startAd.js
File metadata and controls
56 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let adUnitIdBanner = "ca-app-pub-5911839694379275/9157899592"; // Production
let adUnitIdInterstitial = "ca-app-pub-5911839694379275/9570937608"; // Production
let initialized = false;
export default async function startAd() {
if (!IS_FREE_VERSION || !admob) return;
if (!initialized) {
initialized = true;
if (BuildInfo.type === "debug") {
adUnitIdBanner = "ca-app-pub-3940256099942544/6300978111"; // Test
adUnitIdInterstitial = "ca-app-pub-3940256099942544/5224354917"; // Test
}
}
const consentStatus = await consent.getConsentStatus();
if (consentStatus === consent.ConsentStatus.Required) {
await consent.requestInfoUpdate();
}
const formStatus = await consent.getFormStatus();
if (formStatus === consent.FormStatus.Available) {
const form = await consent.loadForm();
form.show();
}
await admob.start();
const currentHour = new Date().getHours();
//currentHour >= 22: Covers 10:00 PM to 11:59 PM.
//currentHour < 5: Covers 12:00 AM to 4:59 AM.
const isQuietHours = currentHour >= 22 || currentHour < 5;
await admob.configure({
appMuted: isQuietHours,
appVolume: isQuietHours ? 0.0 : 1.0,
});
const banner = new admob.BannerAd({
adUnitId: adUnitIdBanner,
position: "bottom",
});
const interstitial = new admob.InterstitialAd({
adUnitId: adUnitIdInterstitial,
});
interstitial.load();
interstitial.on("dismiss", () => {
interstitial.load();
});
window.ad = banner;
window.iad = interstitial;
}