谷歌AMP插件如何添加广告和统计代码adsense/Analytics

    Google AMP 计划(Google’s Accelerated Mobile Pages Project, Google移动网页加速计划,一种用于提升移动网页加载速度的技术,谷歌声称AMP网页载入的平均速度是正常网页的4倍,有时候甚至会达到10倍,译者注)于2016上线。从此以后,Google AMP计划不断发展,并对搜索引擎和媒体网站如何与移动web发生交互产生重要影响。尽管AMP技术已经被许多媒体重点采用,但仍然存在许多亟待解答的问题。首先我们来看看如何wordpress如何启用Google AMP移动网页加速显示技术文章源自技术奇点-https://www.xerer.com/archives/26615.html

    第一步,启用Google AMP移动网页加速显示技术文章源自技术奇点-https://www.xerer.com/archives/26615.html

    网站速度优化-Google-AMP文章源自技术奇点-https://www.xerer.com/archives/26615.html

    早前关注过AMP移动加速显示优化技术(加速移动页面Accelerated Mobile Page)(百度有类似MIP,Facebook有Instant Article),尤其是在Google移动搜索里搜索新闻时候,经常见到排在前面的结果会有AMP闪电符号,打开这种结果网页也是异常地快速与简洁。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    2016年8月,Google宣布AMP移动搜索结果将适用于所有网站(Google取消了移动友好页面的Mobile Friendly标志就是为了给AMP标志让路)。百度、搜狗、雅虎日本最近也宣布支持收录AMP网页,表明此技术应用越来越广泛。大势所趋,艾薇资讯现在也开始使用AMP技术来加速移动端加载速度。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    只需在WordPress后台安装官方AMP插件(不建议安装第三方的插件, 插件的中文翻译支持参考该文章),开启插件即可——不需要任何设置。对于非移动端,直接在每篇文章页面链接的最后加上AMP就可以看到AMP显示效果。也可以使用Chrome的AMP插件来检查页面上可能的HTML语法错误。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    配置好AMP后,之后等待Google爬虫来索引就可以了——也可以手工去Google Webmaster后台提交。我的网站在开启AMP后24小时不到,就可以看到Google已经开始在移动端提供部分搜索结果的AMP(需要在Google手机移动端点击,平板和PC桌面Google都不行)网页了。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    AMP加速移动显示文章源自技术奇点-https://www.xerer.com/archives/26615.html

    AMP本质技术原理其实就是一个简洁版并内置CSS的HTML静态网页(AMP HTML),禁止掉第三方JavaScript而只用少量特定版本的AMP JavaScript,再加上从Google移动搜索结果里面出来的AMP网页全部都由Google全球CDN网络提供Cache高速缓存(AMP Cache),因此在手机上的网页加载速度,即使在移动网络下,也确实达到了异常之快,闪电秒加载,有效提高访客用户体验。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    采用AMP技术的网站加载速度比全站CDN还要快,Google在搜索结果里就开始预加载AMP页面,而且AMP页面本身的元素也已经极度精简。通过Google手机端搜索进入本文后页面的域名都直接变成Google, 比如本文的链接变成:文章源自技术奇点-https://www.xerer.com/archives/26615.html

    https://www.google.com/amp/s/www.xerer.com/archives/26578.html/amp文章源自技术奇点-https://www.xerer.com/archives/26615.html

    使用Google AMP技术的网页本身支持Google Analytics统计,也支持显示AdSense广告。但这种简洁页面的并不是没有代价和缺点:去除了除内容之外的所有其它功能,包括各种JavaScript代码,它甚至可能会有小问题——这项开源技术还在发展中,它的设计目的也不是为了适合所有类型的网站(但非常适合新闻类和博客类等含有静态内容的网站)。这也是有些互动内容较多的网站不愿意使用的原因。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    其实我的网站本身足够简洁,对手机的响应式显示也很友好,并且我也用了CloudFlare的CDN加速服务,因此,Google AMP带来移动端的加载速度提升本身并不会太明显。我使用AMP更主要的原因是因为这项技术是Google推出,为了获取AMP下更好的Google搜索排名优点(SEO),启用它应该利大于弊。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    由于是Google主推的开源服务,所以国内无法看到Google提供的AMP网页,因为在中国大陆无法使用Google搜索。而我的网站主要的访客都是从Google搜索过来,移动搜索所占比重也越来越多,为了更好的服务这些访客——节省他们的时间,开启Google AMP服务支持也无可厚非。而且,增加AMP支持原来不影响网站原来的任何东西,纯粹加分项。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    长期来看,AMP可能只是一个历史过渡期的产物,将来的移动网速只会越来越快,硬件性能也越来越好,网页加载速度也自然跟着提升。不过在目前,我觉得启用AMP还算是拥抱新技术。一万年太久,只争朝夕。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    谷歌AMP插件如何添加广告和统计代码adsense/Analytics文章源自技术奇点-https://www.xerer.com/archives/26615.html

    第二步AMP移动加速页面添加Google Analytics统计代码的设置方法文章源自技术奇点-https://www.xerer.com/archives/26615.html

    网站支持AMP移动网页加速加载技术后,从Google搜索移动端进入相应页面,加载速度确实如闪电般快捷,页面如出水芙蓉般清爽。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    对于WordPress博客而言,如果是通过官方AMP插件实现AMP加速,该插件并不自带Google Analytics统计服务,因为官方AMP插件就相当于另一套主题。因此需要用户自己添加Analyitics代码,才能实现统计服务。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    根据Google的官方总体说明,对于WordPress的官方AMP插件,Analytics代码添加方法如下(其它插件或者网站程序和此原理一样):文章源自技术奇点-https://www.xerer.com/archives/26615.html

    1、 在WordPress控制后台的AMP插件的amp/templates/single.php文件里,将以下代码添加到/head标签之前。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    <script async custom-element="amp-analytics"
    src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>Google AMP
    添加通用JavaScript文件文章源自技术奇点-https://www.xerer.com/archives/26615.html

    2 、然后再将以下代码(注意,此段统计代码不同于Analytics以前的代码,同时请将UA-XXXXX-Y替换成你自己的ID),放到amp/templates/single.php文件里的/body标签之前:文章源自技术奇点-https://www.xerer.com/archives/26615.html

    <amp-analytics type="googleanalytics">
    <script type="application/json">
    {
    "vars": {
    "account": "UA-XXXXX-Y"
    },
    "triggers": {
    "trackPageview": {
    "on": "visible",
    "request": "pageview"
    }
    }
    }
    </script>
    </amp-analytics>
    Google AMP
    添加统计代码文章源自技术奇点-https://www.xerer.com/archives/26615.html

    至此,大功靠成。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    从此AMP页面也会将访问统计发到你的Google Analyitcs里面,支持实时统计。需要分析AMP页面访问时候,可以通过AMP字段过滤出相关统计页面。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    第三部:AMP移动加速页面添加Google AdSense广告代码的设置方法文章源自技术奇点-https://www.xerer.com/archives/26615.html

    网站速度优化-Google-AMP文章源自技术奇点-https://www.xerer.com/archives/26615.html

    艾薇资讯以前不愿意使用Google AMP加速网站,说因为不方便添加AdSense广告。其实通过WordPress官方AMP插件实现的AMP网页很容易就添加AdSense广告。方法和添加AMP Google Analytics是一样的,只需要添加相应的JS库AMP格式的AdSense广告单元即可。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    具体方法如下:文章源自技术奇点-https://www.xerer.com/archives/26615.html

    1 在WordPress控制后台的AMP插件的amp/templates/single.php文件里/head之前添加以下JavaScript代码:文章源自技术奇点-https://www.xerer.com/archives/26615.html

    <script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
    AMP AdSense文章源自技术奇点-https://www.xerer.com/archives/26615.html

    2 接下来在amp/templates/single.php文件里,对应文章中需要出现广告位置的地方添加AdSense单元,注意AdSense广告单元需要是AMP格式:文章源自技术奇点-https://www.xerer.com/archives/26615.html

    以下代码是自适应尺寸广告,建议放在文章标题下(非首屏Below the fold),如下图所示(注意data-ad-client和data-ad-slot的值换成你自己的ID):文章源自技术奇点-https://www.xerer.com/archives/26615.html

    <amp-ad文章源自技术奇点-https://www.xerer.com/archives/26615.html

    layout="responsive"文章源自技术奇点-https://www.xerer.com/archives/26615.html

    width=300文章源自技术奇点-https://www.xerer.com/archives/26615.html

    height=250文章源自技术奇点-https://www.xerer.com/archives/26615.html

    type="adsense"文章源自技术奇点-https://www.xerer.com/archives/26615.html

    data-ad-client="ca-pub-1234567891234567"文章源自技术奇点-https://www.xerer.com/archives/26615.html

    data-ad-slot="1234567890">文章源自技术奇点-https://www.xerer.com/archives/26615.html

    </amp-ad>文章源自技术奇点-https://www.xerer.com/archives/26615.html

    下面的代码是首屏(Above the fold)自适应尺寸广告,建议放在文章标题之上:文章源自技术奇点-https://www.xerer.com/archives/26615.html

    <amp-ad文章源自技术奇点-https://www.xerer.com/archives/26615.html

    layout="fixed-height"文章源自技术奇点-https://www.xerer.com/archives/26615.html

    height=100文章源自技术奇点-https://www.xerer.com/archives/26615.html

    type="adsense"文章源自技术奇点-https://www.xerer.com/archives/26615.html

    data-ad-client="ca-pub-1234567891234567"文章源自技术奇点-https://www.xerer.com/archives/26615.html

    data-ad-slot="1234567890">文章源自技术奇点-https://www.xerer.com/archives/26615.html

    </amp-ad>文章源自技术奇点-https://www.xerer.com/archives/26615.html

    OK,WordPress官方插件AMP下的AdSense广告设置就是如此简单。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    我感觉AMP页面下的AdSense广告又干净、整洁、快速,和内容也浑然一体,估计点击率应该会高一些。文章源自技术奇点-https://www.xerer.com/archives/26615.html

    文章源自技术奇点-https://www.xerer.com/archives/26615.html

    weinxin
    微信公众号
    扫码关注公众号获取资源下载及吃瓜爆料
    • 本文由 发表于 2018/07/2922:26:56

    发表评论

    匿名网友