1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | function 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 | }
|
7 | exports.getGoogleMobileAdsAppId = getGoogleMobileAdsAppId;
|
8 | function 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 | }
|
12 | exports.getGoogleMobileAdsAutoInit = getGoogleMobileAdsAutoInit;
|
13 | async 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 |
|
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 |
|
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 | }
|
62 | exports.setGoogleMobileAdsConfig = setGoogleMobileAdsConfig;
|
63 |
|
\ | No newline at end of file |