angular项目接入google adsense

angular接入google adsense有两种方法:

一,与普通接入类似,暂定名为原生接入

        1,在index.html <head>标签加入自动广告代码(注意:广告码换成自己的):

        <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?                  client=ca-pub-xxxxxx" crossorigin="anonymous"></script>

        2,在希要插入广告的组件中.ts文件加入:

        ((<any>window)['adsbygoogle'] = (<any>window)['adsbygoogle'] || []).push({

        });

        3,在组件的.html加入ins代码(即在adsense后台拷贝的广告点代码):

        <ins class="adsbygoogle"

             style="display:block;width:360px;height:110px"        // 测试宽度有效,高度无效

             data-ad-client="ca-pub-xxxxxx"

             data-ad-slot="xxxxxx"

             data-ad-format="auto"

             data-full-width-responsive="true">

        </ins>

二,使用插件 ng2-adsense

        1,安装插件: npm install ng2-adsense,如果提示版本不对,安装对应合适版本: npm install         ng2-adsense@xxx.xxx.xxx

        2,在app.module.ts加入: import { AdsenseModule } from 'ng2-adsense';

        imports: [

                ...,

                AdsenseModule.forRoot({

                adClient: 'ca-pub-xxxxxxxxxxxxxxx',

         })]

        

        3,在index.html <head>标签加入自动广告代码(注意:广告码换成自己的):

        <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?                  client=ca-pub-xxxxxx" crossorigin="anonymous"></script>

        4,在需要插入广告的组件的.html加入:

        <div>

                <ng-adsense

                    [adClient]="'ca-pub-xxxxxx'"

                    [adSlot]="xxxxxx"

                    [display]="'block'"

                    [width]="320"

                    [height]="108">

                </ng-adsense>

            </div>

ng-adsense参数:

adClient    string    account ca-pub-XXXXXXXXXXXXXXXX
adSlot    string/number    ad slot/number
adFormat    string    adsense ad format: auto,rectangle,vertical,horizontal,inline(可以组合,例: "rectangle,horizontal")
adRegion    string    older adsense code to make all ads on page the same
display    string    element display style
fullWidthResponsive    boolean    enable full width responsive ad
height    number    element height in px
width    number    element width in px
layout    string    used for in-feed ads
layoutKey    string    used for in-feed ads
pageLevelAds    boolean    enable page-level ads
adtest    string    sets up some sort of google test ad
className    string    add custom class names to the "ins" element

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值