-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdisplay-ads-on-android-using-admob.js
119 lines (91 loc) · 2.76 KB
/
display-ads-on-android-using-admob.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
-------------------------------
NOTE:
-------------------------------
Ad unit >
Ad unit settings >
Implementation instructions >
You will see 2 IDs starting with "ca-app-pub-.xxxxxxxxxxxx"
one is ADMOB_APP_ID -> use this while installing plugin
another is YOUR_AD_ID -> this is correct for ads (above will give NETWORK ERROR for ads), now have "internal error", gave my address details also, will wait and try again after some time.
-------------------------------
package.json dependencies:
I have used cordova, react, admob - so some may be unnecessary for you
-------------------------------
"dependencies": {
"babel-cli": "^6.26.0",
"babel-preset-react-app": "^3.1.2",
"cordova-admob-sdk": "0.22.0",
"cordova-android": "^7.1.4",
"cordova-browser": "^5.0.4",
"cordova-ios": "^4.5.5",
"cordova-osx": "^4.0.2",
"cordova-plugin-admob-free": "0.25.0",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-promise-polyfill": "0.0.2",
"cordova-windows": "^6.0.1"
},
*/
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
onDeviceReady: function () {
setupVideoReward();
},
//calls and displays the reward video
function setupVideoReward() {
// alert('setupVideoReward');
if (/(android)/i.test(navigator.userAgent)) {
// alert('android');
setupEvents();
}
//reward video // admob.interstitial.prepare()
var rewardConfig = {
id: 'ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // your reward Ad id
isTesting: false,
autoShow: true
};
admob.rewardvideo.prepare(rewardConfig)
.then((ok) => {
// alert('prepare success');
// alert(ok);
})
.catch(function (error) {
alert('prepare fail');
alert(error);
});
}
function setupEvents() {
document.addEventListener('admob.rewardvideo.events.LOAD_FAIL',
function (event) {
// alert('events.LOAD_FAIL');
alert(JSON.stringify(event));
}
);
document.addEventListener('admob.rewardvideo.events.LOAD',
function (event) {
// alert('events.LOAD');
admob.rewardvideo.show();
}
);
document.addEventListener('admob.rewardvideo.events.OPEN',
function (event) {
// alert('events.OPEN');
}
);
document.addEventListener('admob.rewardvideo.events.CLOSE',
function (event) {
// alert('events.CLOSE');
}
);
document.addEventListener('admob.rewardvideo.events.EXIT_APP',
function (event) {
alert('events.EXIT_APP');
}
);
/* only works if admob detects that the user has finished watching the whole reward video else it will do nothing */
document.addEventListener('admob.rewardvideo.events.REWARD',
function (event) {
alert('events.REWARD');
}
);
}