AngularJS 和 Adsense 广告未在路线更改时加载(整个应用最多 3 个广告) [英] AngularJS and Adsense ads not loaded on route change (up to 3 ads for the entire app)

查看:28
本文介绍了AngularJS 和 Adsense 广告未在路线更改时加载(整个应用最多 3 个广告)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 AdSense 的 Angular 网站,它会在第一次加载或刷新时加载广告,但如果我浏览到另一条路线,它不会加载广告.这是我正在使用的指令:

.directive('googleAdSense', function () {返回 {限制:'A',替换:真的,templateUrl: "../../templates/googleads.html",控制器:函数(){(adsbygoogle = window.adsbygoogle || []).push({});}};});

这是我将脚本标签放置在索引文件头部的位置.所有视图都通过 ng-view 载入/载入索引文件:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

用法如下:

如何解决这个问题,以便在我转到另一个视图时加载广告?

更新:经过进一步测试,它只加载前 3 个广告,这与 Google 防止每页超过 3 个广告的情况一致......问题是我有多个视图'不被视为页面".我想知道 HTML5 模式处理历史是否与此有关...

解决方案

请参阅此处以供参考 (https://productforums.google.com/forum/#!msg/adsense/Ya498_sUlBE/hTWj64zROoEJ),但将脚本标签移动到 index.html 中对我有用.基本上,我将 ng-include 用于顶部菜单,将脚本标记用于顶部广告,然后是 ng-view,然后是最终广告.

I have an Angular site with AdSense and it will load Ads on first load or refresh, but if I browse to another route, it doesn't load the Ads. Here is the directive I am using:

.directive('googleAdSense', function () {
return {
    restrict: 'A',
    replace: true,
    templateUrl: "../../templates/googleads.html",
    controller: function () {
        (adsbygoogle = window.adsbygoogle || []).push({});
    }
};
});

Here is where I place my script tag in the head of the index file. All views load in/out of the index file via ng-view:

<!-- Google Adsense -->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

Here is the usage:

<div data-google-ad-sense></div>

How can I resolve this so it loads the Ads once I go to another View?

Update: After further testing, it only loads the first 3 ads, which is consistent with Google preventing more than 3 ads per page.... the problem is that I have multiple views that aren't being treated as "pages". I am wondering if HTML5 modes handling of history has anything to do with this...

解决方案

See here for reference (https://productforums.google.com/forum/#!msg/adsense/Ya498_sUlBE/hTWj64zROoEJ), but moving the script tags into the index.html worked for me. Basically, I use an ng-include for the top menu, have the script tag for the top ad, then the ng-view, followed by the final ad.

这篇关于AngularJS 和 Adsense 广告未在路线更改时加载(整个应用最多 3 个广告)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆