| 1 |
/*- |
| 2 |
* Author: Alin Marcu |
| 3 |
* Author URI: https://deconf.com |
| 4 |
* Copyright 2013 Alin Marcu |
| 5 |
* License: GPLv2 or later |
| 6 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 7 |
*/ |
| 8 |
|
| 9 |
"use strict"; |
| 10 |
|
| 11 |
if (aiwpItemData.mapsApiKey) { |
| 12 |
google.charts.load('current', { |
| 13 |
'mapsApiKey': aiwpItemData.mapsApiKey, |
| 14 |
'packages': ['corechart', 'table', 'orgchart', 'geochart', 'controls'] |
| 15 |
}); |
| 16 |
} else { |
| 17 |
google.charts.load('current', { |
| 18 |
'packages': ['corechart', 'table', 'orgchart', 'geochart', 'controls'] |
| 19 |
}); |
| 20 |
} |
| 21 |
|
| 22 |
google.charts.setOnLoadCallback(AIWPReportLoad); |
| 23 |
|
| 24 |
// Get the numeric ID |
| 25 |
aiwpItemData.getID = function(item) { |
| 26 |
if (aiwpItemData.scope == 'admin-item') { |
| 27 |
if (typeof item.id == "undefined") { |
| 28 |
return 0 |
| 29 |
} |
| 30 |
if (item.id.split('-')[1] == "undefined") { |
| 31 |
return 0; |
| 32 |
} else { |
| 33 |
return item.id.split('-')[1]; |
| 34 |
} |
| 35 |
} else { |
| 36 |
if (typeof item.id == "undefined") { |
| 37 |
return 1; |
| 38 |
} |
| 39 |
if (item.id.split('-')[4] == "undefined") { |
| 40 |
return 1; |
| 41 |
} else { |
| 42 |
return item.id.split('-')[4]; |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
// Get the selector |
| 48 |
aiwpItemData.getSelector = function(scope) { |
| 49 |
if (scope == 'admin-item') { |
| 50 |
return 'a[id^="aiwp-"]'; |
| 51 |
} else { |
| 52 |
return 'li[id^="wp-admin-bar-aiwp"] a'; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
aiwpItemData.responsiveDialog = function() { |
| 57 |
var dialog, wWidth, visible; |
| 58 |
|
| 59 |
visible = jQuery(".ui-dialog:visible"); |
| 60 |
|
| 61 |
// on each visible dialog |
| 62 |
visible.each(function() { |
| 63 |
dialog = jQuery(this).find(".ui-dialog-content").data("ui-dialog"); |
| 64 |
// on each fluid dialog |
| 65 |
if (dialog.options.fluid) { |
| 66 |
wWidth = jQuery(window).width(); |
| 67 |
// window width vs dialog width |
| 68 |
if (wWidth < (parseInt(dialog.options.maxWidth) + 50)) { |
| 69 |
// don't fill the entire screen |
| 70 |
jQuery(this).css("max-width", "90%"); |
| 71 |
} else { |
| 72 |
// maxWidth bug fix |
| 73 |
jQuery(this).css("max-width", dialog.options.maxWidth + "px"); |
| 74 |
} |
| 75 |
// change dialog position |
| 76 |
dialog.option("position", dialog.options.position); |
| 77 |
} |
| 78 |
}); |
| 79 |
} |
| 80 |
|
| 81 |
jQuery.fn.extend({ |
| 82 |
aiwpItemReport: function(itemId) { |
| 83 |
var postData, tools, template, reports, refresh, init, swmetric, slug = "-" + itemId; |
| 84 |
|
| 85 |
tools = { |
| 86 |
setCookie: function(name, value) { |
| 87 |
var expires, dateItem = new Date(); |
| 88 |
|
| 89 |
if (aiwpItemData.scope == 'admin-widgets') { |
| 90 |
name = "aiwp_wg_" + name; |
| 91 |
} else { |
| 92 |
name = "aiwp_ir_" + name; |
| 93 |
} |
| 94 |
dateItem.setTime(dateItem.getTime() + (24 * 60 * 60 * 1000 * 365)); |
| 95 |
expires = "expires=" + dateItem.toUTCString(); |
| 96 |
document.cookie = name + "=" + value + "; " + expires + "; path=/"; |
| 97 |
}, |
| 98 |
getCookie: function(name) { |
| 99 |
var cookie, cookiesArray, div, i = 0; |
| 100 |
|
| 101 |
if (aiwpItemData.scope == 'admin-widgets') { |
| 102 |
name = "aiwp_wg_" + name + "="; |
| 103 |
} else { |
| 104 |
name = "aiwp_ir_" + name + "="; |
| 105 |
} |
| 106 |
cookiesArray = document.cookie.split(';'); |
| 107 |
for (i = 0; i < cookiesArray.length; i++) { |
| 108 |
cookie = cookiesArray[i]; |
| 109 |
while (cookie.charAt(0) == ' ') |
| 110 |
cookie = cookie.substring(1); |
| 111 |
if (cookie.indexOf(name) == 0) |
| 112 |
return cookie.substring(name.length, cookie.length); |
| 113 |
} |
| 114 |
return false; |
| 115 |
}, |
| 116 |
escape: function(str) { |
| 117 |
div = document.createElement('div'); |
| 118 |
div.appendChild(document.createTextNode(str)); |
| 119 |
return div.innerHTML; |
| 120 |
}, |
| 121 |
isNumeric: function(string) { |
| 122 |
return !isNaN(parseFloat(string)) && isFinite(string); |
| 123 |
}, |
| 124 |
} |
| 125 |
|
| 126 |
template = { |
| 127 |
|
| 128 |
addOptions: function(id, list) { |
| 129 |
var defaultMetric, defaultDimension, defaultView, output = []; |
| 130 |
|
| 131 |
if (!tools.getCookie('default_metric') || !tools.getCookie('default_dimension') || !tools.getCookie('default_swmetric')) { |
| 132 |
defaultMetric = 'sessions'; |
| 133 |
defaultDimension = '30daysAgo'; |
| 134 |
if (aiwpItemData.scope == 'front-item' || aiwpItemData.scope == 'admin-item') { |
| 135 |
swmetric = 'pageviews'; |
| 136 |
} else { |
| 137 |
swmetric = 'sessions'; |
| 138 |
} |
| 139 |
tools.setCookie('default_metric', defaultMetric); |
| 140 |
tools.setCookie('default_dimension', defaultDimension); |
| 141 |
tools.setCookie('default_swmetric', swmetric); |
| 142 |
} else { |
| 143 |
defaultMetric = tools.getCookie('default_metric'); |
| 144 |
defaultDimension = tools.getCookie('default_dimension'); |
| 145 |
defaultView = tools.getCookie('default_view'); |
| 146 |
swmetric = tools.getCookie('default_swmetric'); |
| 147 |
} |
| 148 |
|
| 149 |
if (list == false) { |
| 150 |
if (aiwpItemData.scope == 'front-item' || aiwpItemData.scope == 'admin-item') { |
| 151 |
output = ''; // Remove Sessions metric selection on item reports |
| 152 |
} else { |
| 153 |
output = '<span id="aiwp-swmetric-sessions" title="' + aiwpItemData.i18n[5] + '" class="dashicons dashicons-clock" style="font-size:22px;padding:4px;"></span>'; |
| 154 |
} |
| 155 |
|
| 156 |
output += '<span id="aiwp-swmetric-users" title="' + aiwpItemData.i18n[6] + '" class="dashicons dashicons-admin-users" style="font-size:22px;padding:4px;"></span>'; |
| 157 |
output += '<span id="aiwp-swmetric-pageviews" title="' + aiwpItemData.i18n[7] + '" class="dashicons dashicons-admin-page" style="font-size:22px;padding:4px;"></span>'; |
| 158 |
|
| 159 |
jQuery(id).html(output); |
| 160 |
|
| 161 |
jQuery('#aiwp-swmetric-' + swmetric).css("color", "#008ec2"); |
| 162 |
} else { |
| 163 |
jQuery.each(list, function(key, value) { |
| 164 |
if (key == defaultMetric || key == defaultDimension || key == defaultView) { |
| 165 |
output.push('<option value="' + key + '" selected="selected">' + value + '</option>'); |
| 166 |
} else { |
| 167 |
output.push('<option value="' + key + '">' + value + '</option>'); |
| 168 |
} |
| 169 |
}); |
| 170 |
jQuery(id).html(output.join('')); |
| 171 |
} |
| 172 |
}, |
| 173 |
|
| 174 |
init: function() { |
| 175 |
var tpl; |
| 176 |
|
| 177 |
if (!jQuery('#aiwp-window' + slug).length) { |
| 178 |
return; |
| 179 |
} |
| 180 |
|
| 181 |
if (jQuery('#aiwp-window' + slug).html().length) { // add main template once |
| 182 |
return; |
| 183 |
} |
| 184 |
|
| 185 |
tpl = '<div id="aiwp-container' + slug + '">'; |
| 186 |
if (aiwpItemData.viewList != false) { |
| 187 |
tpl += '<select id="aiwp-sel-view' + slug + '"></select>'; |
| 188 |
} |
| 189 |
tpl += '<select id="aiwp-sel-period' + slug + '"></select> '; |
| 190 |
tpl += '<select id="aiwp-sel-report' + slug + '"></select>'; |
| 191 |
tpl += '<div id="aiwp-sel-metric' + slug + '" style="float:right;display:none;">'; |
| 192 |
tpl += '</div>'; |
| 193 |
tpl += '<div id="aiwp-progressbar' + slug + '"></div>'; |
| 194 |
tpl += '<div id="aiwp-status' + slug + '"></div>'; |
| 195 |
tpl += '<div id="aiwp-reports' + slug + '"></div>'; |
| 196 |
tpl += '<div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;margin-top:10px;">'; |
| 197 |
tpl += aiwpItemData.i18n[14]; |
| 198 |
tpl += ' <a href="https://deconf.com/analytics-insights-google-analytics-dashboard-wordpress/?utm_source=aiwp_report&utm_medium=link&utm_content=backend-reports-widget&utm_campaign=aiwp" rel="nofollow" style="text-decoration:none;font-size:1em;">Analytics Insights</a> '; |
| 199 |
tpl += '</div>'; |
| 200 |
tpl += '</div>', |
| 201 |
|
| 202 |
jQuery('#aiwp-window' + slug).append(tpl); |
| 203 |
|
| 204 |
jQuery("#aiwp-reports" + slug).css({ |
| 205 |
"background-color": "#FFFFFF", |
| 206 |
"height": "auto", |
| 207 |
"margin-top": "0", |
| 208 |
"padding-top": "0", |
| 209 |
"padding-bottom": "0", |
| 210 |
"color": "#3c434a", |
| 211 |
"text-align": "inherit" |
| 212 |
}); |
| 213 |
|
| 214 |
template.addOptions('#aiwp-sel-view' + slug, aiwpItemData.viewList); |
| 215 |
template.addOptions('#aiwp-sel-period' + slug, aiwpItemData.dateList); |
| 216 |
template.addOptions('#aiwp-sel-report' + slug, aiwpItemData.reportList); |
| 217 |
template.addOptions('#aiwp-sel-metric' + slug, false); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
reports = { |
| 222 |
oldViewPort: 0, |
| 223 |
inProgress: 0, |
| 224 |
orgChartTableChartData: '', |
| 225 |
tableChartData: '', |
| 226 |
orgChartPieChartsData: '', |
| 227 |
geoChartTableChartData: '', |
| 228 |
areaChartBottomStatsData: '', |
| 229 |
realtime: '', |
| 230 |
rtRuns: null, |
| 231 |
i18n: null, |
| 232 |
|
| 233 |
getTitle: function(scope) { |
| 234 |
if (scope == 'admin-item') { |
| 235 |
return jQuery('#aiwp' + slug).attr("title"); |
| 236 |
} else { |
| 237 |
if (typeof document.getElementsByTagName("title")[0] === "undefined") { |
| 238 |
return ''; |
| 239 |
} else { |
| 240 |
return document.getElementsByTagName("title")[0].innerHTML; |
| 241 |
} |
| 242 |
} |
| 243 |
}, |
| 244 |
|
| 245 |
alertMessage: function(msg) { |
| 246 |
jQuery("#aiwp-status" + slug).css({ |
| 247 |
"margin-top": "3px", |
| 248 |
"padding-left": "5px", |
| 249 |
"height": "auto", |
| 250 |
"color": "#000", |
| 251 |
"border-left": "5px solid red" |
| 252 |
}); |
| 253 |
jQuery("#aiwp-status" + slug).html(msg); |
| 254 |
}, |
| 255 |
|
| 256 |
areaChartBottomStats: function(response) { |
| 257 |
|
| 258 |
var tpl; |
| 259 |
|
| 260 |
tpl = '<div id="aiwp-areachartbottomstats' + slug + '">'; |
| 261 |
tpl += '<div id="aiwp-areachart' + slug + '"></div>'; |
| 262 |
tpl += '<div id="aiwp-bottomstats' + slug + '">'; |
| 263 |
tpl += '<div class="inside">'; |
| 264 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[5] + '</h3><p id="aiwpsessions' + slug + '"> </p></div>'; |
| 265 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[6] + '</h3><p id="aiwpusers' + slug + '"> </p></div>'; |
| 266 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[7] + '</h3><p id="aiwppageviews' + slug + '"> </p></div>'; |
| 267 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[8] + '</h3><p id="aiwpbouncerate' + slug + '"> </p></div>'; |
| 268 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[9] + '</h3><p id="aiwporganicsearch' + slug + '"> </p></div>'; |
| 269 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[10] + '</h3><p id="aiwppagespervisit' + slug + '"> </p></div>'; |
| 270 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[26] + '</h3><p id="aiwppagetime' + slug + '"> </p></div>'; |
| 271 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[27] + '</h3><p id="aiwppageload' + slug + '"> </p></div>'; |
| 272 |
tpl += '<div class="small-box"><h3>' + aiwpItemData.i18n[28] + '</h3><p id="aiwpsessionduration' + slug + '"> </p></div>'; |
| 273 |
tpl += '</div>'; |
| 274 |
tpl += '</div>'; |
| 275 |
tpl += '</div>'; |
| 276 |
|
| 277 |
if (!jQuery('#aiwp-areachartbottomstats' + slug).length) { |
| 278 |
jQuery('#aiwp-reports' + slug).html(tpl); |
| 279 |
} |
| 280 |
|
| 281 |
jQuery('#aiwp-areachart' + slug).removeAttr("style"); |
| 282 |
|
| 283 |
jQuery('#aiwp-bottomstats' + slug).removeAttr("style"); |
| 284 |
|
| 285 |
jQuery('#aiwp-sel-metric' + slug).hide(); |
| 286 |
|
| 287 |
reports.areaChartBottomStatsData = response; |
| 288 |
|
| 289 |
if (Array.isArray(response)) { |
| 290 |
if (!tools.isNumeric(response[0])) { |
| 291 |
if (Array.isArray(response[0])) { |
| 292 |
jQuery('#aiwp-reports' + slug).show(); |
| 293 |
if (postData.query == 'visitBounceRate,bottomstats') { |
| 294 |
reports.drawAreaChart(response[0], true); |
| 295 |
} else { |
| 296 |
reports.drawAreaChart(response[0], false); |
| 297 |
} |
| 298 |
} else { |
| 299 |
reports.throwDebug(response[0]); |
| 300 |
} |
| 301 |
} else { |
| 302 |
jQuery('#aiwp-reports' + slug).show(); |
| 303 |
reports.throwError('#aiwp-areachart' + slug, response[0], "125px"); |
| 304 |
} |
| 305 |
if (!tools.isNumeric(response[1])) { |
| 306 |
if (Array.isArray(response[1])) { |
| 307 |
jQuery('#aiwp-reports' + slug).show(); |
| 308 |
reports.drawBottomStats(response[1]); |
| 309 |
} else { |
| 310 |
reports.throwDebug(response[1]); |
| 311 |
} |
| 312 |
} else { |
| 313 |
jQuery('#aiwp-reports' + slug).show(); |
| 314 |
reports.throwError('#aiwp-bottomstats' + slug, response[1], "40px"); |
| 315 |
} |
| 316 |
} else { |
| 317 |
reports.throwDebug(response); |
| 318 |
} |
| 319 |
NProgress.done(); |
| 320 |
|
| 321 |
}, |
| 322 |
|
| 323 |
orgChartPieCharts: function(response) { |
| 324 |
|
| 325 |
var tpl; |
| 326 |
var i = 0; |
| 327 |
|
| 328 |
tpl = '<div id="aiwp-orgchartpiecharts' + slug + '">'; |
| 329 |
tpl += '<div id="aiwp-orgchart' + slug + '"></div>'; |
| 330 |
tpl += '<div class="aiwp-floatwraper">'; |
| 331 |
tpl += '<div id="aiwp-piechart-1' + slug + '" class="halfsize floatleft"></div>'; |
| 332 |
tpl += '<div id="aiwp-piechart-2' + slug + '" class="halfsize floatright"></div>'; |
| 333 |
tpl += '</div>'; |
| 334 |
tpl += '<div class="aiwp-floatwraper">'; |
| 335 |
tpl += '<div id="aiwp-piechart-3' + slug + '" class="halfsize floatleft"></div>'; |
| 336 |
tpl += '<div id="aiwp-piechart-4' + slug + '" class="halfsize floatright"></div>'; |
| 337 |
tpl += '</div>'; |
| 338 |
tpl += '</div>'; |
| 339 |
|
| 340 |
jQuery('#aiwp-piechart-1' + slug).removeAttr("style"); |
| 341 |
jQuery('#aiwp-piechart-2' + slug).removeAttr("style"); |
| 342 |
jQuery('#aiwp-piechart-3' + slug).removeAttr("style"); |
| 343 |
jQuery('#aiwp-piechart-4' + slug).removeAttr("style"); |
| 344 |
|
| 345 |
if (!jQuery('#aiwp-orgchartpiecharts' + slug).length) { |
| 346 |
jQuery('#aiwp-reports' + slug).html(tpl); |
| 347 |
} |
| 348 |
|
| 349 |
jQuery('#aiwp-sel-metric' + slug).show(); |
| 350 |
|
| 351 |
reports.orgChartPieChartsData = response; |
| 352 |
if (Array.isArray(response)) { |
| 353 |
if (!tools.isNumeric(response[0])) { |
| 354 |
if (Array.isArray(response[0])) { |
| 355 |
jQuery('#aiwp-reports' + slug).show(); |
| 356 |
reports.drawOrgChart(response[0]); |
| 357 |
} else { |
| 358 |
reports.throwDebug(response[0]); |
| 359 |
} |
| 360 |
} else { |
| 361 |
jQuery('#aiwp-reports' + slug).show(); |
| 362 |
reports.throwError('#aiwp-orgchart' + slug, response[0], "125px"); |
| 363 |
} |
| 364 |
|
| 365 |
for (i = 1; i < response.length; i++) { |
| 366 |
if (!tools.isNumeric(response[i])) { |
| 367 |
if (Array.isArray(response[i])) { |
| 368 |
jQuery('#aiwp-reports' + slug).show(); |
| 369 |
reports.drawPieChart('piechart-' + i, response[i], reports.i18n[i]); |
| 370 |
} else { |
| 371 |
reports.throwDebug(response[i]); |
| 372 |
} |
| 373 |
} else { |
| 374 |
jQuery('#aiwp-reports' + slug).show(); |
| 375 |
reports.throwError('#aiwp-piechart-' + i + slug, response[i], "80px"); |
| 376 |
} |
| 377 |
} |
| 378 |
} else { |
| 379 |
reports.throwDebug(response); |
| 380 |
} |
| 381 |
NProgress.done(); |
| 382 |
}, |
| 383 |
|
| 384 |
geoChartTableChart: function(response) { |
| 385 |
|
| 386 |
var tpl; |
| 387 |
|
| 388 |
tpl = '<div id="aiwp-geocharttablechart' + slug + '">'; |
| 389 |
tpl += '<div id="aiwp-geochart' + slug + '"></div>'; |
| 390 |
tpl += '<div id="aiwp-dashboard' + slug + '">'; |
| 391 |
tpl += '<div id="aiwp-control' + slug + '"></div>'; |
| 392 |
tpl += '<div id="aiwp-tablechart' + slug + '"></div>'; |
| 393 |
tpl += '</div>'; |
| 394 |
tpl += '</div>'; |
| 395 |
|
| 396 |
if (!jQuery('#aiwp-geocharttablechart' + slug).length) { |
| 397 |
jQuery('#aiwp-reports' + slug).html(tpl); |
| 398 |
} |
| 399 |
|
| 400 |
jQuery('#aiwp-geochart' + slug).removeAttr("style"); |
| 401 |
|
| 402 |
jQuery('#aiwp-tablechart' + slug).removeAttr("style"); |
| 403 |
|
| 404 |
jQuery('#aiwp-sel-metric' + slug).show(); |
| 405 |
|
| 406 |
reports.geoChartTableChartData = response; |
| 407 |
if (Array.isArray(response)) { |
| 408 |
if (!tools.isNumeric(response[0])) { |
| 409 |
if (Array.isArray(response[0])) { |
| 410 |
jQuery('#aiwp-reports' + slug).show(); |
| 411 |
reports.drawGeoChart(response[0]); |
| 412 |
reports.drawTableChart(response[0]); |
| 413 |
} else { |
| 414 |
reports.throwDebug(response[0]); |
| 415 |
} |
| 416 |
} else { |
| 417 |
jQuery('#aiwp-reports' + slug).show(); |
| 418 |
reports.throwError('#aiwp-geochart' + slug, response[0], "125px"); |
| 419 |
reports.throwError('#aiwp-tablechart' + slug, response[0], "125px"); |
| 420 |
} |
| 421 |
} else { |
| 422 |
reports.throwDebug(response); |
| 423 |
} |
| 424 |
NProgress.done(); |
| 425 |
}, |
| 426 |
|
| 427 |
orgChartTableChart: function(response) { |
| 428 |
|
| 429 |
var tpl; |
| 430 |
|
| 431 |
tpl = '<div id="aiwp-orgcharttablechart' + slug + '">'; |
| 432 |
tpl += '<div id="aiwp-orgchart' + slug + '"></div>'; |
| 433 |
tpl += '<div id="aiwp-dashboard' + slug + '">'; |
| 434 |
tpl += '<div id="aiwp-control' + slug + '"></div>'; |
| 435 |
tpl += '<div id="aiwp-tablechart' + slug + '"></div>'; |
| 436 |
tpl += '</div>'; |
| 437 |
tpl += '</div>'; |
| 438 |
|
| 439 |
if (!jQuery('#aiwp-orgcharttablechart' + slug).length) { |
| 440 |
jQuery('#aiwp-reports' + slug).html(tpl); |
| 441 |
} |
| 442 |
|
| 443 |
jQuery('#aiwp-orgchart' + slug).removeAttr("style"); |
| 444 |
|
| 445 |
jQuery('#aiwp-tablechart' + slug).removeAttr("style"); |
| 446 |
|
| 447 |
jQuery('#aiwp-sel-metric' + slug).show(); |
| 448 |
|
| 449 |
reports.orgChartTableChartData = response |
| 450 |
if (Array.isArray(response)) { |
| 451 |
if (!tools.isNumeric(response[0])) { |
| 452 |
if (Array.isArray(response[0])) { |
| 453 |
jQuery('#aiwp-reports' + slug).show(); |
| 454 |
reports.drawOrgChart(response[0]); |
| 455 |
} else { |
| 456 |
reports.throwDebug(response[0]); |
| 457 |
} |
| 458 |
} else { |
| 459 |
jQuery('#aiwp-reports' + slug).show(); |
| 460 |
reports.throwError('#aiwp-orgchart' + slug, response[0], "125px"); |
| 461 |
} |
| 462 |
|
| 463 |
if (!tools.isNumeric(response[1])) { |
| 464 |
if (Array.isArray(response[1])) { |
| 465 |
reports.drawTableChart(response[1]); |
| 466 |
} else { |
| 467 |
reports.throwDebug(response[1]); |
| 468 |
} |
| 469 |
} else { |
| 470 |
reports.throwError('#aiwp-tablechart' + slug, response[1], "125px"); |
| 471 |
} |
| 472 |
} else { |
| 473 |
reports.throwDebug(response); |
| 474 |
} |
| 475 |
NProgress.done(); |
| 476 |
}, |
| 477 |
|
| 478 |
tableChart: function(response) { |
| 479 |
|
| 480 |
var tpl; |
| 481 |
|
| 482 |
tpl = '<div id="aiwp-404tablechart' + slug + '"><br>'; |
| 483 |
tpl += '<div id="aiwp-dashboard' + slug + '">'; |
| 484 |
tpl += '<div id="aiwp-control' + slug + '"></div>'; |
| 485 |
tpl += '<div id="aiwp-tablechart' + slug + '"></div>'; |
| 486 |
tpl += '</div>'; |
| 487 |
|
| 488 |
if (!jQuery('#aiwp-404tablechart' + slug).length) { |
| 489 |
jQuery('#aiwp-reports' + slug).html(tpl); |
| 490 |
} |
| 491 |
|
| 492 |
jQuery('#aiwp-404tablechart' + slug).removeAttr("style"); |
| 493 |
|
| 494 |
jQuery('#aiwp-tablechart' + slug).removeAttr("style"); |
| 495 |
|
| 496 |
jQuery('#aiwp-sel-metric' + slug).show(); |
| 497 |
|
| 498 |
reports.tableChartData = response |
| 499 |
if (Array.isArray(response)) { |
| 500 |
if (!tools.isNumeric(response[0])) { |
| 501 |
if (Array.isArray(response[0])) { |
| 502 |
jQuery('#aiwp-reports' + slug).show(); |
| 503 |
reports.drawTableChart(response[0]); |
| 504 |
} else { |
| 505 |
reports.throwDebug(response[0]); |
| 506 |
} |
| 507 |
} else { |
| 508 |
jQuery('#aiwp-reports' + slug).show(); |
| 509 |
reports.throwError('#aiwp-tablechart' + slug, response[0], "125px"); |
| 510 |
} |
| 511 |
} else { |
| 512 |
reports.throwDebug(response); |
| 513 |
} |
| 514 |
NProgress.done(); |
| 515 |
}, |
| 516 |
|
| 517 |
drawTableChart: function(data) { |
| 518 |
var chartData, options, chart, dashboard, control, wrapper; |
| 519 |
|
| 520 |
chartData = google.visualization.arrayToDataTable(data); |
| 521 |
options = { |
| 522 |
page: 'enable', |
| 523 |
pageSize: 10, |
| 524 |
width: '100%', |
| 525 |
allowHtml: true, |
| 526 |
sortColumn: 1, |
| 527 |
sortAscending: false |
| 528 |
}; |
| 529 |
|
| 530 |
dashboard = new google.visualization.Dashboard(document.getElementById('aiwp-dashboard' + slug)); |
| 531 |
|
| 532 |
control = new google.visualization.ControlWrapper({ |
| 533 |
controlType: 'StringFilter', |
| 534 |
containerId: 'aiwp-control' + slug, |
| 535 |
options: { |
| 536 |
filterColumnIndex: 0, |
| 537 |
matchType: 'any', |
| 538 |
ui: { label: '', cssClass: 'aiwp-dashboard-control' }, |
| 539 |
} |
| 540 |
}); |
| 541 |
|
| 542 |
google.visualization.events.addListener(control, 'ready', function() { |
| 543 |
jQuery('.aiwp-dashboard-control input').prop('placeholder', aiwpItemData.i18n[31]); |
| 544 |
}); |
| 545 |
|
| 546 |
wrapper = new google.visualization.ChartWrapper({ |
| 547 |
'chartType': 'Table', |
| 548 |
'containerId': 'aiwp-tablechart' + slug, |
| 549 |
'options': options, |
| 550 |
}); |
| 551 |
|
| 552 |
dashboard.bind(control, wrapper); |
| 553 |
|
| 554 |
dashboard.draw(chartData); |
| 555 |
|
| 556 |
// outputs selection |
| 557 |
google.visualization.events.addListener(wrapper, 'select', function() { |
| 558 |
console.log(wrapper.getDataTable().getValue(wrapper.getChart().getSelection()[0].row, 0)); |
| 559 |
}); |
| 560 |
|
| 561 |
}, |
| 562 |
|
| 563 |
drawOrgChart: function(data) { |
| 564 |
var chartData, options, chart; |
| 565 |
|
| 566 |
chartData = google.visualization.arrayToDataTable(data); |
| 567 |
options = { |
| 568 |
allowCollapse: true, |
| 569 |
allowHtml: true, |
| 570 |
height: '100%' |
| 571 |
}; |
| 572 |
chart = new google.visualization.OrgChart(document.getElementById('aiwp-orgchart' + slug)); |
| 573 |
|
| 574 |
chart.draw(chartData, options); |
| 575 |
}, |
| 576 |
|
| 577 |
drawPieChart: function(id, data, title) { |
| 578 |
var chartData, options, chart; |
| 579 |
|
| 580 |
chartData = google.visualization.arrayToDataTable(data); |
| 581 |
options = { |
| 582 |
is3D: false, |
| 583 |
tooltipText: 'percentage', |
| 584 |
legend: 'none', |
| 585 |
chartArea: { |
| 586 |
width: '99%', |
| 587 |
height: '80%' |
| 588 |
}, |
| 589 |
title: title, |
| 590 |
pieSliceText: 'value', |
| 591 |
colors: aiwpItemData.colorVariations |
| 592 |
}; |
| 593 |
chart = new google.visualization.PieChart(document.getElementById('aiwp-' + id + slug)); |
| 594 |
|
| 595 |
chart.draw(chartData, options); |
| 596 |
}, |
| 597 |
|
| 598 |
drawGeoChart: function(data) { |
| 599 |
var chartData, options, chart; |
| 600 |
|
| 601 |
chartData = google.visualization.arrayToDataTable(data); |
| 602 |
options = { |
| 603 |
chartArea: { |
| 604 |
width: '99%', |
| 605 |
height: '90%' |
| 606 |
}, |
| 607 |
colors: [aiwpItemData.colorVariations[5], aiwpItemData.colorVariations[4]] |
| 608 |
} |
| 609 |
if (aiwpItemData.region) { |
| 610 |
options.region = aiwpItemData.region; |
| 611 |
options.displayMode = 'markers'; |
| 612 |
options.datalessRegionColor = 'EFEFEF'; |
| 613 |
} |
| 614 |
chart = new google.visualization.GeoChart(document.getElementById('aiwp-geochart' + slug)); |
| 615 |
|
| 616 |
chart.draw(chartData, options); |
| 617 |
}, |
| 618 |
|
| 619 |
drawAreaChart: function(data, format) { |
| 620 |
var chartData, options, chart, formatter; |
| 621 |
|
| 622 |
jQuery('#aiwp-sel-metric' + slug).hide(); |
| 623 |
|
| 624 |
chartData = google.visualization.arrayToDataTable(data); |
| 625 |
|
| 626 |
if (format) { |
| 627 |
formatter = new google.visualization.NumberFormat({ |
| 628 |
suffix: '%', |
| 629 |
fractionDigits: 2 |
| 630 |
}); |
| 631 |
|
| 632 |
formatter.format(chartData, 1); |
| 633 |
} |
| 634 |
|
| 635 |
options = { |
| 636 |
legend: { |
| 637 |
position: 'none' |
| 638 |
}, |
| 639 |
pointSize: 3, |
| 640 |
colors: [aiwpItemData.colorVariations[0], aiwpItemData.colorVariations[4]], |
| 641 |
chartArea: { |
| 642 |
width: '99%', |
| 643 |
height: '90%' |
| 644 |
}, |
| 645 |
vAxis: { |
| 646 |
textPosition: "in", |
| 647 |
minValue: 0 |
| 648 |
}, |
| 649 |
hAxis: { |
| 650 |
textPosition: 'none' |
| 651 |
} |
| 652 |
}; |
| 653 |
chart = new google.visualization.AreaChart(document.getElementById('aiwp-areachart' + slug)); |
| 654 |
|
| 655 |
chart.draw(chartData, options); |
| 656 |
}, |
| 657 |
|
| 658 |
drawBottomStats: function(data) { |
| 659 |
jQuery("#aiwpsessions" + slug).html(data[0]); |
| 660 |
jQuery("#aiwpusers" + slug).html(data[1]); |
| 661 |
jQuery("#aiwppageviews" + slug).html(data[2]); |
| 662 |
jQuery("#aiwpbouncerate" + slug).html(data[3]); |
| 663 |
jQuery("#aiwporganicsearch" + slug).html(data[4]); |
| 664 |
jQuery("#aiwppagespervisit" + slug).html(data[5]); |
| 665 |
jQuery("#aiwppagetime" + slug).html(data[6]); |
| 666 |
jQuery("#aiwppageload" + slug).html(data[7]); |
| 667 |
jQuery("#aiwpsessionduration" + slug).html(data[8]); |
| 668 |
}, |
| 669 |
|
| 670 |
rtOnlyUniqueValues: function(value, index, self) { |
| 671 |
return self.indexOf(value) === index; |
| 672 |
}, |
| 673 |
|
| 674 |
rtCountSessions: function(rtData, searchValue, index) { |
| 675 |
var count = 0, i = 0; |
| 676 |
|
| 677 |
for (i = 0; i < rtData["rows"].length; i++) { |
| 678 |
if (jQuery.inArray(searchValue, rtData["rows"][i]) > -1) { |
| 679 |
count += parseInt(rtData["rows"][i][index]); |
| 680 |
} |
| 681 |
} |
| 682 |
return count; |
| 683 |
}, |
| 684 |
|
| 685 |
rtGenerateTooltip: function(rtData) { |
| 686 |
var count = 0, table = "", i = 0; |
| 687 |
|
| 688 |
for (i = 0; i < rtData.length; i++) { |
| 689 |
count += parseInt(rtData[i].count); |
| 690 |
table += "<tr><td class='aiwp-pgdetailsl'>" + rtData[i].value + "</td><td class='aiwp-pgdetailsr'>" + rtData[i].count + "</td></tr>"; |
| 691 |
} |
| 692 |
; |
| 693 |
if (count) { |
| 694 |
return ("<table>" + table + "</table>"); |
| 695 |
} else { |
| 696 |
return (""); |
| 697 |
} |
| 698 |
}, |
| 699 |
|
| 700 |
rtPageDetails: function(rtData, searchValue) { |
| 701 |
var sant, pageTitle, pgStatsTable, i = 0, j = 0, sum = 0, newsum = 0, countrfr = 0, countkwd = 0, countdrt = 0, countscl = 0, countcpg = 0, tablerfr = "", tablekwd = "", tablescl = "", tablecpg = "", tabledrt = ""; |
| 702 |
|
| 703 |
rtData = rtData["rows"]; |
| 704 |
|
| 705 |
for (i = 0; i < rtData.length; i++) { |
| 706 |
|
| 707 |
if (rtData[i][0] == searchValue) { |
| 708 |
pageTitle = rtData[i][5]; |
| 709 |
|
| 710 |
switch (rtData[i][3]) { |
| 711 |
|
| 712 |
case "REFERRAL": |
| 713 |
countrfr += parseInt(rtData[i][6]); |
| 714 |
tablerfr += "<tr><td class='aiwp-pgdetailsl'>" + rtData[i][1] + "</td><td class='aiwp-pgdetailsr'>" + rtData[i][6] + "</td></tr>"; |
| 715 |
break; |
| 716 |
case "ORGANIC": |
| 717 |
countkwd += parseInt(rtData[i][6]); |
| 718 |
tablekwd += "<tr><td class='aiwp-pgdetailsl'>" + rtData[i][2] + "</td><td class='aiwp-pgdetailsr'>" + rtData[i][6] + "</td></tr>"; |
| 719 |
break; |
| 720 |
case "SOCIAL": |
| 721 |
countscl += parseInt(rtData[i][6]); |
| 722 |
tablescl += "<tr><td class='aiwp-pgdetailsl'>" + rtData[i][1] + "</td><td class='aiwp-pgdetailsr'>" + rtData[i][6] + "</td></tr>"; |
| 723 |
break; |
| 724 |
case "CUSTOM": |
| 725 |
countcpg += parseInt(rtData[i][6]); |
| 726 |
tablecpg += "<tr><td class='aiwp-pgdetailsl'>" + rtData[i][1] + "</td><td class='aiwp-pgdetailsr'>" + rtData[i][6] + "</td></tr>"; |
| 727 |
break; |
| 728 |
case "DIRECT": |
| 729 |
countdrt += parseInt(rtData[i][6]); |
| 730 |
break; |
| 731 |
} |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
if (countrfr) { |
| 736 |
tablerfr = "<table><tr><td>" + reports.i18n[0] + "(" + countrfr + ")</td></tr>" + tablerfr + "</table><br />"; |
| 737 |
} |
| 738 |
if (countkwd) { |
| 739 |
tablekwd = "<table><tr><td>" + reports.i18n[1] + "(" + countkwd + ")</td></tr>" + tablekwd + "</table><br />"; |
| 740 |
} |
| 741 |
if (countscl) { |
| 742 |
tablescl = "<table><tr><td>" + reports.i18n[2] + "(" + countscl + ")</td></tr>" + tablescl + "</table><br />"; |
| 743 |
} |
| 744 |
if (countcpg) { |
| 745 |
tablecpg = "<table><tr><td>" + reports.i18n[3] + "(" + countcpg + ")</td></tr>" + tablecpg + "</table><br />"; |
| 746 |
} |
| 747 |
if (countdrt) { |
| 748 |
tabledrt = "<table><tr><td>" + reports.i18n[4] + "(" + countdrt + ")</td></tr></table><br />"; |
| 749 |
} |
| 750 |
return ("<p><center><strong>" + pageTitle + "</strong></center></p>" + tablerfr + tablekwd + tablescl + tablecpg + tabledrt); |
| 751 |
}, |
| 752 |
|
| 753 |
rtRefresh: function() { |
| 754 |
if (reports.render.focusFlag) { |
| 755 |
postData.from = false; |
| 756 |
postData.to = false; |
| 757 |
postData.query = 'realtime'; |
| 758 |
jQuery.post(aiwpItemData.ajaxurl, postData, function(response) { |
| 759 |
if (Array.isArray(response)) { |
| 760 |
jQuery('#aiwp-reports' + slug).show(); |
| 761 |
reports.realtime = response[0]; |
| 762 |
reports.drawRealtimeGA4(reports.realtime); |
| 763 |
} else { |
| 764 |
reports.throwDebug(response); |
| 765 |
} |
| 766 |
|
| 767 |
NProgress.done(); |
| 768 |
|
| 769 |
}); |
| 770 |
} |
| 771 |
}, |
| 772 |
|
| 773 |
|
| 774 |
drawRealtimeGA4: function(rtData) { |
| 775 |
|
| 776 |
var rtInfoRight, pgStatsTable, i, uScreenName, desktopCount = 0, mobileCount = 0, tabletCount = 0, screenName = [], uScreenNameStats = []; |
| 777 |
|
| 778 |
jQuery(function() { |
| 779 |
jQuery('#aiwp-widget *').tooltip({ |
| 780 |
tooltipClass: "aiwp" |
| 781 |
}); |
| 782 |
}); |
| 783 |
|
| 784 |
if (tools.isNumeric(rtData) || typeof rtData === "undefined") { |
| 785 |
rtData = []; |
| 786 |
rtData["totals"] = "0"; |
| 787 |
rtData["rows"] = []; |
| 788 |
rtData["category"] = []; |
| 789 |
} |
| 790 |
|
| 791 |
desktopCount = 0; |
| 792 |
mobileCount = 0; |
| 793 |
tabletCount = 0; |
| 794 |
|
| 795 |
for (i = 0; i < rtData["category"].length; i++) { |
| 796 |
|
| 797 |
screenName.push(rtData["category"][i][0]); |
| 798 |
|
| 799 |
if (rtData["category"][i][0] == "desktop") { |
| 800 |
desktopCount = desktopCount + parseInt(rtData["category"][i][1]); |
| 801 |
} |
| 802 |
if (rtData["category"][i][0] == "mobile") { |
| 803 |
mobileCount = mobileCount + parseInt(rtData["category"][i][1]); |
| 804 |
} |
| 805 |
if (rtData["category"][i][0] == "tablet") { |
| 806 |
tabletCount = tabletCount + parseInt(rtData["category"][i][1]); |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
rtData["totals"] = desktopCount + mobileCount + tabletCount; |
| 811 |
|
| 812 |
if (parseInt(rtData["totals"]) !== parseInt(document.getElementById("aiwp-online-ga4").innerHTML)) { |
| 813 |
jQuery("#aiwp-online-ga4").fadeOut("slow"); |
| 814 |
jQuery("#aiwp-online-ga4").fadeOut(500); |
| 815 |
jQuery("#aiwp-online-ga4").fadeOut("slow", function() { |
| 816 |
if ((parseInt(rtData["totals"])) < (parseInt(document.getElementById("aiwp-online-ga4").innerHTML))) { |
| 817 |
jQuery("#aiwp-online-ga4").css({ |
| 818 |
'background-color': '#FFE8E8' |
| 819 |
}); |
| 820 |
} else { |
| 821 |
jQuery("#aiwp-online-ga4").css({ |
| 822 |
'background-color': '#E0FFEC' |
| 823 |
}); |
| 824 |
} |
| 825 |
document.getElementById("aiwp-online-ga4").innerHTML = rtData["totals"]; |
| 826 |
}); |
| 827 |
jQuery("#aiwp-online-ga4").fadeIn("slow"); |
| 828 |
jQuery("#aiwp-online-ga4").fadeIn(500); |
| 829 |
jQuery("#aiwp-online-ga4").fadeIn("slow", function() { |
| 830 |
jQuery("#aiwp-online-ga4").css({ |
| 831 |
'background-color': '#FFFFFF' |
| 832 |
}); |
| 833 |
}); |
| 834 |
} |
| 835 |
|
| 836 |
if (rtData["totals"] == 0) { |
| 837 |
rtData["rows"] = []; |
| 838 |
} |
| 839 |
|
| 840 |
for (i = 0; i < rtData["rows"].length; i++) { |
| 841 |
uScreenNameStats[i] = { |
| 842 |
"screenName": rtData["rows"][i][0], |
| 843 |
"count": rtData["rows"][i][1] |
| 844 |
} |
| 845 |
} |
| 846 |
uScreenNameStats.sort(function(a, b) { |
| 847 |
return b.count - a.count |
| 848 |
}); |
| 849 |
|
| 850 |
pgStatsTable = ""; |
| 851 |
for (i = 0; i < uScreenNameStats.length; i++) { |
| 852 |
if (i < aiwpItemData.rtLimitPages) { |
| 853 |
pgStatsTable += '<div class="aiwp-pline"><div class="aiwp-pleft">' + uScreenNameStats[i].screenName.substring(0, 70) + '</div><div class="aiwp-pright">' + uScreenNameStats[i].count + '</div></div>'; |
| 854 |
} |
| 855 |
} |
| 856 |
document.getElementById("aiwp-pages").innerHTML = '<br /><div class="aiwp-pg">' + pgStatsTable + '</div>'; |
| 857 |
|
| 858 |
rtInfoRight = '<div class="aiwp-bigtext-ga4"><div class="aiwp-bleft-ga4"><span class="dashicons dashicons-desktop"></span> ' + reports.i18n[12] + '</div><div class="aiwp-bright-ga4">' + desktopCount + '</div></div>'; |
| 859 |
rtInfoRight += '<div class="aiwp-bigtext-ga4"><div class="aiwp-bleft-ga4"><span class="dashicons dashicons-smartphone"></span> ' + reports.i18n[13] + '</div><div class="aiwp-bright-ga4">' + mobileCount + '</div></div>'; |
| 860 |
rtInfoRight += '<div class="aiwp-bigtext-ga4"><div class="aiwp-bleft-ga4"><span class="dashicons dashicons-tablet"></span> ' + reports.i18n[14] + '</div><div class="aiwp-bright-ga4">' + tabletCount + '</div></div>'; |
| 861 |
|
| 862 |
document.getElementById("aiwp-tdo-right-ga4").innerHTML = rtInfoRight; |
| 863 |
}, |
| 864 |
|
| 865 |
throwDebug: function(response) { |
| 866 |
jQuery("#aiwp-status" + slug).css({ |
| 867 |
"margin-top": "3px", |
| 868 |
"padding-left": "5px", |
| 869 |
"height": "auto", |
| 870 |
"color": "#000", |
| 871 |
"border-left": "5px solid red" |
| 872 |
}); |
| 873 |
if (response == '-24') { |
| 874 |
jQuery("#aiwp-status" + slug).html(aiwpItemData.i18n[15]); |
| 875 |
} else { |
| 876 |
jQuery("#aiwp-reports" + slug).css({ |
| 877 |
"background-color": "#F7F7F7", |
| 878 |
"height": "auto", |
| 879 |
"margin-top": "10px", |
| 880 |
"padding-top": "50px", |
| 881 |
"padding-bottom": "50px", |
| 882 |
"color": "#000", |
| 883 |
"text-align": "center" |
| 884 |
}); |
| 885 |
jQuery("#aiwp-reports" + slug).html(response); |
| 886 |
jQuery("#aiwp-reports" + slug).show(); |
| 887 |
jQuery("#aiwp-status" + slug).html(aiwpItemData.i18n[11]); |
| 888 |
console.log("\n********************* AIWP Log ********************* \n\n" + response); |
| 889 |
if (response) { |
| 890 |
postData = { |
| 891 |
action: 'aiwp_set_error', |
| 892 |
response: response, |
| 893 |
aiwp_security_set_error: aiwpItemData.security, |
| 894 |
} |
| 895 |
jQuery.post(aiwpItemData.ajaxurl, postData); |
| 896 |
} |
| 897 |
} |
| 898 |
}, |
| 899 |
|
| 900 |
throwError: function(target, response, p) { |
| 901 |
jQuery(target).css({ |
| 902 |
"background-color": "#F7F7F7", |
| 903 |
"height": "auto", |
| 904 |
"padding-top": p, |
| 905 |
"padding-bottom": p, |
| 906 |
"color": "#000", |
| 907 |
"text-align": "center" |
| 908 |
}); |
| 909 |
if (response == 621) { |
| 910 |
jQuery(target).html('<p><span style="font-size:4em;color:#778899;margin-left:-20px;" class="dashicons dashicons-clock"></span></p><br><p style="font-size:1.1em;color:#778899;">' + aiwpItemData.i18n[13] + '</p>'); |
| 911 |
} else { |
| 912 |
jQuery(target).html(aiwpItemData.i18n[12] + ' ' + response); |
| 913 |
} |
| 914 |
}, |
| 915 |
|
| 916 |
render: function(view, period, query) { |
| 917 |
var projectId, from, to, tpl, focusFlag; |
| 918 |
|
| 919 |
if (period == 'realtime') { |
| 920 |
jQuery('#aiwp-sel-report' + slug).hide(); |
| 921 |
} else { |
| 922 |
jQuery('#aiwp-sel-report' + slug).show(); |
| 923 |
clearInterval(reports.rtRuns); |
| 924 |
} |
| 925 |
|
| 926 |
jQuery('#aiwp-status' + slug).html(''); |
| 927 |
switch (period) { |
| 928 |
case 'today': |
| 929 |
from = 'today'; |
| 930 |
to = 'today'; |
| 931 |
break; |
| 932 |
case 'yesterday': |
| 933 |
from = 'yesterday'; |
| 934 |
to = 'yesterday'; |
| 935 |
break; |
| 936 |
case '7daysAgo': |
| 937 |
from = '7daysAgo'; |
| 938 |
to = 'yesterday'; |
| 939 |
break; |
| 940 |
case '14daysAgo': |
| 941 |
from = '14daysAgo'; |
| 942 |
to = 'yesterday'; |
| 943 |
break; |
| 944 |
case '90daysAgo': |
| 945 |
from = '90daysAgo'; |
| 946 |
to = 'yesterday'; |
| 947 |
break; |
| 948 |
case '365daysAgo': |
| 949 |
from = '365daysAgo'; |
| 950 |
to = 'yesterday'; |
| 951 |
break; |
| 952 |
case '1095daysAgo': |
| 953 |
from = '1095daysAgo'; |
| 954 |
to = 'yesterday'; |
| 955 |
break; |
| 956 |
default: |
| 957 |
from = '30daysAgo'; |
| 958 |
to = 'yesterday'; |
| 959 |
break; |
| 960 |
} |
| 961 |
|
| 962 |
tools.setCookie('default_metric', query); |
| 963 |
tools.setCookie('default_dimension', period); |
| 964 |
|
| 965 |
if (typeof view !== 'undefined') { |
| 966 |
tools.setCookie('default_view', view); |
| 967 |
projectId = view; |
| 968 |
} else { |
| 969 |
projectId = false; |
| 970 |
} |
| 971 |
|
| 972 |
if (aiwpItemData.scope == 'admin-item') { |
| 973 |
postData = { |
| 974 |
action: 'aiwp_backend_item_reports', |
| 975 |
aiwp_security_backend_item_reports: aiwpItemData.security, |
| 976 |
from: from, |
| 977 |
to: to, |
| 978 |
filter: itemId |
| 979 |
} |
| 980 |
} else if (aiwpItemData.scope == 'front-item') { |
| 981 |
postData = { |
| 982 |
action: 'aiwp_frontend_item_reports', |
| 983 |
aiwp_security_frontend_item_reports: aiwpItemData.security, |
| 984 |
from: from, |
| 985 |
to: to, |
| 986 |
filter: aiwpItemData.filter |
| 987 |
} |
| 988 |
} else { |
| 989 |
postData = { |
| 990 |
action: 'aiwp_backend_item_reports', |
| 991 |
aiwp_security_backend_item_reports: aiwpItemData.security, |
| 992 |
projectId: projectId, |
| 993 |
from: from, |
| 994 |
to: to |
| 995 |
} |
| 996 |
} |
| 997 |
if (period == 'realtime') { |
| 998 |
|
| 999 |
reports.i18n = aiwpItemData.i18n.slice(20, 36); |
| 1000 |
|
| 1001 |
reports.render.focusFlag = 1; |
| 1002 |
|
| 1003 |
jQuery('#aiwp-sel-metric' + slug).hide(); |
| 1004 |
|
| 1005 |
jQuery(window).on("focus", function(event) { |
| 1006 |
reports.render.focusFlag = 1; |
| 1007 |
}).on("blur", function(event) { |
| 1008 |
reports.render.focusFlag = 0; |
| 1009 |
}); |
| 1010 |
|
| 1011 |
tpl = '<div id="aiwp-realtime' + slug + '">'; |
| 1012 |
tpl += '<div class="aiwp-rt-box">'; |
| 1013 |
tpl += '<div class="aiwp-rt-title">' + reports.i18n[15] + '</div>'; |
| 1014 |
tpl += '<div class="aiwp-tdo-left-ga4">'; |
| 1015 |
tpl += '<div class="aiwp-online-ga4" id="aiwp-online-ga4">0</div>'; |
| 1016 |
tpl += '</div>'; |
| 1017 |
tpl += '<div class="aiwp-tdo-right-ga4" id="aiwp-tdo-right-ga4">'; |
| 1018 |
tpl += '<div class="aiwp-bigtext-ga4">'; |
| 1019 |
tpl += '<div class="aiwp-bleft-ga4"><span class="dashicons dashicons-desktop"></span> ' + reports.i18n[12] + '</div>'; |
| 1020 |
tpl += '<div class="aiwp-bright-ga4">0</div>'; |
| 1021 |
tpl += '</div>'; |
| 1022 |
tpl += '<div class="aiwp-bigtext-ga4">'; |
| 1023 |
tpl += '<div class="aiwp-bleft-ga4"><span class="dashicons dashicons-smartphone"></span> ' + reports.i18n[13] + '</div>'; |
| 1024 |
tpl += '<div class="aiwp-bright-ga4">0</div>'; |
| 1025 |
tpl += '</div>'; |
| 1026 |
tpl += '<div class="aiwp-bigtext-ga4">'; |
| 1027 |
tpl += '<div class="aiwp-bleft-ga4"><span class="dashicons dashicons-tablet"></span> ' + reports.i18n[14] + '</div>'; |
| 1028 |
tpl += '<div class="aiwp-bright-ga4">0</div>'; |
| 1029 |
tpl += '</div>'; |
| 1030 |
tpl += '</div>'; |
| 1031 |
tpl += '</div>'; |
| 1032 |
tpl += '<div>'; |
| 1033 |
tpl += '<div id="aiwp-pages" class="aiwp-pages"> </div>'; |
| 1034 |
tpl += '</div>'; |
| 1035 |
tpl += '</div>'; |
| 1036 |
|
| 1037 |
|
| 1038 |
jQuery('#aiwp-reports' + slug).html(tpl); |
| 1039 |
|
| 1040 |
reports.rtRefresh(reports.render.focusFlag); |
| 1041 |
|
| 1042 |
reports.rtRuns = setInterval(reports.rtRefresh, 40000); |
| 1043 |
|
| 1044 |
} else { |
| 1045 |
if (jQuery.inArray(query, ['referrers', 'contentpages', 'searches']) > -1) { |
| 1046 |
|
| 1047 |
postData.query = 'channelGrouping,' + query; |
| 1048 |
postData.metric = swmetric; |
| 1049 |
|
| 1050 |
jQuery.post(aiwpItemData.ajaxurl, postData, function(response) { |
| 1051 |
reports.orgChartTableChart(response); |
| 1052 |
}); |
| 1053 |
} else if (query == '404errors') { |
| 1054 |
|
| 1055 |
postData.query = query; |
| 1056 |
postData.metric = swmetric; |
| 1057 |
|
| 1058 |
jQuery.post(aiwpItemData.ajaxurl, postData, function(response) { |
| 1059 |
reports.tableChart(response); |
| 1060 |
}); |
| 1061 |
} else if (query == 'trafficdetails' || query == 'technologydetails') { |
| 1062 |
|
| 1063 |
if (query == 'trafficdetails') { |
| 1064 |
postData.query = 'channelGrouping,medium,visitorType,source,socialNetwork'; |
| 1065 |
reports.i18n = aiwpItemData.i18n.slice(0, 5); |
| 1066 |
} else { |
| 1067 |
reports.i18n = aiwpItemData.i18n.slice(15, 20); |
| 1068 |
postData.query = 'deviceCategory,browser,operatingSystem,screenResolution,mobileDeviceBranding'; |
| 1069 |
} |
| 1070 |
postData.metric = swmetric; |
| 1071 |
|
| 1072 |
jQuery.post(aiwpItemData.ajaxurl, postData, function(response) { |
| 1073 |
reports.orgChartPieCharts(response) |
| 1074 |
}); |
| 1075 |
|
| 1076 |
} else if (query == 'locations') { |
| 1077 |
|
| 1078 |
postData.query = query; |
| 1079 |
postData.metric = swmetric; |
| 1080 |
|
| 1081 |
jQuery.post(aiwpItemData.ajaxurl, postData, function(response) { |
| 1082 |
reports.geoChartTableChart(response); |
| 1083 |
}); |
| 1084 |
|
| 1085 |
} else { |
| 1086 |
|
| 1087 |
postData.query = query + ',bottomstats'; |
| 1088 |
|
| 1089 |
jQuery.post(aiwpItemData.ajaxurl, postData, function(response) { |
| 1090 |
reports.areaChartBottomStats(response); |
| 1091 |
}); |
| 1092 |
|
| 1093 |
} |
| 1094 |
|
| 1095 |
} |
| 1096 |
|
| 1097 |
}, |
| 1098 |
|
| 1099 |
refresh: function() { |
| 1100 |
if (jQuery('#aiwp-areachartbottomstats' + slug).length > 0 && Array.isArray(reports.areaChartBottomStatsData)) { |
| 1101 |
reports.areaChartBottomStats(reports.areaChartBottomStatsData); |
| 1102 |
} |
| 1103 |
if (jQuery('#aiwp-orgchartpiecharts' + slug).length > 0 && Array.isArray(reports.orgChartPieChartsData)) { |
| 1104 |
reports.orgChartPieCharts(reports.orgChartPieChartsData); |
| 1105 |
} |
| 1106 |
if (jQuery('#aiwp-geocharttablechart' + slug).length > 0 && Array.isArray(reports.geoChartTableChartData)) { |
| 1107 |
reports.geoChartTableChart(reports.geoChartTableChartData); |
| 1108 |
} |
| 1109 |
if (jQuery('#aiwp-orgcharttablechart' + slug).length > 0 && Array.isArray(reports.orgChartTableChartData)) { |
| 1110 |
reports.orgChartTableChart(reports.orgChartTableChartData); |
| 1111 |
} |
| 1112 |
if (jQuery('#aiwp-404tablechart' + slug).length > 0 && Array.isArray(reports.tableChartData)) { |
| 1113 |
reports.tableChart(reports.tableChartData); |
| 1114 |
} |
| 1115 |
}, |
| 1116 |
|
| 1117 |
init: function() { |
| 1118 |
|
| 1119 |
|
| 1120 |
if (!reports.inProgress) { |
| 1121 |
|
| 1122 |
reports.inProgress = 1; |
| 1123 |
|
| 1124 |
try { |
| 1125 |
NProgress.configure({ |
| 1126 |
parent: "#aiwp-progressbar" + slug, |
| 1127 |
showSpinner: false |
| 1128 |
}); |
| 1129 |
NProgress.start(); |
| 1130 |
} catch (e) { |
| 1131 |
reports.alertMessage(aiwpItemData.i18n[0]); |
| 1132 |
} |
| 1133 |
|
| 1134 |
reports.render(jQuery('#aiwp-sel-view' + slug).val(), jQuery('#aiwp-sel-period' + slug).val(), jQuery('#aiwp-sel-report' + slug).val()); |
| 1135 |
|
| 1136 |
jQuery(window).on("resize", function() { |
| 1137 |
var diff = jQuery(window).width() - reports.oldViewPort; |
| 1138 |
if ((diff < -5) || (diff > 5)) { |
| 1139 |
reports.oldViewPort = jQuery(window).width(); |
| 1140 |
reports.refresh(); // refresh only on over 5px viewport width changes |
| 1141 |
} |
| 1142 |
}); |
| 1143 |
|
| 1144 |
reports.inProgress = 0; |
| 1145 |
|
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
|
| 1150 |
template.init(); |
| 1151 |
|
| 1152 |
reports.init(); |
| 1153 |
|
| 1154 |
jQuery('#aiwp-sel-view' + slug).on("change", function() { |
| 1155 |
reports.init(); |
| 1156 |
}); |
| 1157 |
|
| 1158 |
jQuery('#aiwp-sel-period' + slug).on("change", function() { |
| 1159 |
reports.init(); |
| 1160 |
}); |
| 1161 |
|
| 1162 |
jQuery('#aiwp-sel-report' + slug).on("change", function() { |
| 1163 |
reports.init(); |
| 1164 |
}); |
| 1165 |
|
| 1166 |
jQuery('[id^=aiwp-swmetric-]').on("click", function() { |
| 1167 |
swmetric = this.id.replace('aiwp-swmetric-', ''); |
| 1168 |
tools.setCookie('default_swmetric', swmetric); |
| 1169 |
jQuery('#aiwp-swmetric-sessions').css("color", "#444"); |
| 1170 |
jQuery('#aiwp-swmetric-users').css("color", "#444"); |
| 1171 |
jQuery('#aiwp-swmetric-pageviews').css("color", "#444"); |
| 1172 |
jQuery('#' + this.id).css("color", "#008ec2"); |
| 1173 |
|
| 1174 |
//jQuery( '#aiwp-reports' + slug ).html( '' ); |
| 1175 |
reports.init(); |
| 1176 |
}); |
| 1177 |
|
| 1178 |
if (aiwpItemData.scope == 'admin-widgets') { |
| 1179 |
return; |
| 1180 |
} else { |
| 1181 |
return this.dialog({ |
| 1182 |
width: 'auto', |
| 1183 |
maxWidth: 510, |
| 1184 |
height: 'auto', |
| 1185 |
modal: true, |
| 1186 |
fluid: true, |
| 1187 |
dialogClass: 'aiwp wp-dialog', |
| 1188 |
resizable: false, |
| 1189 |
title: reports.getTitle(aiwpItemData.scope), |
| 1190 |
position: { |
| 1191 |
my: "top", |
| 1192 |
at: "top+100", |
| 1193 |
of: window |
| 1194 |
} |
| 1195 |
}); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
}); |
| 1199 |
|
| 1200 |
function AIWPReportLoad() { |
| 1201 |
if (aiwpItemData.scope == 'admin-widgets') { |
| 1202 |
jQuery('#aiwp-window-1').aiwpItemReport(1); |
| 1203 |
} else { |
| 1204 |
if (aiwpItemData.scope == 'front-item') { |
| 1205 |
jQuery(aiwpItemData.getSelector(aiwpItemData.scope)).on("click", function() { |
| 1206 |
if (!jQuery("#aiwp-window-1").length > 0) { |
| 1207 |
jQuery("body").append('<div id="aiwp-window-1"></div>'); |
| 1208 |
} |
| 1209 |
jQuery('#aiwp-window-1').aiwpItemReport(1); |
| 1210 |
}); |
| 1211 |
} else { |
| 1212 |
jQuery(aiwpItemData.getSelector(aiwpItemData.scope)).on("click", function() { |
| 1213 |
if (!jQuery("#aiwp-window-" + aiwpItemData.getID(this)).length > 0) { |
| 1214 |
jQuery("body").append('<div id="aiwp-window-' + aiwpItemData.getID(this) + '"></div>'); |
| 1215 |
} |
| 1216 |
jQuery('#aiwp-window-' + aiwpItemData.getID(this)).aiwpItemReport(aiwpItemData.getID(this)); |
| 1217 |
}); |
| 1218 |
} |
| 1219 |
} |
| 1220 |
|
| 1221 |
// on window resize |
| 1222 |
jQuery(window).on("resize", function() { |
| 1223 |
aiwpItemData.responsiveDialog(); |
| 1224 |
}); |
| 1225 |
|
| 1226 |
// dialog width larger than viewport |
| 1227 |
jQuery(document).on("dialogopen", ".ui-dialog", function(event, ui) { |
| 1228 |
aiwpItemData.responsiveDialog(); |
| 1229 |
}); |
| 1230 |
} |