1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- export class DouYinAdManager {
- private bannerAd: any;
- private rewardVideoAd: any;
- private interstitialAd: any;
- constructor() {
- this.initBannerAd();
- this.initRewardVideoAd();
- this.initInterstitialAd();
- }
- private initBannerAd() {
- let tt = (window as any)["tt"];
- if (tt.createBannerAd) {
- this.bannerAd = tt.createBannerAd({
- adUnitId: 'YOUR_BANNER_AD_ID',
- style: {
- left: 0,
- top: 0,
- width: 300
- }
- });
- this.bannerAd.onLoad(() => {
- this.bannerAd.show();
- });
- this.bannerAd.onError((err) => {
- console.log('bannerAd onError', err);
- });
- this.bannerAd.onClose(() => {
- console.log('bannerAd onClose');
- });
- }
- }
- private initRewardVideoAd() {
- let tt = (window as any)["tt"];
- if (tt.createRewardedVideoAd) {
- this.rewardVideoAd = tt.createRewardedVideoAd({
- adUnitId: 'YOUR_REWARD_VIDEO_AD_ID'
- });
- this.rewardVideoAd.onLoad(() => {
- console.log('rewardVideoAd onLoad');
- });
- this.rewardVideoAd.onError((err) => {
- console.log('rewardVideoAd onError', err);
- });
- this.rewardVideoAd.onClose((res) => {
- if (res && res.isEnded) {
- console.log('rewardVideoAd onClose, user finished video');
- } else {
- console.log('rewardVideoAd onClose, user left video');
- }
- });
- }
- }
- private initInterstitialAd() {
- let tt = (window as any)["tt"];
- if (tt.createInterstitialAd) {
- this.interstitialAd = tt.createInterstitialAd({
- adUnitId: 'YOUR_INTERSTITIAL_AD_ID'
- });
- this.interstitialAd.onLoad(() => {
- console.log('interstitialAd onLoad');
- });
- this.interstitialAd.onError((err) => {
- console.log('interstitialAd onError', err);
- });
- this.interstitialAd.onClose(() => {
- console.log('interstitialAd onClose');
- });
- }
- }
- public showRewardVideoAd(callback: Function) {
- if (this.rewardVideoAd) {
- this.rewardVideoAd.show().then(() => {
- console.log('rewardVideoAd shown successfully');
- callback();
- })
- }
- }
- public showBannerAd() {
- if (this.bannerAd) {
- this.bannerAd.show().catch((err) => {
- console.log('showBannerAd error', err);
- });
- }
- }
- public showInterstitialAd() {
- if (this.interstitialAd) {
- this.interstitialAd.show().catch((err) => {
- console.log('showInterstitialAd error', err);
- });
- }
- }
- }
|