function inArray(needle, haystack) { var length = haystack.length; for(var i = 0; i < length; i++) { if(haystack[i] == needle) return true; } return false; } var statistics = (function() { 'use strict'; /* Initialize attributes */ var STAT = { page_loader: app.get_loader2('Loading...'), /*graphs to be loaded initially upon first load*/ date_range: { 'start_date': '30daysAgo', 'end_date': 'yesterday', 'filter_input_id': '#ga_date_range', }, base_url: app.get_vars().baseurl, /*actual container of graphs when generated*/ graphs: {}, //originally => the_chart /*graphs to be loaded initially upon first load*/ graph_list_per_set: { 'first': [ //1st tab 'visitors_graph', 'sessions_graph', 'session_duration_graph', 'pageviews_graph', 'unique_pageviews_graph', 'event_views_graph', 'bounce_rate_graph', 'users_and_browsers', 'users_and_device_category', 'source_mediums_graph' ], 'second': [ //3rd tab ] }, graph_configs: { 'general': { 'utypes': '1_2_3', 'data_url': app.get_vars().baseurl + 'get_ga_data/', }, /* 1st tab */ 'visitors_graph': { data_name: 'visitors', tbl_abbrev: 'vis', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'visitors-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'sessions_graph': { data_name: 'sessions', tbl_abbrev: 'sess', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'sessions-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'session_duration_graph': { data_name: 'session_duration', tbl_abbrev: 'sess', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'session_duration-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'pageviews_graph': { data_name: 'pageviews', tbl_abbrev: 'pv', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'pageviews-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'unique_pageviews_graph': { data_name: 'unique_pageviews', tbl_abbrev: 'pv', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'unique_pageviews-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'event_views_graph': { data_name: 'event_views', tbl_abbrev: 'ev', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'event_views-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'bounce_rate_graph': { data_name: 'bounceRate', tbl_abbrev: 'bcr', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'bounceRate-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'users_and_browsers': { data_name: 'users_browsers', tbl_abbrev: 'br', container_name: 'browsers-chart', graph_type: 'pie', options: { legend: { display: false, }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.labels[tooltipItem.index]; var value = data.datasets[0].data[tooltipItem.index]; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips }, colors: [ 'rgb(255, 139, 3)', 'rgb(255, 230, 3)', 'rgb(167, 255, 3)', 'rgb(27, 163, 0)', 'rgb(3, 255, 187)', 'rgb(3, 217, 255)', 'rgb(3, 126, 255)', 'rgb(4, 48, 161)', 'rgb(114, 3, 255)', 'rgb(255, 3, 33)', 'rgb(220, 3, 255)', 'rgb(125, 0, 0)', ] }, /* 1st tab */ 'users_and_device_category': { data_name: 'users_and_device_category', tbl_abbrev: 'dv', container_name: 'device-categories-chart', graph_type: 'pie', options: { legend: { display: false, }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.labels[tooltipItem.index]; var value = data.datasets[0].data[tooltipItem.index]; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips }, colors: [ 'rgb(255, 139, 3)', 'rgb(255, 230, 3)', 'rgb(167, 255, 3)', 'rgb(27, 163, 0)', 'rgb(3, 255, 187)', 'rgb(3, 217, 255)', 'rgb(3, 126, 255)', 'rgb(4, 48, 161)', 'rgb(114, 3, 255)', 'rgb(255, 3, 33)', 'rgb(220, 3, 255)', 'rgb(125, 0, 0)', ] }, /* 3rd tab */ 'source_mediums_graph': { data_name: 'source_mediums_graph', tbl_abbrev: 'gsm', container_name: 'source_mediums_graph-chart', graph_type: 'pie', options: { legend: { display: false, }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.labels[tooltipItem.index]; var value = data.datasets[0].data[tooltipItem.index]; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips }, colors: [ 'rgb(255, 139, 3)', 'rgb(255, 230, 3)', 'rgb(167, 255, 3)', 'rgb(27, 163, 0)', 'rgb(3, 255, 187)', 'rgb(3, 217, 255)', 'rgb(3, 126, 255)', 'rgb(4, 48, 161)', 'rgb(114, 3, 255)', 'rgb(255, 3, 33)', 'rgb(220, 3, 255)', 'rgb(125, 0, 0)', ] }, }, /* * TABLES */ table_list_per_set: { 'first': [ //first tab 'f_url_clicks_table', 'f_contact_email_category_table', 'y_contact_emails_table', ], 'second': [ //second tab 'y_registrations_table', 'f_subscribers_table', 'y_events_table', 'f30days_events_table', 'f_events_per_status_table', 'y_reservations_per_subs_table', 'f30days_reservations_per_subs_table', 'y_reservations_table', 'f30days_reservations_table', 'y_cancellations_table', 'f30days_cancellations_table', 'faq_stat_table' ], 'third': [ //third tab 'f_searches_table', 'faq_searches_table', // 'source_mediums_table', ] }, table_configs: { 'general': { /* Where the data is fetched from*/ 'data_url': app.get_vars().baseurl + 'get_dashboard_table_data/', }, /* * general tab - liens cliques * url clicks */ 'f_url_clicks_table': { data_name: 'url_clicks', data_cat: 'filtered', data_containers: [], }, /* * general tab - liens cliques * contact email category data */ 'f_contact_email_category_table': { data_name: 'contact_cat', data_cat: 'filtered', data_containers: [], }, /* * general tab - liens cliques * yearly contact emails */ 'y_contact_emails_table': { data_name: 'y_contact', data_cat: 'yearly', data_containers: ['y_contact_cur_year', 'y_contact_prev_year'], }, /* * abonnes tab first row - Nombre d'inscriptions (Nouveau qui a confirmé son formulaire de première inscription) * yearly registrations */ 'y_registrations_table': { data_name: 'y0', data_cat: 'yearly', data_containers: ['y0_cur_year', 'y0_prev_year'], }, /* * abonnes tab first row - Nombre d'inscriptions (Nouveau qui a confirmé son formulaire de première inscription) * subscribers per interval based on filter */ 'f_subscribers_table': { data_name: 'fsubs', data_cat: 'filtered', data_containers: ['fsubs_interval'], }, /* * abonnes tab 2nd row - Nombre d'événements par statuts (prochainement, en cours, complets, terminés, passés, archivés) total + /année * yearly event count */ 'y_events_table': { data_name: 'y1', data_cat: 'yearly', data_containers: ['y1_cur_year', 'y1_prev_year'], }, /* * abonnes tab 2nd row - events last 30 days */ 'f30days_events_table': { data_name: 'f_y1', data_cat: 'filtered', data_containers: ['f_y1_interval'], }, /* * abonnes tab 2nd row - Nombre d'événements par statuts (prochainement, en cours, complets, terminés, passés, archivés) total + /année * number of events per backoffice status */ 'f_events_per_status_table': { data_name: 'fevents', data_cat: 'filtered', data_containers: ['fevents_proc', 'fevents_en', 'fevents_com', 'fevents_ter', 'fevents_pas', 'fevents_arc'], }, /* * abonnes tab 3rd row - Nombre de réservations effectuées (par abonnés) * yearly reservations per subscriber */ 'y_reservations_per_subs_table': { data_name: 'y2', data_cat: 'yearly', data_containers: ['y2_cur_year', 'y2_prev_year'], }, /* * abonnes tab 2nd row - subscribers last 30 days */ 'f30days_reservations_per_subs_table': { data_name: 'f_y2', data_cat: 'filtered', data_containers: ['f_y2_interval'], }, /* * abonnes tab 4th row - Nombre de places réservées * yearly reservations */ 'y_reservations_table': { data_name: 'y3', data_cat: 'yearly', data_containers: ['y3_cur_year', 'y3_prev_year'], }, /* * reservations last 30 days */ 'f30days_reservations_table': { data_name: 'f_y3', data_cat: 'filtered', data_containers: ['f_y3_interval'], }, /* * abonnes tab 5th row - Nombre d'annulations effectuées (annulation totale de réservation) * yearly cancellations */ 'y_cancellations_table': { data_name: 'y4', data_cat: 'yearly', data_containers: ['y4_cur_year', 'y4_prev_year'], }, 'f30days_cancellations_table': { data_name: 'f_y4', data_cat: 'filtered', data_containers: ['f_y4_interval'], }, /* * recherches tab * faq searches */ 'f_searches_table': { data_name: 's', data_cat: 'filtered', data_containers: [], }, 'faq_searches_table': { data_name: 'faq_search', data_cat: 'filtered', data_containers: [], }, 'source_mediums_table': { data_name: 'source_mediums', data_cat: 'filtered', data_containers: [], }, 'faq_stat_table': { data_name: 'faq_stat', data_cat: 'filtered', data_containers: [], }, }, total_search: 0, } /***************************************************************************** * * Event listeners for UI elements * ****************************************************************************/ $('button#filter_dashboard_data').on('click', function(event) { event.preventDefault(); STAT.toggleLoader('tab', 'show'); STAT.toggleLoader('filter', 'show'); setTimeout(function(){ STAT.generateGraphs(STAT.graph_list_per_set['first']) statistics.generateTables(statistics.table_list_per_set['first']) statistics.generateTables(statistics.table_list_per_set['second']) statistics.generateTables(statistics.table_list_per_set['third']) }, 100); }); // set data triggers for each graph $('.chart-btn-holder').on('click', 'button:not(.total_u_data)', function() { // remove users to get chart data name var chart_data_name = ((this.id).split('___'))[0]; var chart_user_type = ((this.id).split('___'))[1]; $(this).toggleClass('disable-btn'); // do not disable all, at least 1 trigger should remain active var len = ($('#'+chart_data_name+'_triggers .disable-btn').toArray()).length; if (len == 3) { $(this).removeClass('disable-btn'); } else { STAT.graphs[chart_data_name+'-chart'].data.datasets.forEach(function(ds) { if(ds.label == chart_user_type){ ds.hidden = !ds.hidden; } }); STAT.graphs[chart_data_name+'-chart'].update(); } }); /* Load tab data on click */ $('.statistics-tabs').on('click', function(event) { event.preventDefault(); if (!$(this).hasClass('tab_data_loaded')) { /* Load tab data */ // switch (this.id) { // case 'general-tabb': // STAT.generateGraphs(STAT.graph_list_per_set['first']) // break; // case 'abonnes-tabb': // break; // case 'recherches-tabb': // STAT.generateGraphs(STAT.graph_list_per_set['second']) // break; // default: // } /* Indicate that the tab data has been loaded*/ $(this).addClass('tab_data_loaded'); } else { } }); $('a#export_dashboard_data').on('click', function(event) { STAT.toggleLoader('tab', 'show'); app.btn_loader('#export_dashboard_data'); STAT.exportDashboardData(); setTimeout(function(){ app.rmbtn_loader('#export_dashboard_data'); STAT.toggleLoader('export', 'remove'); }, 1000); }); /***************************************************************************** * * Methods for dealing with statistics page * ****************************************************************************/ /** * @method * initializes the status of buttons (onload) base on the main buttons */ STAT.initConfigs = function() { Chart.defaults.global.animation.duration = 900; Chart.defaults.global.responsive = true; Chart.defaults.global.maintainAspectRatio = false; // load a locale for numbers numeral.register('locale', 'fr', { delimiters: { thousands: ' ', decimal: ',' }, abbreviations: { thousand: 'k', million: 'm', billion: 'b', trillion: 't' }, ordinal : function (number) { return number === 1 ? 'er' : 'ème'; }, currency: { symbol: 'MGA' } }); numeral.locale('fr'); /* * initialize the daterangepicker, set the default date range to 30 days ago from current date */ $('.datetimepicker').daterangepicker({ autoApply: true, locale: { format: 'DD/MM/YYYY', // cancelLabel : dashboard_data.cancel, // applyLabel : 'Appliquer le filtre', "daysOfWeek": 'di_lu_ma_me_je_ce_sa'.split('_'), "monthNames": 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_') }, defaultDate : moment().subtract(30, 'days'), startDate: moment().subtract(30, 'days'), endDate: moment().subtract(1, 'days'), maxDate: moment().subtract(1, 'days'), }); }; /** ** @method formats number to french */ STAT.formatNumToFr = function(number){ return (number - Math.floor(number))? numeral(number).format('0,0.00') : numeral(number).format('0,0'); }; STAT.formatNumToFrNoDec = function(number){ return numeral(number).format('0,0'); }; /** ** @method sets the start and end date when filtering graph ** @param string date range : from date filter input */ STAT.setDateFilter = function(){ var date_range = $('#ga_date_range').val(); if (date_range) { date_range = date_range.split(' - '); STAT.date_range.start_date = date_range[0].replace(/\//g, '-');; STAT.date_range.end_date = date_range[1].replace(/\//g, '-');; } }; /** ** @method sets user filter, depends on what is checked in the filter */ STAT.setUserFilter = function(){ var checked_utypes = $('.user-filter:checked').toArray(); if (0 != checked_utypes.length || checked_utypes.length < 3) { var utypes = []; for (var i = 0; i < checked_utypes.length; i++) { utypes.push(checked_utypes[i].value); } STAT.graph_configs.general.utypes = utypes.join('_'); } }; /** ** @method reset box values to zero for the active tab */ STAT.resetGraphBoxValues = function(){ $('li.active>a.statistics-tabs span.box_values').html(0); $('span.box_values_total').html(0); }; /** ** @method reset box values to zero */ STAT.disableEmptyBoxValues = function(graph_category){ var stat_btn = ($('#'+graph_category+'_triggers .stat_btn').toArray()); for (var i = 0; i < stat_btn.length; i++) { var box_val = parseInt($('#'+stat_btn[i].id + ' .box_values').html()); if (box_val == 0) { $('#'+stat_btn[i].id).attr('disabled', 'disabled'); $('#'+stat_btn[i].id).addClass('disable-btn'); } else { $('#'+stat_btn[i].id).removeAttr('disabled'); $('#'+stat_btn[i].id).removeClass('disable-btn'); } } }; /** ** @method set loader */ STAT.toggleLoader = function(item, action){ switch (item) { case 'tab': if (action == 'remove') { app.remove_loader(); return; } /* Set tab loader */ $('.tab-pane.active').prepend(STAT.page_loader); break; case 'export': if (action == 'remove') { app.remove_loader(); return; } /* Set tab loader */ $('.tab-pane.active').prepend(app.get_loader2('Exporting...')); break; case 'filter': if (action == 'remove') { app.rmbtn_loader('#filter_dashboard_data'); return; } app.btn_loader('#filter_dashboard_data'); break; default: } }; /** ** @method plot graph data, per graph type have specific ways of data manipulation */ STAT.prepAndPlot = { /* GRAPHS */ 'prepare_visitors_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_sessions_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_session_duration_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']?row[g_info['tbl_abbrev']+'_rdata']:0); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']?row[g_info['tbl_abbrev']+'_rdata']:0); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_pageviews_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_unique_pageviews_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_event_views_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_bounce_rate_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total_sess_rdata' : 0, 'Total_sess_br' : 0, 'Nouveaux_sess_rdata' : 0, 'Nouveaux_sess_br' : 0, 'Connus_sess_rdata' : 0, 'Connus_sess_br' : 0, 'Connectés_sess_rdata' : 0, 'Connectés_sess_br' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type'] + '_sess_rdata'] += parseInt(row['sess_rdata']); accu_box_values[row['user_type'] + '_sess_br'] += parseInt(row['sess_br']); if (row['user_type'] != 'Connectés') { /* Sum up all values for all users => accu box values total (except connected user)*/ // total sessions accu_box_values.Total_sess_rdata += parseInt(row['sess_rdata']); // total bounce rate per session accu_box_values.Total_sess_br += parseInt(row['sess_br']); } /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html( STAT.formatNumToFr( Math.round( (accu_box_values[key + '_sess_br']/accu_box_values[key + '_sess_rdata']) * 100 ) )); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html( STAT.formatNumToFr( Math.round( (accu_box_values.Total_sess_br/accu_box_values.Total_sess_rdata) * 100 ) )); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_users_and_browsers': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* labels of each slice */ }, datasets_data = { 'all' : [], }, /* all data for the pie graph */ table_data = ''; var color_index = 0; data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row['rtype']); } /* Collect dataset data per slice */ datasets_data['all'].push(row['vis_rdata']);; /* Set table data */ table_data += `