BaptisteLegrand

Comment savoir si vos visiteurs lisent réellement le contenu

May 6th, 2013
370
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. DANS WORDPRESS, VOICI CE A QUOI DEVRAIT RESSEMBLER LE CODE DE SUIVI GOOGLE ANALYTICS, DANS LE FICHIER HEADER.PHP DE VOTRE THEME
  3.  
  4. Source : http://www.baptistelegrand.fr/blog/google-analytics-comment-savoir-si-visiteurs-lisent-reellement-contenu-430.html
  5. */
  6.  
  7.  
  8. <!-- Appel de la librairie jQuery -->
  9. <script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js?ver=3.1.3'></script>
  10.  
  11. <!-- Début du code de suivi Google Analytics -->
  12. <script type="text/javascript">
  13. var _gaq = _gaq || [];
  14. _gaq.push(['_setAccount', 'UA-78966-18']);
  15.  
  16. // Ci-dessous, le script qui permet de mesurer le comportement des lecteurs du contenu
  17. /////////////////////////////////////////////////////////////////////////////////////////
  18.  
  19.  
  20. /* PLEASE DON'T REMOVE THESE CREDITS.
  21. ****************************************
  22. By Baptiste Legrand // @Baptiste_L // baptiste.legrand@gmail.com
  23. => http://www.baptistelegrand.fr/about-me
  24.  
  25. Permalink for this script & explanations
  26. - in french : http://bit.ly/10cJgSF
  27. - in english version :
  28.  
  29. Inspired by / Based on :
  30. - Eivind SAVIO's work : http://www.savio.no/blogg/a/114/tracking-content-scrollers-scanners-og-readers-in-google-analytics
  31. - and Justin CUTRONI's : http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/
  32.  
  33. Feel free to reuse / adapt this script as you wish.
  34. Just, a tweet / mail would be nice, and please leave these credits in your source so that each contributor can be identified.
  35. *****************************************/
  36.  
  37.  
  38. // Edit these if needed
  39. var debugMode = true; // True to display alerts only (nothing is sent to Google Analytics); otherwise : false (no alerts, send info to GA)
  40. var commentsTrigger = 0.3; // What percentage of comments must be scrolled down to trigger an event "Comment checker"
  41. var minReadTime = 60; // Minumum time (in seconds) to read the content, to be considered a Real Reader rather than a Scanner
  42.  
  43. // Do not modify those
  44. var timer = 0;
  45. var scrollable = false;
  46. var alerted = false;
  47. var scroller = false;
  48. var endContent = false;
  49. var beyonder = false;
  50. var pageTimeLoad = 0;
  51. var callBackTime = 100;
  52. //
  53.  
  54.    
  55. jQuery(function($)
  56. {
  57.     // Is the content long enough to be scrolled ? otherwise, don't run script
  58.     if ($(window).height() < $('#content').height()) {
  59.         scrollable = true;
  60.     }
  61.    
  62.     var contentTopPos = $('#content').offset().top; // Start of content
  63.     var contentHeight = $('#content').offset().top+ $('#content').innerHeight();    // Total content height
  64.     var commentsStart = $('#comments').offset().top; // Start of comments
  65.    
  66.     var commentsHeight = $('#comments').innerHeight();
  67.     var minCommentsScroll = commentsHeight*commentsTrigger;
  68.    
  69.    
  70.     function trackLocation() // Let's track read speed
  71.     {
  72.         bottom = $(window).height() + $(window).scrollTop(); // Reader scroll position
  73.         if (bottom > contentTopPos && !scroller) // Start timer when scroll starts
  74.         {  
  75.             scrollTimeStart = new Date().getTime();
  76.             scroller = true;
  77.             if (pageTimeLoad > 0) { timeToScroll = Math.round((scrollTimeStart-pageTimeLoad)/1000); }
  78.             else  { timeToScroll = ""; }
  79.             if(debugMode)
  80.             {
  81.                 alert("Vous avez commencé à scroller le contenu. On en déduit que vous parcourez le contenu. Cool, évènement n°1 validé.");
  82.             }
  83.             else
  84.             {
  85.                 // Event n°0 : tell Google Analytics that visitor has started reading
  86.                 _gaq.push(['_trackEvent','Contenu','Started Reading',window.location.pathname,timeToScroll,true]);
  87.             }
  88.         }
  89.        
  90.        
  91.         if(bottom >= contentHeight &&!endContent) // If reached end of content
  92.         {
  93.             now = new Date().getTime();
  94.             contentTime = Math.round((now-scrollTimeStart)/1000); // Total read time
  95.            
  96.             // var readSpeedRatio = Math.round(contentWordCount/contentTime); // Average reading speed (not used anymore)
  97.             if (contentTime < minReadTime)
  98.             {
  99.                 readerType = "Scanner"; // He read too fast : he's a scanner
  100.             }
  101.             else
  102.             {
  103.                 readerType = "Real Reader"; // He took his time to read : he's a real reader (we like him)
  104.             }
  105.            
  106.            
  107.             if(!debugMode)
  108.             {
  109.                 // Event n°1 : tell GA that user has reached end of content
  110.                 _gaq.push(['_trackEvent','Contenu','Full Read : '+readerType,window.location.pathname,contentTime,true]);
  111.                
  112.                 // Register the fact that the visitor is a Real Reader or a Scanneur, to be able to analyze what he does next
  113.                 // cf : http://cutroni.com/blog/2011/05/18/mastering-google-analytics-custom-variables/
  114.                 _gaq.push(['_setCustomVar' , 5, 'ReaderType', readerType, 2]);
  115.                
  116.             } else {
  117.                 alert("Vous avez atteint la fin du contenu. Cool, évènement n°2 validé. Vous avez parcouru le contenu en "+contentTime+" secondes, ce qui fait de vous un "+readerType);
  118.             }
  119.             endContent = true;
  120.         }
  121.        
  122.         if (bottom >= commentsStart+minCommentsScroll && !beyonder)
  123.         {
  124.             endTime = new Date().getTime();
  125.             totalTime = Math.round((endTime - scrollTimeStart)/1000);
  126.             if(!debugMode)
  127.             {
  128.                 // Tell GA that user has browed about 30% of comments
  129.                 _gaq.push(['_trackEvent','Contenu','Comments checker : '+readerType,window.location.pathname,totalTime,true]);
  130.             }
  131.             else { alert("Oh, et en plus vous vous intéressez aux commentaires. Cool cool cool. Evènement n°3 validé."); }
  132.             beyonder = true;
  133.         }
  134.     }
  135.  
  136.     var scrollStarted = false;
  137.     $(window).scroll(function () // Run script
  138.     {
  139.         if ( scrollable && scrollStarted ) // I mean, if necessary only
  140.         {
  141.             if (timer) { clearTimeout(timer); }
  142.             timer = setTimeout(trackLocation, callBackTime); // Checking regularily
  143.         }
  144.         scrollStarted = true;
  145.     });
  146. });
  147. // FIN DU SCRIPT D'ANALYSE DU COMPORTEMENT DES LECTEURS
  148. /////////////////////////////////////////////////////////
  149.  
  150. // Ci-dessous, la fin du code de suivi de Google Analytics
  151. _gaq.push(['_trackPageview']);
  152.  
  153. // Compter les visites SANS rebond rapide
  154. setTimeout("_gaq.push(['_trackEvent', 'NoBounce', '>15s',window.location.pathname,1,true])",15000);
  155.  
  156. (function()
  157. {
  158. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  159. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  160. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  161. })();
  162. </script>
  163. <!-- le code de suivi Google Analytics s'arrête ici -->
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×