我與我緊密合作的seo公司告訴我,我需要在我的流星項目的主體標籤之間添加此代碼。如何爲meteor.js添加谷歌再營銷代碼?
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/949352235 /?value=0&guid=ON&script=0"/>
</div>
</noscript>
但是,正如我們所知,腳本標籤在body標籤內不能正確執行。 所以我搜索谷歌找到答案,我發現這個代碼,可以工作,但它是在反應。我怎樣才能將這個反應代碼轉換爲正常的JavaScript,我可以從模板或其他東西中引用。我在想一個onCreated和orRendered函數。
GoogleTag = React.createClass({
displayName : 'GoogleTag',
render(){
var src = '';
if(this.props.type === 'conversion'){
src = _.template('//www.googleadservices.com/pagead/conversion/<%=id%>/?label=<%=label%>&guid=ON&script=0'),
src = src({id : this.props.id, label : this.props.label})
}
if (this.props.type === 'remarketing') {
src = _.template('//googleads.g.doubleclick.net/pagead/viewthroughconversion/<%=id%>/?value=0&guid=ON&script=0'),
src = src({id: this.props.id})
}
var style = {
display : "inline"
},
imgStyle = {
borderStyle : "none"
}
return (
<div style={style}>
<img height="1" width="1" style={imgStyle} alt="" src={src}/>
</div>
)
}
})
嘿Lieuwe,謝謝爲了您的評論。 我做了你所說的,並將腳本標籤放在頭部,並且我在我的谷歌標籤助理上收到了這個錯誤。 http://s11.postimg.org/olv1wnzb7/Screen_Shot_2016_03_16_at_10_30_50_AM.png – DCastillo
@DCastillo是不是更像是一個警告?我沒有使用Google Tag Assistant的經驗,但我想這是因爲在頭塊中渲染腳本。但Meteor默認會這樣做,所以這不會成爲問題。如果你真的必須把它放在體內,請看一下https://github.com/meteorhacks/meteor-inject-initial(特別是Inject.rawBody函數) –
好的,謝謝,我會試試這個。 – DCastillo