[英]Google Analytics not tracking the events correctly
我正在使用Google Analytics(分析)(analytics.js)追蹤社交功能的幾個按鈕以及Facebook和Twitter,但是問題是自從我配置分析代碼的最后一個星期六以來,我的儀表板和這很奇怪,因為如果我打開Chrome或Firefox的開發人員控制台可以看到該請求並返回200 OK,那么我不知道確切的錯誤是什么。
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<a href="#" id="my_button">My button</a>
<a href="#" id="my_facebook_button">My Facebook Button</a>
<a href="https://twitter.com/intent/tweet?text=My tweet body!&url=http://mywebsite.com"></a>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXX',
xfbml : true,
version : 'v2.2'
});
//Track FB Share function
FB.Event.subscribe('message.send', function(targetUrl) {
ga('send', {
'hitType': 'social',
'socialNetwork': 'Facebook',
'socialAction': 'Share',
'socialTarget': 'http://giftagiftcard.com'
});
});
};
</script>
<script src="jquery.js"></script>
<script src="main.js"></script>
<script>
// Google analytics
(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', 'UA-58646812-1', 'auto');
ga('send', 'pageview', {
'hitCallback': function() {
console.log('Analytics is sending data');
}
});
//Twitter Web Intents
window.twttr = (function (d,s,id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
}(document, "script", "twitter-wjs"));
//Track twitter tweets
function trackTwitter(intent_event) {
if (intent_event) {
ga('send', {
'hitType': 'social',
'socialNetwork': 'Twitter',
'socialAction': 'Tweet',
'socialTarget': 'http://mywebsite.com/'
});
}
}
</script>
</body>
</html>
main.js
$(function() {
$('#my_button').on('click', function(e) {
e.preventDefault();
ga('send', 'My button', 'button', 'click', 'My button!');
});
$('#my_facebook_button').on('click', function(e) {
e.preventDefault();
FB.ui({
method: 'feed',
name: 'The name',
link: 'http://mywebsite.com',
picture: 'http://thepicture.png',
caption: 'The caption',
description: 'The description'
},
function(response) {
}
);
});
});
實際上,Facebook和Twitter會打開彈出窗口以進行共享或鳴叫,但Facebook並未檢測到FB.Event.subscribe。
所以,我的錯誤是:
我希望有人知道我的代碼有什么問題。 先感謝您。
在main.js中,這行看起來像:
ga('send', 'My button', 'button', 'click', 'My button!');
“我的按鈕”看起來不像“事件”這樣的GA方法。
您可以使用Google Analytics(分析)調試器插件-非常有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.