2014-10-10 190 views
0

我已經完成Google跟蹤轉換。現在我也需要Facebook像素跟蹤。Facebook跟蹤和Google跟蹤腳本

我的谷歌主管腳本是這樣的:

<script> 
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

ga('create', 'XX-XXXXXXXX-X' 'auto'); 
ga('send', 'pageview'); 

</script> 

我的JavaScript調用了谷歌看起來是這樣的:

if (typeof ga !== 'undefined') 
{ 
    ga('send', 'event', 'Blub', 'blub'); 
} 

現在我需要添加Facebook的跟蹤,我從Facebook得到這個腳本:

<script>(function() { 
    var _fbq = window._fbq || (window._fbq = []); 
    if (!_fbq.loaded) { 
    var fbds = document.createElement('script'); 
    fbds.async = true; 
    fbds.src = '//connect.facebook.net/en_US/fbds.js'; 
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(fbds, s); 
    _fbq.loaded = true; 
} 
})(); 
window._fbq = window._fbq || []; 
window._fbq.push(['track', 'XXXXXXXXXXXXX', {'value':'0.00','currency’:'XXX'}]); 
</script> 

我該如何整合Facebook代碼而不必泄露Google代碼? 如果我同時使用,是否有問題?

BR

回答

0

您可以添加它沒有任何問題。

<script> 
/* Facebook tracking */ 
(function() { 
    var _fbq = window._fbq || (window._fbq = []); 
    if (!_fbq.loaded) { 
    var fbds = document.createElement('script'); 
    fbds.async = true; 
    fbds.src = '//connect.facebook.net/en_US/fbds.js'; 
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(fbds, s); 
    _fbq.loaded = true; 
} 
})(); 

/* Google Analytics tracking */ 
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

ga('create', 'XX-XXXXXXXX-X' 'auto'); 
ga('send', 'pageview'); 

</script> 

對於事件:

if (typeof ga !== 'undefined') 
{ 
    ga('send', 'event', 'Blub', 'blub'); 
} 
window._fbq = window._fbq || []; 
window._fbq.push(['track', 'XXXXXXXXXXXXX', {'value':'0.00','currency’:'XXX'}]); 
+0

謝謝!我已經這樣做了。完美的作品。 – blubbering 2014-10-13 09:53:52

+0

我可以知道..這個代碼(Facebook跟蹤)的目的是什麼..我對此有疑問,我需要在我的shopify商店實施..你能解釋我嗎?謝謝 – pcs 2015-06-17 09:32:28

+0

@saina - 只有當你運行的是facebook廣告。更多信息:https://www.facebook.com/help/435189689870514/ – MisterPhilip 2015-06-21 22:25:56