<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Google Adsense | SDT 攻城獅區</title>
	<atom:link href="https://sdt.hameba.tw/tag/google-adsense/feed/" rel="self" type="application/rss+xml" />
	<link>https://sdt.hameba.tw</link>
	<description>由Steven, Der, Ted 三位高級打字員所組成，是三位工程師(攻城獅)所維護的技術分享平台，或許偶爾會分享一些日常，有任何問題或是錯誤的部分，歡迎留言告訴我們！</description>
	<lastBuildDate>Fri, 27 Dec 2019 06:15:05 +0800</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.3</generator>

<image>
	<url>https://sdt.hameba.tw/wp-content/uploads/2020/02/hameba_favicon-150x150.png</url>
	<title>Google Adsense | SDT 攻城獅區</title>
	<link>https://sdt.hameba.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Gatsbyjs 新增內容於 head</title>
		<link>https://sdt.hameba.tw/381/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gatsbyjs-%25e6%2596%25b0%25e5%25a2%259e%25e5%2585%25a7%25e5%25ae%25b9%25e6%2596%25bc-head</link>
				<comments>https://sdt.hameba.tw/381/#respond</comments>
				<pubDate>Fri, 27 Dec 2019 06:14:36 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[gatsbyjs]]></category>
		<category><![CDATA[Google Adsense]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[react]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=381</guid>
				<description><![CDATA[<p>用gatsbyjs可以快速製作出react static網頁， 但是要將google adsense 加入時發 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/381/" class="more-link">閱讀全文<span class="screen-reader-text">〈Gatsbyjs 新增內容於 head〉</span></a></p>
The post <a href="https://sdt.hameba.tw/381/">Gatsbyjs 新增內容於 head</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>用gatsbyjs可以快速製作出react static網頁，</p>
<p>但是要將google adsense 加入時發現，default設定沒有放head的方式，</p>
<p><span id="more-381"></span></p>
<p>所以官方也提供類似的方法。</p><pre class="crayon-plain-tag"># 進入專案資料夾下，執行複製指令
$ cp .cache/default-html.js src/html.js</pre><p></p><pre class="crayon-plain-tag">$ nano /src/html.js

# 內容如下
import React from "react"
import PropTypes from "prop-types"

export default function HTML(props) {
  return (
    &lt;html {...props.htmlAttributes}&gt;
      &lt;head&gt;
        &lt;meta charSet="utf-8" /&gt;
        &lt;meta httpEquiv="x-ua-compatible" content="ie=edge" /&gt;
        &lt;meta
          name="viewport"
          content="width=device-width, initial-scale=1, shrink-to-fit=no"
        /&gt;
        {props.headComponents}
      &lt;/head&gt;
      &lt;body {...props.bodyAttributes}&gt;
        {props.preBodyComponents}
        &lt;div
          key={`body`}
          id="___gatsby"
          dangerouslySetInnerHTML={{ __html: props.body }}
        /&gt;
        {props.postBodyComponents}
      &lt;/body&gt;
    &lt;/html&gt;
  )
}

HTML.propTypes = {
  htmlAttributes: PropTypes.object,
  headComponents: PropTypes.array,
  bodyAttributes: PropTypes.object,
  preBodyComponents: PropTypes.array,
  body: PropTypes.string,
  postBodyComponents: PropTypes.array,
}</pre><p>將想放入的GA, Google Adsense都可以放入Head裡面，</p>
<p>下次build product就可以看見Head有自定義的內容。</p>
<p>&nbsp;</p>
<p>Reference</p>
<p><a href="https://www.gatsbyjs.org/docs/custom-html/">https://www.gatsbyjs.org/docs/custom-html/</a></p>
<div id="gtx-trans">
<div class="gtx-trans-icon"></div>
</div>The post <a href="https://sdt.hameba.tw/381/">Gatsbyjs 新增內容於 head</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/381/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
	</channel>
</rss>
