我在Ionic 3上使用Videogular 2。 我按照本教程(https://videogular.github.io/videogular2/modules/ima-ads/)进行实施。但是,当Videogular尝试在VgImaAds.loadAds方法上加载广告时,会出现此错误“未定义googletag”。我已导入App.module.ts中所需的每个模块。这是App.module.ts中的导入。
imports: [
IonicModule.forRoot(MyApp,{
backButtonText:'',
backButtonIcon:'arrow-back',
iconMode:'md',
modalEnter: 'modal-slide-in',
modalLeave: 'modal-slide-out',
}),
IonicStorageModule.forRoot(),
BrowserModule,
VgCoreModule,
VgControlsModule,
VgOverlayPlayModule,
VgBufferingModule,
VgImaAdsModule]
这是我的页面组件html。
<ion-content>
<vg-player id="demo-player">
<vg-ima-ads
[vgCompanion]="'companion-ad'"
[vgCompanionSize]="[728, 90]"
[vgNetwork]="'6062'"
[vgUnitPath]="'iab_vast_samples'"
[vgAdTagUrl]="'http://pubads.g.doubleclick.net/gampad/ads?sz=640x360&iu=/20277799247/Tv8-App-Preroll&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&url=[referrer_url]&description_url=[description_url]&correlator='"
[vgSkipButton]="'.skip-button'">
</vg-ima-ads>
<video [vgMedia]="media" #media id="singleVideo" preload="auto" crossorigin>
<source [src]="liveStreamLink" type="application/x-mpegURL">
</video>
</vg-player>
<div class='skip-button'>custom skip ad button</div>
<div id="companion-ad"></div>
</ion-content>
另外,我已经在index.html的head部分添加了标记。但显然,它无法在VgImaAds.loadAds上找到此脚本的googletag属性。我该怎么办?
答案 0 :(得分:1)
您需要在声明index.html
中的ima脚本之前初始化googletag属性<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true; gads.type = 'text/javascript';
gads.src = 'https://www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>