我正试图通过Google Analytics跟踪Facebook的喜欢和分享。我创建了一个Facebook应用程序并安装了Google Analytics跟踪代码,Facebook Javascript SDK,社交互动跟踪代码和类似/共享按钮。
这是我的代码:
<?php $link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>
<head>
<meta property="og:url" content="<?php echo $link; ?>" />
<meta property="og:type" content="website" />
<!-- Google Analytics -->
<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','https://www.google-
analytics.com/analytics.js','ga');
ga('create', 'UA-76485748-1', 'auto');
ga('send', 'pageview');
</script>
<!-- Google Analytics -->
</head>
<body>
<!-- Facebook Javascript SDK -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0&appId=2097539277193081&autoLogAppEvents=1';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- Facebook Javascript SDK -->
<!-- Facebook Social Interaction Tracking -->
<script>
window.fbAsyncInit = function(){
FB.Event.subscribe('edge.create', function(targetURL){
ga('send', 'social', 'facebook', 'like', targetURL);
});
FB.Event.subscribe('message.send', function(location){
ga('send', 'social', 'facebook', 'send', location);
});
};
</script>
<!-- Facebook Social Interaction Tracking -->
<div class="fb-like" data-href="<?php echo $link; ?>" data-width="150" data-layout="button_count" data-action="like" data-size="large" data-show-faces="false"></div>
<div class="fb-share-button" data-href="<?php echo $link; ?>" data-layout="button_count" data-size="large" data-mobile-iframe="false">
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $link ?>;src=sdkpreparse" onclick="ga('send', 'social', 'facebook', 'send', location);" class="fb-xfbml-parse-ignore">Share</a>
</div>
...
</body>
但是,我没有在GA Acquisition&gt;中看到任何数据。社交&gt;插件,我不知道为什么或者我究竟做错了什么。
以下是我的测试网站:https://solid.miami/dev/gifthope/
任何帮助将不胜感激!谢谢!