mardi 24 février 2015

Google Analytics event tracker custom social button

I have a question about tracking event on google analytics.


I'd like to track my custom social button with google analytics event track but what I did don't seems work well, or maybe I don't know where search on google analytics. This is my code:



<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', 'UA-XXXXXXXX-X', 'auto');
ga('send', 'pageview');

</script>

<script type="text/javascript">
jQuery( document ).ready(function($) {
$('#fb_btn').on('click', function(e){
ga('send', 'social', 'facebook', 'send', '<?php the_permalink() ?>');
});

$('#tw_btn').on('click', function(){
ga('send', 'social', 'twitter', 'tweet', '<?php the_permalink() ?>');
});

$('#pn_btn').on('click', function(){
ga('send', 'social', 'pinterest', 'pinned', '<?php the_permalink() ?>');
});
});
</script>


Obviously I'm writing javascript code on a php page(wordpress) so I print my page with .


My buttons have onclick function. For example facebook button:



<a id="fb_btn" href="http://ift.tt/1cFNY44 the_permalink() ?>" class="social_button_facebook" target="_blank" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=400'); return false;">
<img src="<?php bloginfo('template_url'); ?>/img/share/facebook.png" alt="facebook icon">
<span><strong></strong><small class="hidden_ab_test">Share This</small> </span>
</a>


Can can be a problem?


Also I found to add this to my code:



'hitCallback': function() {
console.log('analytics.js done sending data');
}


The console.log write the sentence but if I check on analytics I don't find anything.


Where am I doing wrong? Thanks!!


Aucun commentaire:

Enregistrer un commentaire