mercredi 28 janvier 2015

Google Analytics don't track correctly the normal and social events

I'm using google analytics (analytics.js) to track a couple of buttons and facebook and twitter for social part but the problem is since the last Saturday that I configured the analytics code, can't see my events registered in my dashboard and it's strange because If I open the developers console of Chrome or Firefox can see the request and is returning 200 OK so, I don't know what's the exactly error.


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="http://ift.tt/1mTQtoO 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://ift.tt/1HemFRp'
});
});

};
</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) {
}
);
});

});


Actually, Facebook and twitter open the popup to share or tweet but facebook is not detecting the FB.Event.sunscribe.


So, my errors are:



  • I don't know if my GA events are wrong but the request return 200 OK and I can't see the events in my dashboard.

  • Facebook is not detecting the Event.subscribe to once the user share, record the event


I hope someone knows what are the issues with my code. Thank you in advance.


Aucun commentaire:

Enregistrer un commentaire