コード例 #1
0
ファイル: Analytics.php プロジェクト: Vatia13/tofido
 public function actionHeatmaps()
 {
     if (!$this->_assertLinkedAccount()) {
         return;
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // sanitize
         $regEx = '#[^a-z0-9\\:\\-\\=\\|\\ \\;]#i';
         $_POST['metric'] = preg_replace($regEx, '', @$_POST['metric']);
         $_POST['segment'] = preg_replace($regEx, '', @$_POST['segment']);
         $_POST['end'] = absint(@$_POST['end']);
         $_POST['weeks'] = absint(@$_POST['weeks']);
         if (empty($_POST['page_path'])) {
             $_POST['page_path'] = false;
         }
         if (!DigitalPointBetterAnalytics_Helper_Api::check()) {
             if (array_search($_POST['metric'], array('ga:users', 'ga:sessions', 'ga:hits', 'ga:organicSearches')) === false) {
                 wp_send_json(array('error' => sprintf(__('Not all metrics are available for unlicensed copies of the Better Analytics plugin.%1$s%2$sYou can license a copy over here.%3$s%1$sIf this is a valid license, make sure the purchaser of the add-on has verified ownership of this domain %4$sover here%3$s.', 'better-analytics'), '<br /><br />', '<a href="' . esc_url(BETTER_ANALYTICS_PRO_PRODUCT_URL . '#utm_source=admin_reports_ajax&utm_medium=wordpress&utm_campaign=plugin') . '" target="_blank">', '</a>', '<a href="' . esc_url('https://forums.digitalpoint.com/marketplace/domain-verification#utm_source=admin_reports_ajax&utm_medium=wordpress&utm_campaign=plugin') . '" target="_blank">')));
             }
         }
         if ($_POST['page_path']) {
             $_POST['metric'] .= (strpos($_POST['metric'], '|') ? ';' : '|') . 'ga:pagePath==' . $_POST['page_path'];
         }
         $heatmapData = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getWeeklyHeatmap($_POST['end'], $_POST['weeks'], $_POST['metric'], $_POST['segment']);
         wp_send_json(array('heatmap_data' => $heatmapData));
     }
     $heatmapData = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getWeeklyHeatmap(1, 4, 'ga:sessions' . (!empty($_REQUEST['page_path']) ? '|ga:pagePath==' . $_REQUEST['page_path'] : ''));
     $_hourMap = array();
     for ($i = 0; $i < 24; $i++) {
         $_hourMap[$i] = date('g A', $i * 3600);
     }
     $this->_view('reports/heatmaps', array('heatmap_data' => $heatmapData, 'metrics' => DigitalPointBetterAnalytics_Model_Reporting::getMetrics(), 'segments' => DigitalPointBetterAnalytics_Model_Reporting::getSegments(), 'hour_map' => $_hourMap));
 }
コード例 #2
0
ファイル: Stats.php プロジェクト: Vatia13/tofido
    function form($instance)
    {
        wp_enqueue_script('chosen_js', BETTER_ANALYTICS_PLUGIN_URL . 'assets/chosen/chosen.jquery.min.js', array(), BETTER_ANALYTICS_VERSION);
        wp_enqueue_style('chosen_css', BETTER_ANALYTICS_PLUGIN_URL . 'assets/chosen/chosen.min.css', array(), BETTER_ANALYTICS_VERSION);
        $title = isset($instance['title']) ? esc_attr($instance['title']) : esc_attr('Analytics Stats', 'better-analytics');
        $metric = isset($instance['metric']) ? $instance['metric'] : 'ga:sessions';
        $days = isset($instance['days']) ? absint($instance['days']) : 1;
        $format = isset($instance['format']) ? $instance['format'] : '%1$s: <strong>%2$s</strong>';
        $thisPageOnly = isset($instance['this_page_only']) ? $instance['this_page_only'] : '';
        $private = isset($instance['private']) ? $instance['private'] : '';
        $betterAnalyticsOptions = get_option('better_analytics');
        if (!DigitalPointBetterAnalytics_Base_Public::getInstance()->getTokens() || !$betterAnalyticsOptions['api']['profile']) {
            echo '<p>' . sprintf(esc_html__('No Linked Google Analytics Account (API access required for this widget).  You can link one in the %1$sBetter Analytics API settings%2$s.', 'better-analytics'), '<a href="' . esc_url(menu_page_url('better-analytics', false) . '#top#api') . '">', '</a>') . '</p>';
        }
        ?>

		<p><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        esc_html_e('Title:');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
" /></p>


		<?php 
        $metrics = DigitalPointBetterAnalytics_Model_Reporting::getMetrics();
        echo '<select id="' . $this->get_field_id('metric') . '" name="' . $this->get_field_name('metric') . '" class="chosen-select">';
        foreach ($metrics as $label => $group) {
            echo '<optgroup label="' . htmlentities($label) . '">';
            foreach ($group as $key => $name) {
                echo '<option value="' . $key . '"' . selected($key, $metric) . '>' . htmlentities($name) . '</option>';
            }
            echo '</optgroup>';
        }
        echo '</select>
			<script>
				jQuery( document ).ready(function() {
					jQuery("#widgets-right .chosen-select").chosen({
							search_contains: true,
							width: "100%"
						});
				});
			</script>
';
        ?>


		<p><label for="<?php 
        echo $this->get_field_id('days');
        ?>
"><?php 
        esc_html_e('Number of days to show:', 'better-analytics');
        ?>
</label>
			<input id="<?php 
        echo $this->get_field_id('days');
        ?>
" name="<?php 
        echo $this->get_field_name('days');
        ?>
" type="text" value="<?php 
        echo $days;
        ?>
" min="1" style="width:80px;"/></p>

		<p><label for="<?php 
        echo $this->get_field_id('format');
        ?>
"><?php 
        esc_html_e('HTML Format For Widget:', 'better-analytics');
        ?>
</label>
			<textarea id="<?php 
        echo $this->get_field_id('format');
        ?>
" name="<?php 
        echo $this->get_field_name('format');
        ?>
" type="text" style="display:block;width:100%"><?php 
        echo esc_textarea($format);
        ?>
</textarea>
			<span class="description"><?php 
        esc_html_e('You can add HTML formatting here if you wish.  %1$s = metric name, %2$s = value', 'better-analytics');
        ?>
</span>
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('this_page_only');
        ?>
">
				<input id="<?php 
        echo $this->get_field_id('this_page_only');
        ?>
" name="<?php 
        echo $this->get_field_name('this_page_only');
        ?>
" type="checkbox" value="1" <?php 
        checked('1', $thisPageOnly);
        ?>
>
				<?php 
        esc_html_e('Stats for current page only', 'better-analytics');
        ?>
</label>
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('private');
        ?>
">
				<input id="<?php 
        echo $this->get_field_id('private');
        ?>
" name="<?php 
        echo $this->get_field_name('private');
        ?>
" type="checkbox" value="1" <?php 
        checked('1', $private);
        ?>
>
				<?php 
        esc_html_e('Private (adheres to role/author permissions)', 'better-analytics');
        ?>
</label>
		</p>

	<?php 
    }