Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- DANS WORDPRESS, VOICI CE A QUOI DEVRAIT RESSEMBLER LE CODE DE SUIVI GOOGLE ANALYTICS, DANS LE FICHIER HEADER.PHP DE VOTRE THEME
- Source : http://www.baptistelegrand.fr/blog/google-analytics-comment-savoir-si-visiteurs-lisent-reellement-contenu-430.html
- */
- <!-- Appel de la librairie jQuery -->
- <script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js?ver=3.1.3'></script>
- <!-- Début du code de suivi Google Analytics -->
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-78966-18']);
- // Ci-dessous, le script qui permet de mesurer le comportement des lecteurs du contenu
- /////////////////////////////////////////////////////////////////////////////////////////
- /* PLEASE DON'T REMOVE THESE CREDITS.
- ****************************************
- By Baptiste Legrand // @Baptiste_L // baptiste.legrand@gmail.com
- => http://www.baptistelegrand.fr/about-me
- Permalink for this script & explanations
- - in french : http://bit.ly/10cJgSF
- - in english version :
- Inspired by / Based on :
- - Eivind SAVIO's work : http://www.savio.no/blogg/a/114/tracking-content-scrollers-scanners-og-readers-in-google-analytics
- - and Justin CUTRONI's : http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/
- Feel free to reuse / adapt this script as you wish.
- Just, a tweet / mail would be nice, and please leave these credits in your source so that each contributor can be identified.
- *****************************************/
- // Edit these if needed
- var debugMode = true; // True to display alerts only (nothing is sent to Google Analytics); otherwise : false (no alerts, send info to GA)
- var commentsTrigger = 0.3; // What percentage of comments must be scrolled down to trigger an event "Comment checker"
- var minReadTime = 60; // Minumum time (in seconds) to read the content, to be considered a Real Reader rather than a Scanner
- // Do not modify those
- var timer = 0;
- var scrollable = false;
- var alerted = false;
- var scroller = false;
- var endContent = false;
- var beyonder = false;
- var pageTimeLoad = 0;
- var callBackTime = 100;
- //
- jQuery(function($)
- {
- // Is the content long enough to be scrolled ? otherwise, don't run script
- if ($(window).height() < $('#content').height()) {
- scrollable = true;
- }
- var contentTopPos = $('#content').offset().top; // Start of content
- var contentHeight = $('#content').offset().top+ $('#content').innerHeight(); // Total content height
- var commentsStart = $('#comments').offset().top; // Start of comments
- var commentsHeight = $('#comments').innerHeight();
- var minCommentsScroll = commentsHeight*commentsTrigger;
- function trackLocation() // Let's track read speed
- {
- bottom = $(window).height() + $(window).scrollTop(); // Reader scroll position
- if (bottom > contentTopPos && !scroller) // Start timer when scroll starts
- {
- scrollTimeStart = new Date().getTime();
- scroller = true;
- if (pageTimeLoad > 0) { timeToScroll = Math.round((scrollTimeStart-pageTimeLoad)/1000); }
- else { timeToScroll = ""; }
- if(debugMode)
- {
- alert("Vous avez commencé à scroller le contenu. On en déduit que vous parcourez le contenu. Cool, évènement n°1 validé.");
- }
- else
- {
- // Event n°0 : tell Google Analytics that visitor has started reading
- _gaq.push(['_trackEvent','Contenu','Started Reading',window.location.pathname,timeToScroll,true]);
- }
- }
- if(bottom >= contentHeight &&!endContent) // If reached end of content
- {
- now = new Date().getTime();
- contentTime = Math.round((now-scrollTimeStart)/1000); // Total read time
- // var readSpeedRatio = Math.round(contentWordCount/contentTime); // Average reading speed (not used anymore)
- if (contentTime < minReadTime)
- {
- readerType = "Scanner"; // He read too fast : he's a scanner
- }
- else
- {
- readerType = "Real Reader"; // He took his time to read : he's a real reader (we like him)
- }
- if(!debugMode)
- {
- // Event n°1 : tell GA that user has reached end of content
- _gaq.push(['_trackEvent','Contenu','Full Read : '+readerType,window.location.pathname,contentTime,true]);
- // Register the fact that the visitor is a Real Reader or a Scanneur, to be able to analyze what he does next
- // cf : http://cutroni.com/blog/2011/05/18/mastering-google-analytics-custom-variables/
- _gaq.push(['_setCustomVar' , 5, 'ReaderType', readerType, 2]);
- } else {
- 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);
- }
- endContent = true;
- }
- if (bottom >= commentsStart+minCommentsScroll && !beyonder)
- {
- endTime = new Date().getTime();
- totalTime = Math.round((endTime - scrollTimeStart)/1000);
- if(!debugMode)
- {
- // Tell GA that user has browed about 30% of comments
- _gaq.push(['_trackEvent','Contenu','Comments checker : '+readerType,window.location.pathname,totalTime,true]);
- }
- else { alert("Oh, et en plus vous vous intéressez aux commentaires. Cool cool cool. Evènement n°3 validé."); }
- beyonder = true;
- }
- }
- var scrollStarted = false;
- $(window).scroll(function () // Run script
- {
- if ( scrollable && scrollStarted ) // I mean, if necessary only
- {
- if (timer) { clearTimeout(timer); }
- timer = setTimeout(trackLocation, callBackTime); // Checking regularily
- }
- scrollStarted = true;
- });
- });
- // FIN DU SCRIPT D'ANALYSE DU COMPORTEMENT DES LECTEURS
- /////////////////////////////////////////////////////////
- // Ci-dessous, la fin du code de suivi de Google Analytics
- _gaq.push(['_trackPageview']);
- // Compter les visites SANS rebond rapide
- setTimeout("_gaq.push(['_trackEvent', 'NoBounce', '>15s',window.location.pathname,1,true])",15000);
- (function()
- {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- </script>
- <!-- le code de suivi Google Analytics s'arrête ici -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement