Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- //get time
- jQuery.fixTime = function() {
- var dateObj = new Date();
- return Math.floor(dateObj.getTime() / 1000);
- }
- var startTime = jQuery.fixTime();
- jQuery(window).bind('beforeunload', function(){
- var endTime = jQuery.fixTime() - startTime;
- // get and convert headers time
- var headers = JSON.parse(localStorage.getItem('headers'));
- var str = []
- for(var i = 0; i < headers.length-1; i++) {
- var time = parseInt(headers[i+1].timeEnd) - parseInt(headers[i].timeEnd);
- str.push({'name': headers[i].name, 'time': time})
- }
- // for last element
- var time = parseInt(headers[headers.length-1].timeStart) - parseInt(endTime);
- str.push({'name': headers[headers.length-1].name, 'time': time})
- var headers_name = {},
- headers_count = {},
- newArraySeries = []
- // count sum of time for unique headers
- str.forEach(
- function(e){
- if(!headers_name[e.name]){
- headers_name[e.name] = 0
- headers_count[e.name] = 0
- }
- // convert msec to second
- headers_name[e.name] += parseInt(e.time)/1000
- headers_count[e.name]++
- }
- )
- for(var names in headers_name){
- newArraySeries.push({name : names, data : headers_name[names]})
- }
- // send autoEvents to GA for each header
- newArraySeries.forEach(function(e) {
- dataLayer.push({'event': 'autoEvent', 'eventCategory': 'AO — scrollBlocks', 'eventAction': document.title, 'eventLabel': e.name, 'eventValue': Math.round(e.data)});
- fbq('track', 'AO — scrollBlocks', {
- 'eventAction': document.title,
- 'eventLabel': e.name,
- 'eventValue': Math.round(e.data)
- });
- })
- localStorage.removeItem('headers');
- })
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement