UNPKG

2.71 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function getGoogleMobileAdsAppId(config) {
4 var _a, _b, _c;
5 return _c = (_b = (_a = config.android) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.googleMobileAdsAppId, (_c !== null && _c !== void 0 ? _c : null);
6}
7exports.getGoogleMobileAdsAppId = getGoogleMobileAdsAppId;
8function getGoogleMobileAdsAutoInit(config) {
9 var _a, _b, _c;
10 return _c = (_b = (_a = config.android) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.googleMobileAdsAutoInit, (_c !== null && _c !== void 0 ? _c : false);
11}
12exports.getGoogleMobileAdsAutoInit = getGoogleMobileAdsAutoInit;
13async function setGoogleMobileAdsConfig(config, manifestDocument) {
14 const appId = getGoogleMobileAdsAppId(config);
15 const autoInit = getGoogleMobileAdsAutoInit(config);
16 if (!appId) {
17 return manifestDocument;
18 }
19 let mainApplication = manifestDocument.manifest.application.filter((e) => e['$']['android:name'] === '.MainApplication')[0];
20 // add application ID
21 let existingApplicationId;
22 const newApplicationId = {
23 $: {
24 'android:name': 'com.google.android.gms.ads.APPLICATION_ID',
25 'android:value': appId,
26 },
27 };
28 if (mainApplication.hasOwnProperty('meta-data')) {
29 existingApplicationId = mainApplication['meta-data'].filter((e) => e['$']['android:name'] === 'com.google.android.gms.ads.APPLICATION_ID');
30 if (existingApplicationId.length) {
31 existingApplicationId[0]['$']['android:value'] = appId;
32 }
33 else {
34 mainApplication['meta-data'].push(newApplicationId);
35 }
36 }
37 else {
38 mainApplication['meta-data'] = [newApplicationId];
39 }
40 // add delay auto init
41 let existingDelayAutoInit;
42 const newDelayAutoInit = {
43 $: {
44 'android:name': 'com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT',
45 'android:value': !autoInit,
46 },
47 };
48 if (mainApplication.hasOwnProperty('meta-data')) {
49 existingDelayAutoInit = mainApplication['meta-data'].filter((e) => e['$']['android:name'] === 'com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT');
50 if (existingDelayAutoInit.length) {
51 existingDelayAutoInit[0]['$']['android:value'] = !autoInit;
52 }
53 else {
54 mainApplication['meta-data'].push(newDelayAutoInit);
55 }
56 }
57 else {
58 mainApplication['meta-data'] = [newDelayAutoInit];
59 }
60 return manifestDocument;
61}
62exports.setGoogleMobileAdsConfig = setGoogleMobileAdsConfig;
63//# sourceMappingURL=GoogleMobileAds.js.map
\No newline at end of file