Angular.js &Adsense [英] Angular.js & Adsense

查看:30
本文介绍了Angular.js &Adsense的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 angular.js 应用程序上投放广告,我阅读了一些内容后发现无法仅复制和粘贴普通的 Adsense 代码.

我听说你应该将它包装在一个带有嵌入的指令中",我能找到的唯一例子是另一个 Stackoverflow 帖子:AngularJs 和 AddThis 社交插件

有人可以帮助指导如何使用 Google Adsense 执行此操作吗?

解决方案

你需要创建一个指令

yourApp.directive('ads', function() {返回 {限制:'A',templateUrl: 'partiels/adsTpl',控制器:函数(){(adsbygoogle = window.adsbygoogle || []).push({});}};});

在我的案例partiels/adsTpl.html"中使用您的广告代码创建一个模板

将指令添加到您的页面

 

将 adSense js 调用放在主页的 head 部分,然后放在 angularjs 之前

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

等等,这对我来说非常适合

I'm trying to put ads on my angular.js app, and I've done some reading and discovered it isn't possible to just copy and paste the normal adsense code.

I've heard you are supposed to "wrap it in a directive with a transclusion," and the only example I can find of this is another Stackoverflow post: AngularJs and AddThis social plugin

Can someone help give guidance about how to go about doing this with Google Adsense?

解决方案

you need to create a directive

yourApp.directive('ads', function() {
    return {
        restrict: 'A',
        templateUrl: 'partiels/adsTpl',
        controller: function(){
            (adsbygoogle = window.adsbygoogle || []).push({});
        }
    };
});

create a template with your ads code in my case "partiels/adsTpl.html"

<ins class="adsbygoogle"
 style="display:inline-block;width:300px;height:250px"
 data-ad-client="ca-pub-00000000"
 data-ad-slot="000000"></ins>

add the directive to your page

 <div data-ads></div>

place the adSense js call in the head section of your main page before angularjs

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

et voila , this is work perfectly for me

这篇关于Angular.js &amp;Adsense的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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