function ga_dash_front_content($content) { global $post; global $GADASH_Config; /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); if (!$tools->check_roles($GADASH_Config->options['ga_dash_access_front']) or !($GADASH_Config->options['ga_dash_frontend_stats'] or $GADASH_Config->options['ga_dash_frontend_keywords'])) { return $content; } if ((is_page() || is_single()) && !is_preview()) { wp_enqueue_script('gadash-general-settings', plugins_url('admin/js/admin.js', dirname(__FILE__)), array('jquery')); $page_url = $_SERVER["REQUEST_URI"]; // str_replace(site_url(), "", get_permalink()); $post_id = $post->ID; $content .= '<script type="text/javascript"> gadash_firstclick = true; function checknpcounter(max) { try { if (npcounter == max) { NProgress.done(); } else { npcounter++; NProgress.set((1/(max+1))*npcounter); } } catch(e) {} } npcounter = 0; jQuery(document).ready(function(){ jQuery("#gadwp-title").click(function(){ if (gadash_firstclick){ try { NProgress.configure({ parent: "#gadwp-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"}); jQuery("#gadwp-progressbar").html("' . __("A JavaScript Error is blocking plugin resources!", 'ga-dash') . '"); } if(typeof ga_dash_drawpagesessions == "function"){ jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",gadash_postid: "' . $post_id . '",query: "pageviews",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){ if (!jQuery.isNumeric(response)){ if (jQuery.isArray(response)){ gadash_pagesessions = response; google.setOnLoadCallback(ga_dash_drawpagesessions(gadash_pagesessions)); } else { checknpcounter(0); jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"}); jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '"); console.log("\\n********************* GADWP Log ********************* \\n\\n"+response); } }else{ jQuery("#gadwp-sessions").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"}); jQuery("#gadwp-sessions").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")"); checknpcounter(1); } }); } if(typeof ga_dash_drawpagesearches == "function"){ jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",gadash_postid: "' . $post_id . '",query: "searches",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){ if (!jQuery.isNumeric(response)){ if (jQuery.isArray(response)){ gadash_pagesearches = response; google.setOnLoadCallback(ga_dash_drawpagesearches(gadash_pagesearches)); } else { checknpcounter(0); jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"}); jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '"); console.log("\\n********************* GADWP Log ********************* \\n\\n"+response); } }else{ jQuery("#gadwp-searches").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"}); jQuery("#gadwp-searches").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")"); checknpcounter(1); } }); } gadash_firstclick = false; } }); });'; if ($GADASH_Config->options['ga_dash_frontend_stats']) { $title = __("Views vs UniqueViews", 'ga-dash'); if (isset($GADASH_Config->options['ga_dash_style'])) { $css = "colors:['" . $GADASH_Config->options['ga_dash_style'] . "','" . $tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20) . "'],"; $color = $GADASH_Config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } $content .= ' google.load("visualization", "1", {packages:["corechart"]}); function ga_dash_drawpagesessions(gadash_pagesessions) { var data = google.visualization.arrayToDataTable(gadash_pagesessions); var options = { legend: {position: "none"}, pointSize: 3,' . $css . ' title: "' . $title . '", vAxis: { textPosition: "in", minValue: 0}, chartArea: {width: "100%", height: "80%"}, hAxis: { textPosition: "none"} }; var chart = new google.visualization.AreaChart(document.getElementById("gadwp-sessions")); chart.draw(data, options); checknpcounter(1); }'; } if ($GADASH_Config->options['ga_dash_frontend_keywords']) { $content .= ' google.load("visualization", "1", {packages:["table"]}) function ga_dash_drawpagesearches(gadash_pagesearches) { var datas = google.visualization.arrayToDataTable(gadash_pagesearches); var options = { page: "enable", pageSize: 6, width: "100%" }; var chart = new google.visualization.Table(document.getElementById("gadwp-searches")); chart.draw(datas, options); checknpcounter(1); }'; } $content .= "</script>"; $content .= '<p> <div id="gadwp"> <div id="gadwp-title"> <a href="#gadwp">' . __('Google Analytics Reports', "ga-dash") . ' <span id="gadwp-arrow">▼</span></a> </div> <div id="gadwp-progressbar"></div> <div id="gadwp-content"> ' . ($GADASH_Config->options['ga_dash_frontend_stats'] ? '<div id="gadwp-sessions"></div>' : '') . ($GADASH_Config->options['ga_dash_frontend_keywords'] ? '<div id="gadwp-searches" class="gadwp-spinner"></div>' : '') . ' </div> </div> </p>'; } return $content; }
function gadash_dashboard_widgets() { global $GADASH_Config; /* * Include GAPI */ if ($GADASH_Config->options['ga_dash_token']) { include_once $GADASH_Config->plugin_path . '/tools/gapi.php'; global $GADASH_GAPI; } else { echo '<p>' . __("This plugin needs an authorization:", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Authorize Plugin", 'ga-dash'), 'secondary') . '</form>'; return; } /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); $tools->ga_dash_cleanup_timeouts(); if (current_user_can('manage_options')) { if (isset($_REQUEST['ga_dash_profile_select'])) { $GADASH_Config->options['ga_dash_tableid'] = $_REQUEST['ga_dash_profile_select']; } $profiles = $GADASH_Config->options['ga_dash_profile_list']; $profile_switch = ''; if (is_array($profiles)) { if (!$GADASH_Config->options['ga_dash_tableid']) { if ($GADASH_Config->options['ga_dash_tableid_jail']) { $GADASH_Config->options['ga_dash_tableid'] = $GADASH_Config->options['ga_dash_tableid_jail']; } else { $GADASH_Config->options['ga_dash_tableid'] = $tools->guess_default_domain($profiles); } } else { if ($GADASH_Config->options['ga_dash_jailadmins'] and $GADASH_Config->options['ga_dash_tableid_jail']) { $GADASH_Config->options['ga_dash_tableid'] = $GADASH_Config->options['ga_dash_tableid_jail']; } } $profile_switch .= '<select id="ga_dash_profile_select" name="ga_dash_profile_select" onchange="this.form.submit()">'; foreach ($profiles as $profile) { if (!$GADASH_Config->options['ga_dash_tableid']) { $GADASH_Config->options['ga_dash_tableid'] = $profile[1]; } if (isset($profile[3])) { $profile_switch .= '<option value="' . esc_attr($profile[1]) . '" '; $profile_switch .= selected($profile[1], $GADASH_Config->options['ga_dash_tableid'], false); $profile_switch .= ' title="' . __("View Name:", 'ga-dash') . ' ' . esc_attr($profile[0]) . '">' . esc_attr($tools->ga_dash_get_profile_domain($profile[3])) . '</option>'; } } $profile_switch .= "</select>"; } else { echo '<p>' . __("Something went wrong while retrieving profiles list.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("More details", 'ga-dash'), 'secondary') . '</form>'; return; } } $GADASH_Config->set_plugin_options(); ?> <form id="ga-dash" method="POST"> <?php if (current_user_can('manage_options')) { if ($GADASH_Config->options['ga_dash_jailadmins']) { if ($GADASH_Config->options['ga_dash_tableid_jail']) { $projectId = $GADASH_Config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'ga-dash'), 'secondary') . '</form>'; return; } } else { echo $profile_switch; $projectId = $GADASH_Config->options['ga_dash_tableid']; } } else { if ($GADASH_Config->options['ga_dash_tableid_jail']) { $projectId = $GADASH_Config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'ga-dash'), 'secondary') . '</form>'; return; } } if (!$projectId) { echo '<p>' . __("Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'ga-dash') . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button(__("Find out more!", 'ga-dash'), 'secondary') . '</form>'; return; } else { $profile_info = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $projectId); if (isset($profile_info[4])) { $GADASH_GAPI->timeshift = $profile_info[4]; } else { $GADASH_GAPI->timeshift = (int) current_time('timestamp') - time(); } } if (isset($_REQUEST['query'])) { $query = $_REQUEST['query']; $GADASH_Config->options['ga_dash_default_metric'] = $query; $GADASH_Config->set_plugin_options(); } else { $query = isset($GADASH_Config->options['ga_dash_default_metric']) ? $GADASH_Config->options['ga_dash_default_metric'] : 'sessions'; } if (isset($_REQUEST['period'])) { $period = $_REQUEST['period']; $GADASH_Config->options['ga_dash_default_dimension'] = $period; $GADASH_Config->set_plugin_options(); } else { $period = isset($GADASH_Config->options['ga_dash_default_dimension']) ? $GADASH_Config->options['ga_dash_default_dimension'] : '30daysAgo'; } ?> <select id="ga_dash_period" name="period" onchange="this.form.submit()"> <option value="realtime" <?php selected("realtime", $period, true); ?> ><?php _e("Real-Time", 'ga-dash'); ?> </option> <option value="today" <?php selected("today", $period, true); ?> ><?php _e("Today", 'ga-dash'); ?> </option> <option value="yesterday" <?php selected("yesterday", $period, true); ?> ><?php _e("Yesterday", 'ga-dash'); ?> </option> <option value="7daysAgo" <?php selected("7daysAgo", $period, true); ?> ><?php _e("Last 7 Days", 'ga-dash'); ?> </option> <option value="14daysAgo" <?php selected("14daysAgo", $period, true); ?> ><?php _e("Last 14 Days", 'ga-dash'); ?> </option> <option value="30daysAgo" <?php selected("30daysAgo", $period, true); ?> ><?php _e("Last 30 Days", 'ga-dash'); ?> </option> <option value="90daysAgo" <?php selected("90daysAgo", $period, true); ?> ><?php _e("Last 90 Days", 'ga-dash'); ?> </option> </select> <?php if ($period != 'realtime') { ?> <select id="ga_dash_query" name="query" onchange="this.form.submit()"> <option value="sessions" <?php selected("sessions", $query, true); ?> ><?php _e("Sessions", 'ga-dash'); ?> </option> <option value="users" <?php selected("users", $query, true); ?> ><?php _e("Users", 'ga-dash'); ?> </option> <option value="organicSearches" <?php selected("organicSearches", $query, true); ?> ><?php _e("Organic", 'ga-dash'); ?> </option> <option value="pageviews" <?php selected("pageviews", $query, true); ?> ><?php _e("Page Views", 'ga-dash'); ?> </option> <option value="visitBounceRate" <?php selected("visitBounceRate", $query, true); ?> ><?php _e("Bounce Rate", 'ga-dash'); ?> </option> <option value="locations" <?php selected("locations", $query, true); ?> ><?php _e("Location", 'ga-dash'); ?> </option> <option value="contentpages" <?php selected("contentpages", $query, true); ?> ><?php _e("Pages", 'ga-dash'); ?> </option> <option value="referrers" <?php selected("referrers", $query, true); ?> ><?php _e("Referrers", 'ga-dash'); ?> </option> <option value="searches" <?php selected("searches", $query, true); ?> ><?php _e("Searches", 'ga-dash'); ?> </option> <option value="trafficdetails" <?php selected("trafficdetails", $query, true); ?> ><?php _e("Traffic Details", 'ga-dash'); ?> </option> </select> <?php } ?> </form> <div id="gadash-progressbar"></div> <?php switch ($period) { case 'today': $from = 'today'; $to = 'today'; $haxis = 4; break; case 'yesterday': $from = 'yesterday'; $to = 'yesterday'; $haxis = 4; break; case '7daysAgo': $from = '7daysAgo'; $to = 'yesterday'; $haxis = 2; break; case '14daysAgo': $from = '14daysAgo'; $to = 'yesterday'; $haxis = 3; break; case '30daysAgo': $from = '30daysAgo'; $to = 'yesterday'; $haxis = 5; break; default: $from = '90daysAgo'; $to = 'yesterday'; $haxis = 16; break; } if ($query == 'visitBounceRate') { $formater = "var formatter = new google.visualization.NumberFormat({\r\n\t\t\t\t pattern: '#,##%',\r\n\t\t\t\t fractionDigits: 2\r\n\t\t\t\t});\r\n \r\n\t\t\t\tformatter.format(data, 1);\t"; } else { $formater = ''; } /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); if (isset($GADASH_Config->options['ga_dash_style'])) { $light_color = $tools->colourVariator($GADASH_Config->options['ga_dash_style'], 40); $dark_color = $tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20); $css = "colors:['" . $GADASH_Config->options['ga_dash_style'] . "','" . $tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20) . "'],"; $color = $GADASH_Config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } if ($period == 'realtime') { wp_register_style('jquery-ui-tooltip-html', $GADASH_Config->plugin_url . '/realtime/jquery/jquery.ui.tooltip.html.css'); wp_enqueue_style('jquery-ui-tooltip-html'); if (!wp_script_is('jquery')) { wp_enqueue_script('jquery'); } if (!wp_script_is('jquery-ui-tooltip')) { wp_enqueue_script("jquery-ui-tooltip"); } if (!wp_script_is('jquery-ui-core')) { wp_enqueue_script("jquery-ui-core"); } if (!wp_script_is('jquery-ui-position')) { wp_enqueue_script("jquery-ui-position"); } if (!wp_script_is('jquery-ui-position')) { wp_enqueue_script("jquery-ui-position"); } wp_register_script("jquery-ui-tooltip-html", $GADASH_Config->plugin_url . '/realtime/jquery/jquery.ui.tooltip.html.js'); wp_enqueue_script("jquery-ui-tooltip-html"); } if ($period == 'realtime') { ?> <div class="realtime"> <div class="gadash-rt-box"> <div class='gadash-tdo-left'> <div class='gadash-online' id='gadash-online'>0</div> </div> <div class='gadash-tdo-right' id='gadash-tdo-right'> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("REFERRAL", 'ga-dash'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("ORGANIC", 'ga-dash'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("SOCIAL", 'ga-dash'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("CAMPAIGN", 'ga-dash'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("DIRECT", 'ga-dash'); ?> </div> <div class="gadash-bright">0</div> </div> <div class="gadash-bigtext"> <div class="gadash-bleft"><?php _e("NEW", 'ga-dash'); ?> </div> <div class="gadash-bright">0</div> </div> </div> </div> <div> <div id='gadash-pages' class='gadash-pages'> </div> </div> </div> <script type="text/javascript"> var focusFlag = 1; jQuery(document).ready(function(){ jQuery(window).bind("focus",function(event){ focusFlag = 1; }).bind("blur", function(event){ focusFlag = 0; }); }); jQuery(function() { jQuery( document ).tooltip(); }); function onlyUniqueValues(value, index, self) { return self.indexOf(value) === index; } function countsessions(data, searchvalue) { var count = 0; for ( var i = 0; i < data["rows"].length; i = i + 1 ) { if (jQuery.inArray(searchvalue, data["rows"][ i ])>-1){ count += parseInt(data["rows"][ i ][6]); } } return count; } function gadash_generatetooltip(data) { var count = 0; var table = ""; for ( var i = 0; i < data.length; i = i + 1 ) { count += parseInt(data[ i ].count); table += "<tr><td class='gadash-pgdetailsl'>"+data[i].value+"</td><td class='gadash-pgdetailsr'>"+data[ i ].count+"</td></tr>"; }; if (count){ return("<table>"+table+"</table>"); }else{ return(""); } } function gadash_pagedetails(data, searchvalue) { var newdata = []; for ( var i = 0; i < data["rows"].length; i = i + 1 ){ var sant=1; for ( var j = 0; j < newdata.length; j = j + 1 ){ if (data["rows"][i][0]+data["rows"][i][1]+data["rows"][i][2]+data["rows"][i][3]==newdata[j][0]+newdata[j][1]+newdata[j][2]+newdata[j][3]){ newdata[j][6] = parseInt(newdata[j][6]) + parseInt(data["rows"][i][6]); sant = 0; } } if (sant){ newdata.push(data["rows"][i].slice()); } } var countrfr = 0; var countkwd = 0; var countdrt = 0; var countscl = 0; var countcpg = 0; var tablerfr = ""; var tablekwd = ""; var tablescl = ""; var tablecpg = ""; var tabledrt = ""; for ( var i = 0; i < newdata.length; i = i + 1 ) { if (newdata[i][0] == searchvalue){ var pagetitle = newdata[i][5]; switch (newdata[i][3]){ case "REFERRAL": countrfr += parseInt(newdata[ i ][6]); tablerfr += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "ORGANIC": countkwd += parseInt(newdata[ i ][6]); tablekwd += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][2]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "SOCIAL": countscl += parseInt(newdata[ i ][6]); tablescl += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "CUSTOM": countcpg += parseInt(newdata[ i ][6]); tablecpg += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>"; break; case "DIRECT": countdrt += parseInt(newdata[ i ][6]); break; }; }; }; if (countrfr){ tablerfr = "<table><tr><td><?php _e("REFERRALS", 'ga-dash'); ?> ("+countrfr+")</td></tr>"+tablerfr+"</table><br />"; } if (countkwd){ tablekwd = "<table><tr><td><?php _e("KEYWORDS", 'ga-dash'); ?> ("+countkwd+")</td></tr>"+tablekwd+"</table><br />"; } if (countscl){ tablescl = "<table><tr><td><?php _e("SOCIAL", 'ga-dash'); ?> ("+countscl+")</td></tr>"+tablescl+"</table><br />"; } if (countcpg){ tablecpg = "<table><tr><td><?php _e("CAMPAIGN", 'ga-dash'); ?> ("+countcpg+")</td></tr>"+tablecpg+"</table><br />"; } if (countdrt){ tabledrt = "<table><tr><td><?php _e("DIRECT", 'ga-dash'); ?> ("+countdrt+")</td></tr></table><br />"; } return ("<p><center><strong>"+pagetitle+"</strong></center></p>"+tablerfr+tablekwd+tablescl+tablecpg+tabledrt); } function online_refresh(){ if (focusFlag){ jQuery.post(ajaxurl, {action: "gadashadmin_get_realtime", projectId: "<?php echo $projectId; ?> ", gadashadmin_security_widgetrealtime: "<?php echo wp_create_nonce('gadashadmin_get_realtime'); ?> "}, function(response){ var data = jQuery.parseJSON(response); if (jQuery.isNumeric(data) || typeof data === "undefined"){ data = []; data["totalsForAllResults"] = [] data["totalsForAllResults"]["rt:activeUsers"] = "0"; data["rows"]= []; } if (data["totalsForAllResults"]["rt:activeUsers"]!==document.getElementById("gadash-online").innerHTML){ jQuery("#gadash-online").fadeOut("slow"); jQuery("#gadash-online").fadeOut(500); jQuery("#gadash-online").fadeOut("slow", function() { if ((parseInt(data["totalsForAllResults"]["rt:activeUsers"]))<(parseInt(document.getElementById("gadash-online").innerHTML))){ jQuery("#gadash-online").css({'background-color' : '#FFE8E8'}); }else{ jQuery("#gadash-online").css({'background-color' : '#E0FFEC'}); } document.getElementById("gadash-online").innerHTML = data["totalsForAllResults"]["rt:activeUsers"]; }); jQuery("#gadash-online").fadeIn("slow"); jQuery("#gadash-online").fadeIn(500); jQuery("#gadash-online").fadeIn("slow", function() { jQuery("#gadash-online").css({'background-color' : '#FFFFFF'}); }); }; if (data["totalsForAllResults"]["rt:activeUsers"] == 0){ data["rows"]= []; }; var pagepath = []; var referrals = []; var keywords = []; var social = []; var visittype = []; var custom = []; for ( var i = 0; i < data["rows"].length; i = i + 1 ) { pagepath.push( data["rows"][ i ][0] ); if (data["rows"][i][3]=="REFERRAL"){ referrals.push( data["rows"][ i ][1] ); } if (data["rows"][i][3]=="ORGANIC"){ keywords.push( data["rows"][ i ][2] ); } if (data["rows"][i][3]=="SOCIAL"){ social.push( data["rows"][ i ][1] ); } if (data["rows"][i][3]=="CUSTOM"){ custom.push( data["rows"][ i ][1] ); } visittype.push( data["rows"][ i ][3] ); } var upagepathstats = []; var upagepath = pagepath.filter(onlyUniqueValues); for ( var i = 0; i < upagepath.length; i = i + 1 ) { upagepathstats[i]={"pagepath":upagepath[i],"count":countsessions(data,upagepath[i])}; } upagepathstats.sort( function(a,b){ return b.count - a.count } ); var pgstatstable = ""; for ( var i = 0; i < upagepathstats.length; i = i + 1 ) { if (i < <?php echo $GADASH_Config->options['ga_realtime_pages']; ?> ){ pgstatstable += '<div class="gadash-pline"><div class="gadash-pleft"><a href="#" title="'+gadash_pagedetails(data, upagepathstats[i].pagepath)+'">'+upagepathstats[i].pagepath.substring(0,70)+'</a></div><div class="gadash-pright">'+upagepathstats[i].count+'</div></div>'; } } document.getElementById("gadash-pages").innerHTML='<br /><div class="gadash-pg">'+pgstatstable+'</div>'; var ureferralsstats = []; var ureferrals = referrals.filter(onlyUniqueValues); for ( var i = 0; i < ureferrals.length; i = i + 1 ) { ureferralsstats[i]={"value":ureferrals[i],"count":countsessions(data,ureferrals[i])}; } ureferralsstats.sort( function(a,b){ return b.count - a.count } ); var ukeywordsstats = []; var ukeywords = keywords.filter(onlyUniqueValues); for ( var i = 0; i < ukeywords.length; i = i + 1 ) { ukeywordsstats[i]={"value":ukeywords[i],"count":countsessions(data,ukeywords[i])}; } ukeywordsstats.sort( function(a,b){ return b.count - a.count } ); var usocialstats = []; var usocial = social.filter(onlyUniqueValues); for ( var i = 0; i < usocial.length; i = i + 1 ) { usocialstats[i]={"value":usocial[i],"count":countsessions(data,usocial[i])}; } usocialstats.sort( function(a,b){ return b.count - a.count } ); var ucustomstats = []; var ucustom = custom.filter(onlyUniqueValues); for ( var i = 0; i < ucustom.length; i = i + 1 ) { ucustomstats[i]={"value":ucustom[i],"count":countsessions(data,ucustom[i])}; } ucustomstats.sort( function(a,b){ return b.count - a.count } ); var uvisittype = ["REFERRAL","ORGANIC","SOCIAL","CUSTOM"]; document.getElementById("gadash-tdo-right").innerHTML = '<div class="gadash-bigtext"><a href="#" title="'+gadash_generatetooltip(ureferralsstats)+'"><div class="gadash-bleft">'+'<?php _e("REFERRAL", 'ga-dash'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[0])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" title="'+gadash_generatetooltip(ukeywordsstats)+'"><div class="gadash-bleft">'+'<?php _e("ORGANIC", 'ga-dash'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[1])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" title="'+gadash_generatetooltip(usocialstats)+'"><div class="gadash-bleft">'+'<?php _e("SOCIAL", 'ga-dash'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[2])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" title="'+gadash_generatetooltip(ucustomstats)+'"><div class="gadash-bleft">'+'<?php _e("CAMPAIGN", 'ga-dash'); ?> '+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[3])+'</div></div>'; var uvisitortype = ["DIRECT","NEW"]; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("DIRECT", 'ga-dash'); ?> '+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[0])+'</div></div>'; document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("NEW", 'ga-dash'); ?> '+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[1])+'</div></div>'; }); }; }; online_refresh(); setInterval(online_refresh, 60000); </script> <?php } else { if (array_search($query, array('referrers', 'contentpages', 'searches')) !== FALSE) { ?> <div id="gadash-trafficchannels"></div> <div id="gadash-prs"></div> <script type="text/javascript"> google.load("visualization", "1", {packages:["table","orgchart"]}); function checknpcounter(max) { try { if (npcounter == max) { NProgress.done(); } else { npcounter++; NProgress.set((1/(max+1))*npcounter); } } catch(e) {} } try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border":"1px solid red","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?> "); } npcounter = 0; jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "<?php echo $query; ?> ",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_prs=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawprs(gadash_prs)); }else{ jQuery("#gadash-prs").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-prs").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(1); } }); jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "trafficchannels",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_trafficchannels=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels)); }else{ jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(1); } }); function ga_dash_drawprs(gadash_prs) { var data = google.visualization.arrayToDataTable(gadash_prs); var options = { page: 'enable', pageSize: 10, width: '100%' }; var chart = new google.visualization.Table(document.getElementById('gadash-prs')); chart.draw(data, options); checknpcounter(1); }; function ga_dash_drawtrafficchannels(gadash_trafficchannels) { var data = google.visualization.arrayToDataTable(gadash_trafficchannels); var options = { allowCollapse:true, allowHtml:true }; var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels')); chart.draw(data, options); checknpcounter(1); }; </script> <?php } else { if ($query == 'trafficdetails') { ?> <div id="gadash-trafficchannels"></div> <div class="gadash-floatwraper"> <div id="gadash-trafficmediums"></div> <div id="gadash-traffictype"></div> </div> <div class="gadash-floatwraper"> <div id="gadash-trafficorganic"></div> <div id="gadash-socialnetworks"></div> </div> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart","orgchart"]}); function checknpcounter(max) { try { if (npcounter == max) { NProgress.done(); } else { npcounter++; NProgress.set((1/(max+1))*npcounter); } } catch(e) {} } try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border":"1px solid red","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?> "); } npcounter = 0; jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "medium",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_trafficmediums=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawtrafficmediums(gadash_trafficmediums)); }else{ jQuery("#gadash-trafficmediums").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficmediums").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(4); } }); jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "visitorType",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_traffictype=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawtraffictype(gadash_traffictype)); }else{ jQuery("#gadash-traffictype").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-traffictype").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(4); } }); jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "trafficchannels",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_trafficchannels=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels)); }else{ jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(4); } }); jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "socialNetwork",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_socialnetworks=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawsocialnetworks(gadash_socialnetworks)); }else{ jQuery("#gadash-socialnetworks").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-socialnetworks").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(4); } }); jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "source",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_trafficorganic=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawtrafficorganic(gadash_trafficorganic)); }else{ jQuery("#gadash-trafficorganic").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"}); jQuery("#gadash-trafficorganic").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(4); } }); function ga_dash_drawtrafficmediums(gadash_trafficmediums) { var data = google.visualization.arrayToDataTable(gadash_trafficmediums); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Traffic Mediums", 'ga-dash'); ?> ', colors:['<?php echo esc_html($GADASH_Config->options['ga_dash_style']); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficmediums')); chart.draw(data, options); checknpcounter(4); }; function ga_dash_drawtraffictype(gadash_traffictype) { var data = google.visualization.arrayToDataTable(gadash_traffictype); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Visitor Type", 'ga-dash'); ?> ', colors:['<?php echo esc_html($GADASH_Config->options['ga_dash_style']); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-traffictype')); chart.draw(data, options); checknpcounter(4); }; function ga_dash_drawsocialnetworks(gadash_socialnetworks) { var data = google.visualization.arrayToDataTable(gadash_socialnetworks); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Social Networks", 'ga-dash'); ?> ', colors:['<?php echo esc_html($GADASH_Config->options['ga_dash_style']); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-socialnetworks')); chart.draw(data, options); checknpcounter(4); }; function ga_dash_drawtrafficorganic(gadash_trafficorganic) { var data = google.visualization.arrayToDataTable(gadash_trafficorganic); var options = { is3D: false, tooltipText: 'percentage', legend: 'none', chartArea: {width: '99%',height: '80%'}, title: '<?php _e("Search Engines", 'ga-dash'); ?> ', colors:['<?php echo esc_html($GADASH_Config->options['ga_dash_style']); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20)); ?> '] }; var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficorganic')); chart.draw(data, options); checknpcounter(4); }; function ga_dash_drawtrafficchannels(gadash_trafficchannels) { var data = google.visualization.arrayToDataTable(gadash_trafficchannels); var options = { allowCollapse:true, allowHtml:true }; var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels')); chart.draw(data, options); checknpcounter(4); }; </script> <?php } else { if ($query == 'locations') { ?> <div id="gadash-map"></div> <div id="gadash-locations"></div> <script type="text/javascript"> google.load("visualization", "1", {packages:["geochart","table"]}); function checknpcounter(max) { try { if (npcounter == max) { NProgress.done(); } else { npcounter++; NProgress.set((1/(max+1))*npcounter); } } catch(e) {} } try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border":"1px solid red","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?> "); } npcounter = 0; jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "<?php echo $query; ?> ",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_locations=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawmaplocations(gadash_locations)); google.setOnLoadCallback(ga_dash_drawlocations(gadash_locations)); }else{ jQuery("#gadash-map").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-map").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(1); jQuery("#gadash-locations").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-locations").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(1); } }); function ga_dash_drawmaplocations(gadash_locations) { var data = google.visualization.arrayToDataTable(gadash_locations); var options = { chartArea: {width: '99%',height: '90%'}, colors: ['<?php echo $light_color; ?> ', '<?php echo $dark_color; ?> '], <?php $GADASH_GAPI->getcountrycodes(); if ($GADASH_Config->options['ga_target_geomap'] and isset($GADASH_GAPI->country_codes[$GADASH_Config->options['ga_target_geomap']])) { ?> region : '<?php echo esc_html($GADASH_Config->options['ga_target_geomap']); ?> ', displayMode : 'markers', datalessRegionColor : 'EFEFEF' <?php } ?> } var chart = new google.visualization.GeoChart(document.getElementById('gadash-map')); chart.draw(data, options); checknpcounter(1); } function ga_dash_drawlocations(gadash_locations) { var data = google.visualization.arrayToDataTable(gadash_locations); var options = { page: 'enable', pageSize: 10, width: '100%' }; var chart = new google.visualization.Table(document.getElementById('gadash-locations')); chart.draw(data, options); checknpcounter(1); }; </script> <?php } else { ?> <div id="gadash-mainchart"></div> <div id="gadash-bottomstats" class="gadash-wrapper"> <div class="inside"> <div class="small-box"> <h3><?php _e("Sessions", 'ga-dash'); ?> </h3> <p id="gdsessions"> </p> </div> <div class="small-box"> <h3><?php _e("Users", 'ga-dash'); ?> </h3> <p id="gdusers"> </p> </div> <div class="small-box"> <h3><?php _e("Page Views", 'ga-dash'); ?> </h3> <p id="gdpageviews"> </p> </div> <div class="small-box"> <h3><?php _e("Bounce Rate", 'ga-dash'); ?> </h3> <p id="gdbouncerate"> </p> </div> <div class="small-box"> <h3><?php _e("Organic Search", 'ga-dash'); ?> </h3> <p id="gdorganicsearch"> </p> </div> <div class="small-box"> <h3><?php _e("Pages/Session", 'ga-dash'); ?> </h3> <p id="gdpagespervisit"> </p> </div> </div> </div> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); function checknpcounter(max) { try { if (npcounter == max) { NProgress.done(); } else { npcounter++; NProgress.set((1/(max+1))*npcounter); } } catch(e) {} } try { NProgress.configure({ parent: "#gadash-progressbar" }); NProgress.configure({ showSpinner: false }); NProgress.start(); } catch(e) { jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border":"1px solid red","border-left":"5px solid red"}); jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?> "); } npcounter = 0; jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "<?php echo $query; ?> ",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_mainchart=jQuery.parseJSON(response); google.setOnLoadCallback(ga_dash_drawmainchart(gadash_mainchart)); }else{ jQuery("#gadash-mainchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"}); jQuery("#gadash-mainchart").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(1); } }); jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?> ",from: "<?php echo $from; ?> ",to: "<?php echo $to; ?> ",query: "bottomstats",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?> "}, function(response){ if (!jQuery.isNumeric(response)){ gadash_bottomstats=jQuery.parseJSON(response); ga_dash_drawbottomstats(gadash_bottomstats); }else{ jQuery("#gadash-bottomstats").css({"background-color":"#F7F7F7","height":"auto","padding-top":"40px","padding-bottom":"40px","color":"#000","text-align":"center","width": "98%"}); jQuery("#gadash-bottomstats").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")"); checknpcounter(1); } }); function ga_dash_drawbottomstats(gadash_bottomstats) { jQuery("#gadash-bottomstats #gdsessions").text(gadash_bottomstats[0]); jQuery("#gadash-bottomstats #gdusers").text(gadash_bottomstats[1]); jQuery("#gadash-bottomstats #gdpageviews").text(gadash_bottomstats[2]); jQuery("#gadash-bottomstats #gdbouncerate").text(parseFloat(gadash_bottomstats[3]).toFixed(2)+"%"); jQuery("#gadash-bottomstats #gdorganicsearch").text(gadash_bottomstats[4]); jQuery("#gadash-bottomstats #gdpagespervisit").text(parseFloat(gadash_bottomstats[5]).toFixed(2)); checknpcounter(1); } function ga_dash_drawmainchart(gadash_mainchart) { var data = google.visualization.arrayToDataTable(gadash_mainchart); var options = { legend: {position: 'none'}, pointSize: 3,<?php echo $css; ?> chartArea: {width: '99%',height: '90%'}, vAxis: { textPosition: "in", minValue: 0}, hAxis: { textPosition: 'none' } }; <?php echo $formater; ?> var chart = new google.visualization.AreaChart(document.getElementById('gadash-mainchart')); chart.draw(data, options); checknpcounter(1); }; </script> <?php } } } } }
function frontend_afterpost_visits($projectId, $page_url, $post_id) { global $GADASH_Config; $content = ''; $from = '30daysAgo'; $to = 'yesterday'; $metrics = 'ga:pageviews,ga:uniquePageviews'; $dimensions = 'ga:year,ga:month,ga:day'; $title = __("Views vs UniqueViews", 'ga-dash'); /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); if (isset($GADASH_Config->options['ga_dash_style'])) { $css = "colors:['" . $GADASH_Config->options['ga_dash_style'] . "','" . $tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20) . "'],"; $color = $GADASH_Config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } try { $serial = 'gadash_qr21' . $post_id . 'stats'; $transient = get_transient($serial); if (empty($transient)) { $data = $this->service->data_ga->get('ga:' . $projectId, $from, $to, $metrics, array('dimensions' => $dimensions, 'filters' => 'ga:pagePath==' . $page_url, 'userIp' => $_SERVER['SERVER_ADDR'])); set_transient($serial, $data, $this->get_timeouts(1)); } else { $data = $transient; } } catch (Exception $e) { update_option('gadash_lasterror', esc_html($e)); return ''; } if (!isset($data['rows'])) { return ''; } $ga_dash_statsdata = ""; for ($i = 0; $i < $data['totalResults']; $i++) { $ga_dash_statsdata .= "['" . $data['rows'][$i][0] . "-" . $data['rows'][$i][1] . "-" . $data['rows'][$i][2] . "'," . round($data['rows'][$i][3], 2) . "," . round($data['rows'][$i][4], 2) . "],"; } $ga_dash_statsdata = rtrim($ga_dash_statsdata, ','); if ($ga_dash_statsdata) { $content .= ' google.load("visualization", "1", {packages:["corechart"]}); function ga_dash_drawstats() { var data = google.visualization.arrayToDataTable([' . "\r\n\t\t\t\t ['" . __("Date", 'ga-dash') . "', '" . __("Views", 'ga-dash') . "', '" . __("UniqueViews", 'ga-dash') . "']," . $ga_dash_statsdata . "\r\n\t\t\t\t]);\r\n\t\t\t\t\r\n\t\t\t\tvar options = {\r\n\t\t\t\t legend: {position: 'none'},\r\n\t\t\t\t pointSize: 3," . $css . "\r\n\t\t\t\t title: '" . $title . "',\r\n\t\t \t\t vAxis: {minValue: 0},\t\t\t\t\t\t\r\n\t\t\t\t chartArea: {width: '100%'},\r\n\t\t\t\t hAxis: { showTextEvery: 5}\r\n\t\t\t\t};\r\n\t\t\t\t\r\n\t\t\t\tvar chart = new google.visualization.AreaChart(document.getElementById('ga_dash_statsdata'));\r\n\t\t\t\tchart.draw(data, options);\r\n\t\t\t\t\r\n\t\t\t\t}"; } return $content; }
function gadash_dashboard_widgets() { global $GADASH_Config; /* * Include GAPI */ if ($GADASH_Config->options['ga_dash_token'] and function_exists('curl_version')) { include_once $GADASH_Config->plugin_path . '/tools/gapi.php'; global $GADASH_GAPI; } else { echo '<p>' . __("This plugin needs an authorization:", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Authorize Plugin", 'ga-dash'), 'secondary') . '</form>'; return; } /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); $tools->ga_dash_cleanup_timeouts(); if (!$GADASH_GAPI->client->getAccessToken()) { echo '<p>' . __("Something went wrong. Please check the Debugging Data section for possible errors", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Error Log", 'ga-dash'), 'secondary') . '</form>'; return; } if (current_user_can('manage_options')) { if (isset($_REQUEST['ga_dash_profile_select'])) { $GADASH_Config->options['ga_dash_tableid'] = $_REQUEST['ga_dash_profile_select']; } $profiles = $GADASH_Config->options['ga_dash_profile_list']; $profile_switch = ''; if (is_array($profiles)) { if (!$GADASH_Config->options['ga_dash_tableid']) { if ($GADASH_Config->options['ga_dash_tableid_jail']) { $GADASH_Config->options['ga_dash_tableid'] = $GADASH_Config->options['ga_dash_tableid_jail']; } else { $GADASH_Config->options['ga_dash_tableid'] = $tools->guess_default_domain($profiles); } } else { if ($GADASH_Config->options['ga_dash_jailadmins'] and $GADASH_Config->options['ga_dash_tableid_jail']) { $GADASH_Config->options['ga_dash_tableid'] = $GADASH_Config->options['ga_dash_tableid_jail']; } } $profile_switch .= '<select id="ga_dash_profile_select" name="ga_dash_profile_select" onchange="this.form.submit()">'; foreach ($profiles as $profile) { if (!$GADASH_Config->options['ga_dash_tableid']) { $GADASH_Config->options['ga_dash_tableid'] = $profile[1]; } if (isset($profile[3])) { $profile_switch .= '<option value="' . esc_attr($profile[1]) . '" '; $profile_switch .= selected($profile[1], $GADASH_Config->options['ga_dash_tableid'], false); $profile_switch .= ' title="' . __("View Name:", 'ga-dash') . ' ' . esc_attr($profile[0]) . '">' . esc_attr($tools->ga_dash_get_profile_domain($profile[3])) . '</option>'; } } $profile_switch .= "</select>"; } else { echo '<p>' . __("Something went wrong while retrieving profiles list.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("More details", 'ga-dash'), 'secondary') . '</form>'; return; } } $GADASH_Config->set_plugin_options(); ?> <form id="ga-dash" method="POST"> <?php if (current_user_can('manage_options')) { if ($GADASH_Config->options['ga_dash_jailadmins']) { if ($GADASH_Config->options['ga_dash_tableid_jail']) { $projectId = $GADASH_Config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'ga-dash'), 'secondary') . '</form>'; return; } } else { echo $profile_switch; $projectId = $GADASH_Config->options['ga_dash_tableid']; } } else { if ($GADASH_Config->options['ga_dash_tableid_jail']) { $projectId = $GADASH_Config->options['ga_dash_tableid_jail']; } else { echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'ga-dash'), 'secondary') . '</form>'; return; } } if (!$projectId) { echo '<p>' . __("Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'ga-dash') . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button(__("Find out more!", 'ga-dash'), 'secondary') . '</form>'; return; } else { $profile_info = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $projectId); if (isset($profile_info[4])) { $GADASH_GAPI->timeshift = $profile_info[4]; } else { $GADASH_GAPI->timeshift = (int) current_time('timestamp') - time(); } } if (isset($_REQUEST['query'])) { $query = $_REQUEST['query']; $GADASH_Config->options['ga_dash_default_metric'] = $query; $GADASH_Config->set_plugin_options(); } else { $query = isset($GADASH_Config->options['ga_dash_default_metric']) ? $GADASH_Config->options['ga_dash_default_metric'] : 'visits'; } if (isset($_REQUEST['period'])) { $period = $_REQUEST['period']; $GADASH_Config->options['ga_dash_default_dimension'] = $period; $GADASH_Config->set_plugin_options(); } else { $period = isset($GADASH_Config->options['ga_dash_default_dimension']) ? $GADASH_Config->options['ga_dash_default_dimension'] : '30daysAgo'; } if ($period == "realtime") { $realtime = "realtime"; $period = ''; } else { $realtime = ''; } ?> <select id="ga_dash_period" name="period" onchange="this.form.submit()"> <option value="realtime" <?php selected("realtime", $period, true); ?> ><?php _e("Real-Time", 'ga-dash'); ?> </option> <option value="today" <?php selected("today", $period, true); ?> ><?php _e("Today", 'ga-dash'); ?> </option> <option value="yesterday" <?php selected("yesterday", $period, true); ?> ><?php _e("Yesterday", 'ga-dash'); ?> </option> <option value="7daysAgo" <?php selected("7daysAgo", $period, true); ?> ><?php _e("Last 7 Days", 'ga-dash'); ?> </option> <option value="14daysAgo" <?php selected("14daysAgo", $period, true); ?> ><?php _e("Last 14 Days", 'ga-dash'); ?> </option> <option value="30daysAgo" <?php selected("30daysAgo", $period, true); ?> ><?php _e("Last 30 Days", 'ga-dash'); ?> </option> <option value="90daysAgo" <?php selected("90daysAgo", $period, true); ?> ><?php _e("Last 90 Days", 'ga-dash'); ?> </option> </select> <?php if (!$realtime) { ?> <select id="ga_dash_query" name="query" onchange="this.form.submit()"> <option value="visits" <?php selected("visits", $query, true); ?> ><?php _e("Visits", 'ga-dash'); ?> </option> <option value="visitors" <?php selected("visitors", $query, true); ?> ><?php _e("Visitors", 'ga-dash'); ?> </option> <option value="organicSearches" <?php selected("organicSearches", $query, true); ?> ><?php _e("Organic", 'ga-dash'); ?> </option> <option value="pageviews" <?php selected("pageviews", $query, true); ?> ><?php _e("Page Views", 'ga-dash'); ?> </option> <option value="visitBounceRate" <?php selected("visitBounceRate", $query, true); ?> ><?php _e("Bounce Rate", 'ga-dash'); ?> </option> </select> <?php } ?> </form> <?php switch ($period) { case 'today': $from = 'today'; $to = 'today'; $haxis = 4; $dh = __("Hour", 'ga-dash'); break; case 'yesterday': $from = 'yesterday'; $to = 'yesterday'; $haxis = 4; $dh = __("Hour", 'ga-dash'); break; case '7daysAgo': $from = '7daysAgo'; $to = 'yesterday'; $haxis = 2; $dh = __("Date", 'ga-dash'); break; case '14daysAgo': $from = '14daysAgo'; $to = 'yesterday'; $haxis = 3; $dh = __("Date", 'ga-dash'); break; case '30daysAgo': $from = '30daysAgo'; $to = 'yesterday'; $haxis = 5; $dh = __("Date", 'ga-dash'); break; default: $from = '90daysAgo'; $to = 'yesterday'; $haxis = 16; $dh = __("Date", 'ga-dash'); break; } if ($realtime == "realtime") { wp_register_style('jquery-ui-tooltip-html', $GADASH_Config->plugin_url . '/realtime/jquery/jquery.ui.tooltip.html.css'); wp_enqueue_style('jquery-ui-tooltip-html'); if (!wp_script_is('jquery')) { wp_enqueue_script('jquery'); } if (!wp_script_is('jquery-ui-tooltip')) { wp_enqueue_script("jquery-ui-tooltip"); } if (!wp_script_is('jquery-ui-core')) { wp_enqueue_script("jquery-ui-core"); } if (!wp_script_is('jquery-ui-position')) { wp_enqueue_script("jquery-ui-position"); } if (!wp_script_is('jquery-ui-position')) { wp_enqueue_script("jquery-ui-position"); } wp_register_script("jquery-ui-tooltip-html", $GADASH_Config->plugin_url . '/realtime/jquery/jquery.ui.tooltip.html.js'); wp_enqueue_script("jquery-ui-tooltip-html"); } else { switch ($query) { case 'visitors': $title = __("Visitors", 'ga-dash'); break; case 'pageviews': $title = __("Page Views", 'ga-dash'); break; case 'visitBounceRate': $title = __("Bounce Rate", 'ga-dash'); break; case 'organicSearches': $title = __("Organic Searches", 'ga-dash'); break; default: $title = __("Visits", 'ga-dash'); } } if ($query == 'visitBounceRate') { $formater = "var formatter = new google.visualization.NumberFormat({\r\n\t\t\t\t pattern: '#,##%',\r\n\t\t\t\t fractionDigits: 2\r\n\t\t\t\t});\r\n\t\t\t\r\n\t\t\t\tformatter.format(data, 1);\t"; } else { $formater = ''; } $ga_dash_statsdata = $GADASH_GAPI->ga_dash_main_charts($projectId, $period, $from, $to, $query); if (!$ga_dash_statsdata) { echo '<p>' . __("No stats available. Please check the Debugging Data section for possible errors", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Error Log", 'ga-dash'), 'secondary') . '</form>'; return; } $ga_dash_bottom_stats = $GADASH_GAPI->ga_dash_bottom_stats($projectId, $period, $from, $to); if (!$ga_dash_bottom_stats) { echo '<p>' . __("No stats available. Please check the Debugging Data section for possible errors", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Error Log", 'ga-dash'), 'secondary') . '</form>'; return; } if (isset($GADASH_Config->options['ga_dash_style'])) { $light_color = $tools->colourVariator($GADASH_Config->options['ga_dash_style'], 40); $dark_color = $tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20); $css = "colors:['" . $GADASH_Config->options['ga_dash_style'] . "','" . $tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20) . "'],"; $color = $GADASH_Config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } ?> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(ga_dash_callback); function ga_dash_callback(){ if(typeof ga_dash_drawstats == "function"){ ga_dash_drawstats(); } if(typeof ga_dash_drawmap == "function"){ ga_dash_drawmap(); } if(typeof ga_dash_drawpgd == "function"){ ga_dash_drawpgd(); } if(typeof ga_dash_drawrd == "function"){ ga_dash_drawrd(); } if(typeof ga_dash_drawsd == "function"){ ga_dash_drawsd(); } if(typeof ga_dash_drawtraffic == "function"){ ga_dash_drawtraffic(); } }; <?php if ($realtime != "realtime") { ?> function ga_dash_drawstats() { var data = google.visualization.arrayToDataTable([ ['<?php echo $dh; ?> ', '<?php echo $title; ?> '], <?php echo $ga_dash_statsdata; ?> ]); var options = { legend: {position: 'none'}, pointSize: 3,<?php echo $css; ?> title: '<?php echo $title; ?> ', chartArea: {width: '85%'}, vAxis: {minValue: 0}, hAxis: { title: '<?php echo $dh; ?> ', titleTextStyle: {color: '<?php echo $dark_color; ?> '}, showTextEvery: <?php echo $haxis; ?> } }; <?php echo $formater; ?> var chart = new google.visualization.AreaChart(document.getElementById('ga_dash_statsdata')); chart.draw(data, options); }; <?php } $ga_dash_visits_country = ''; if ($GADASH_Config->options['ga_dash_map'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { $ga_dash_visits_country = $GADASH_GAPI->ga_dash_visits_country($projectId, $from, $to); if ($ga_dash_visits_country) { ?> google.load("visualization", "1", {packages:["geochart"]}) function ga_dash_drawmap() { var data = google.visualization.arrayToDataTable([ ['<?php _e("Country/City", 'ga-dash'); ?> ', ' <?php _e("Visits", 'ga-dash'); ?> '], <?php echo $ga_dash_visits_country; ?> ]); var options = { colors: ['<?php echo $light_color; ?> ', '<?php echo $dark_color; ?> '], <?php if ($GADASH_Config->options['ga_target_geomap']) { ?> region : '<?php echo esc_html($GADASH_Config->options['ga_target_geomap']); ?> ', displayMode : 'markers', datalessRegionColor : 'EFEFEF' <?php } ?> } var chart = new google.visualization.GeoChart(document.getElementById('ga_dash_mapdata')); chart.draw(data, options); } <?php } } $ga_dash_traffic_sources = ''; $ga_dash_new_return = ''; if ($GADASH_Config->options['ga_dash_traffic'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { $ga_dash_traffic_sources = $GADASH_GAPI->ga_dash_traffic_sources($projectId, $from, $to); $ga_dash_new_return = $GADASH_GAPI->ga_dash_new_return($projectId, $from, $to); if ($ga_dash_traffic_sources and $ga_dash_new_return) { ?> google.load("visualization", "1", {packages:["corechart"]}) function ga_dash_drawtraffic() { var data = google.visualization.arrayToDataTable([ ['<?php _e("Source", 'ga-dash'); ?> ', '<?php _e("Visits", 'ga-dash'); ?> '], <?php echo $ga_dash_traffic_sources; ?> ]); var datanvr = google.visualization.arrayToDataTable([ ['<?php echo _e("Type", 'ga-dash'); ?> ', '<?php _e("Visits", 'ga-dash'); ?> '], <?php echo $ga_dash_new_return; ?> ]); var chart = new google.visualization.PieChart(document.getElementById('ga_dash_trafficdata')); chart.draw(data, { is3D: false, tooltipText: 'percentage', legend: 'none', title: '<?php _e("Traffic Sources", 'ga-dash'); ?> ', colors:['<?php echo esc_html($GADASH_Config->options['ga_dash_style']); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20)); ?> '] }); var chart1 = new google.visualization.PieChart(document.getElementById('ga_dash_nvrdata')); chart1.draw(datanvr, { is3D: false, tooltipText: 'percentage', legend: 'none', title: '<?php _e("New vs. Returning", 'ga-dash'); ?> ', colors:['<?php echo esc_html($GADASH_Config->options['ga_dash_style']); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +20)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], +10)); ?> ','<?php echo esc_html($tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20)); ?> '] }); } <?php } } $ga_dash_top_pages = ''; if ($GADASH_Config->options['ga_dash_pgd'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { $ga_dash_top_pages = $GADASH_GAPI->ga_dash_top_pages($projectId, $from, $to); if ($ga_dash_top_pages) { ?> google.load("visualization", "1", {packages:["table"]}) function ga_dash_drawpgd() { var data = google.visualization.arrayToDataTable([ ['<?php _e("Top Pages", 'ga-dash'); ?> ', '<?php _e("Visits", 'ga-dash'); ?> '], <?php echo $ga_dash_top_pages; ?> ]); var options = { page: 'enable', pageSize: 6, width: '100%', allowHtml:true }; var chart = new google.visualization.Table(document.getElementById('ga_dash_pgddata')); chart.draw(data, options); }; <?php } } $ga_dash_top_referrers = ''; if ($GADASH_Config->options['ga_dash_rd'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { $ga_dash_top_referrers = $GADASH_GAPI->ga_dash_top_referrers($projectId, $from, $to); if ($ga_dash_top_referrers) { ?> google.load("visualization", "1", {packages:["table"]}) function ga_dash_drawrd() { var datar = google.visualization.arrayToDataTable([ ['<?php _e("Top Referrers", 'ga-dash'); ?> ', '<?php _e("Visits", 'ga-dash'); ?> '], <?php echo $ga_dash_top_referrers; ?> ]); var options = { page: 'enable', pageSize: 6, width: '100%', allowHtml:true }; var chart = new google.visualization.Table(document.getElementById('ga_dash_rdata')); chart.draw(datar, options); } <?php } } $ga_dash_top_searches = ''; if ($GADASH_Config->options['ga_dash_sd'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { $ga_dash_top_searches = $GADASH_GAPI->ga_dash_top_searches($projectId, $from, $to); if ($ga_dash_top_searches) { ?> google.load("visualization", "1", {packages:["table"]}) function ga_dash_drawsd() { var datas = google.visualization.arrayToDataTable([ ['<?php echo _e("Top Searches", 'ga-dash'); ?> ', '<?php _e("Visits", 'ga-dash'); ?> '], <?php echo $ga_dash_top_searches; ?> ]); var options = { page: 'enable', pageSize: 6, width: '100%' }; var chart = new google.visualization.Table(document.getElementById('ga_dash_sdata')); chart.draw(datas, options); } <?php } } ?> </script> </script> <?php if ($realtime != "realtime") { ?> <div id="ga_dash_statsdata" class="widefat" style="height: 350px;"></div> <div id="details_div"> <table class="gatable" cellpadding="4"> <tr> <td width="24%"><?php _e("Visits:", 'ga-dash'); ?> </td> <td width="12%" class="gavalue"><a href="?query=visits&period=<?php echo $period; ?> " class="gatable"><?php echo (int) $ga_dash_bottom_stats['rows'][0][1]; ?> </td> <td width="24%"><?php _e("Visitors:", 'ga-dash'); ?> </td> <td width="12%" class="gavalue"><a href="?query=visitors&period=<?php echo $period; ?> " class="gatable"><?php echo (int) $ga_dash_bottom_stats['rows'][0][2]; ?> </a></td> <td width="24%"><?php _e("Page Views:", 'ga-dash'); ?> </td> <td width="12%" class="gavalue"><a href="?query=pageviews&period=<?php echo $period; ?> " class="gatable"><?php echo (int) $ga_dash_bottom_stats['rows'][0][3]; ?> </a></td> </tr> <tr> <td><?php _e("Bounce Rate:", 'ga-dash'); ?> </td> <td class="gavalue"><a href="?query=visitBounceRate&period=<?php echo $period; ?> " class="gatable"><?php echo (double) round($ga_dash_bottom_stats['rows'][0][4], 2); ?> %</a></td> <td><?php _e("Organic Search:", 'ga-dash'); ?> </td> <td class="gavalue"><a href="?query=organicSearches&period=<?php echo $period; ?> " class="gatable"><?php echo (int) $ga_dash_bottom_stats['rows'][0][5]; ?> </a></td> <td><?php _e("Pages per Visit:", 'ga-dash'); ?> </td> <td class="gavalue"><a href="#" class="gatable"><?php echo (double) ($ga_dash_bottom_stats['rows'][0][1] ? round($ga_dash_bottom_stats['rows'][0][3] / $ga_dash_bottom_stats['rows'][0][1], 2) : '0'); ?> </a></td> </tr> </table> </div> <?php } else { if ($GADASH_Config->options['ga_dash_userapi']) { ?> <p style='padding: 100px; line-height: 2em;'> <?php _e("This is a beta feature and is only available when using my Developer Key! (", 'ga-dash'); ?> <a href="https://deconf.com/google-analytics-dashboard-real-time-reports/" target="_blank"><?php _e("more about this feature", 'ga-dash'); ?> </a>) </p> <?php } else { ?> <table width='90%' class='realtime'> <tr> <td class='gadash-tdo-left'> <div> <span class='gadash-online' id='gadash-online'> </span> </div> </td> <td class='gadash-tdo-right' id='gadash-tdo-right'><span class="gadash-bigtext"><?php _e("REFERRAL", 'ga-dash'); ?> : 0</span><br /> <br /> <span class="gadash-bigtext"><?php _e("ORGANIC", 'ga-dash'); ?> : 0</span><br /> <br /> <span class="gadash-bigtext"><?php _e("SOCIAL", 'ga-dash'); ?> : 0</span><br /> <br /></td> <td class='gadash-tdo-rights' id='gadash-tdo-rights'><span class="gadash-bigtext"><?php _e("DIRECT", 'ga-dash'); ?> : 0</span><br /> <br /> <span class="gadash-bigtext"><?php _e("NEW", 'ga-dash'); ?> : 0</span><br /> <br /> <span class="gadash-bigtext"><?php _e("RETURN", 'ga-dash'); ?> : 0</span><br /> <br /></td> </tr> <tr> <td id='gadash-pages' class='gadash-pages' colspan='3'> </td> </tr> </table> <?php echo $GADASH_GAPI->ga_realtime(); } } if ($GADASH_Config->options['ga_dash_map'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back']) and $ga_dash_visits_country) { ?> <br /> <h3> <?php if ($GADASH_Config->options['ga_target_geomap']) { $GADASH_GAPI->getcountrycodes(); echo __("Visits from ", 'ga-dash') . esc_html($GADASH_GAPI->country_codes[$GADASH_Config->options['ga_target_geomap']]); } else { echo __("Visits by Country", 'ga-dash'); } ?> </h3> <div id="ga_dash_mapdata"></div> <?php } if ($GADASH_Config->options['ga_dash_traffic'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back']) and ($ga_dash_top_referrers or $ga_dash_top_pages or $ga_dash_traffic_sources and $ga_dash_new_return)) { ?> <br /> <h3> <?php _e("Traffic Overview", 'ga-dash'); ?> </h3> <div style="width: 100%; clear: both;"> <div style="width: 50%; float: left;"> <div id="ga_dash_trafficdata"></div> </div> <div style="width: 50%; float: left;"> <div id="ga_dash_nvrdata"></div> </div> </div> <div style="clear: both;"></div> <?php } if ($GADASH_Config->options['ga_dash_pgd'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { ?> <div id="ga_dash_pgddata"></div> <?php } if ($GADASH_Config->options['ga_dash_rd'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { ?> <div id="ga_dash_rdata"></div> <?php } if ($GADASH_Config->options['ga_dash_sd'] and $tools->check_roles($GADASH_Config->options['ga_dash_access_back'])) { ?> <div id="ga_dash_sdata"></div> <?php } }
public function widget($args, $instance) { global $GADASH_Config; $widget_title = apply_filters('widget_title', $instance['title']); $title = __("Sessions", 'ga-dash') . ($instance['anonim'] ? "' " . __("trend", 'ga-dash') : ''); echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Widget - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n"; echo $args['before_widget']; if (!empty($widget_title)) { echo $args['before_title'] . $widget_title . $args['after_title']; } /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); if (isset($GADASH_Config->options['ga_dash_style'])) { $css = "colors:['" . $GADASH_Config->options['ga_dash_style'] . "','" . $tools->colourVariator($GADASH_Config->options['ga_dash_style'], -20) . "'],"; $color = $GADASH_Config->options['ga_dash_style']; } else { $css = ""; $color = "#3366CC"; } ob_start(); if ($instance['anonim']) { $formater = "var formatter = new google.visualization.NumberFormat({\n\t\t\t\t\t suffix: '%',\n\t\t\t\t\t fractionDigits: 2\n\t\t\t\t\t});\n \n\t\t\t\t\tformatter.format(data, 1);\t"; } else { $formater = ''; } $periodtext = ""; switch ($instance['period']) { case '7daysAgo': $periodtext = __('Last 7 Days', 'ga-dash'); break; case '14daysAgo': $periodtext = __('Last 14 Days', 'ga-dash'); break; case '30daysAgo': $periodtext = __('Last 30 Days', 'ga-dash'); break; default: $periodtext = ""; break; } switch ($instance['display']) { case '1': echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div><div id="gadwp-widgettotals"></div></div>'; break; case '2': echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div></div>'; break; case '3': echo '<div id="gadwp-widget"><div id="gadwp-widgettotals"></div></div>'; break; } echo '<script type="text/javascript"> jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontendwidget_data",gadash_number: "' . $this->number . '",gadash_optionname: "' . $this->option_name . '"}, function(response){ if (!jQuery.isNumeric(response) && jQuery.isArray(response)){ if (jQuery("#gadwp-widgetchart")[0]){ gadash_widgetsessions=response[0]; google.setOnLoadCallback(ga_dash_drawfwidgetsessions(gadash_widgetsessions)); } if (jQuery("#gadwp-widgettotals")[0]){ ga_dash_drawtotalsstats(response[1]); } }else{ jQuery("#gadwp-widgetchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"50px","padding-bottom":"50px","color":"#000","text-align":"center"}); jQuery("#gadwp-widgetchart").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")"); } });'; echo 'google.load("visualization", "1", {packages:["corechart"]}); function ga_dash_drawfwidgetsessions(response) { var data = google.visualization.arrayToDataTable(response); var options = { legend: {position: "none"}, pointSize: 3,' . $css . ' title: "' . $title . '", titlePosition: "in", chartArea: {width: "95%",height:"75%"}, hAxis: { textPosition: "none"}, vAxis: { textPosition: "none", minValue: 0, gridlines: {color: "transparent"}, baselineColor: "transparent"} } var chart = new google.visualization.AreaChart(document.getElementById("gadwp-widgetchart")); ' . $formater . ' chart.draw(data, options); } function ga_dash_drawtotalsstats(response) { if (response == null){ response = 0; } jQuery("#gadwp-widgettotals").html("<div class=\\"gadwp-left\\">' . __("Period:", 'ga-dash') . '</div> <div class=\\"gadwp-right\\">' . $periodtext . '</div><div class=\\"gadwp-left\\">' . __("Sessions:", 'ga-dash') . '</div> <div class=\\"gadwp-right\\">"+response+"</div>"); }'; echo '</script>'; if ($instance['give_credits'] == 1) { echo '<div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;">' . __('generated by', 'ga-dash') . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a> </div>'; } $widget_content = ob_get_contents(); ob_end_clean(); echo apply_filters('widget_html_content', $widget_content); echo $args['after_widget']; echo "\n<!-- END GADWP Widget -->\n"; }