Version Description
Download this release
Release Info
Developer | ShareThis |
Plugin | Google Analytics |
Version | 2.5.2 |
Comparing to | |
See all releases |
Code changes from version 2.5.1 to 2.5.2
- assets/images/demographics-ad.png +0 -0
- assets/images/demographics-ex.png +0 -0
- class/Ga_Admin.php +51 -24
- class/Ga_Helper.php +163 -4
- class/Ga_Stats.php +100 -82
- class/Ga_Template.php +73 -0
- css/googleanalytics.css +9 -2
- googleanalytics.php +2 -2
- js/googleanalytics_page.js +16 -1
- readme.txt +10 -4
- view/ga_notice.php +10 -5
- view/stats.php +39 -24
- view/templates/date_custom_range_filter.php +26 -0
- view/templates/demographic-chart.php +35 -19
- view/templates/gdpr-config.php +1 -27
- view/templates/sidebar/demo-ad.php +1 -1
assets/images/demographics-ad.png
ADDED
Binary file
|
assets/images/demographics-ex.png
ADDED
Binary file
|
class/Ga_Admin.php
CHANGED
@@ -82,7 +82,7 @@ class Ga_Admin {
|
|
82 |
delete_option('googleanalytics_gdpr_config');
|
83 |
delete_option('googleanalytics_demographic');
|
84 |
delete_option('googleanalytics_demo_data');
|
85 |
-
|
86 |
delete_option('googleanalytics_send_data');
|
87 |
delete_option('googleanalytics_hide_terms');
|
88 |
delete_option('googleanalytics_sharethis_terms');
|
@@ -479,25 +479,28 @@ class Ga_Admin {
|
|
479 |
* @return string HTML code
|
480 |
*/
|
481 |
public static function get_stats_page() {
|
482 |
-
$
|
483 |
-
$
|
|
|
|
|
484 |
$gender_chart = null;
|
485 |
-
$
|
486 |
-
$
|
487 |
-
|
488 |
if ( Ga_Helper::is_authorized() && Ga_Helper::is_account_selected() && ! Ga_Helper::is_all_feature_disabled() ) {
|
489 |
-
list( $chart, $age_chart, $gender_chart, $boxes, $labels, $sources ) = self::generate_stats_data();
|
490 |
}
|
491 |
|
492 |
return Ga_Helper::get_chart_page(
|
493 |
'stats',
|
494 |
-
|
495 |
-
'
|
496 |
-
'
|
497 |
-
'
|
498 |
-
'
|
499 |
-
'
|
500 |
-
'
|
|
|
501 |
)
|
502 |
);
|
503 |
}
|
@@ -765,21 +768,44 @@ class Ga_Admin {
|
|
765 |
public static function generate_stats_data() {
|
766 |
$selected = Ga_Helper::get_selected_account_data( true );
|
767 |
$update_data = self::checkDataDate();
|
768 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
769 |
$stats_data = self::api_client()->call(
|
770 |
-
|
771 |
[ $query_params ]
|
772 |
);
|
773 |
-
$gender_params =
|
774 |
$gender_data = self::api_client()->call(
|
775 |
'ga_api_data',
|
776 |
[$gender_params]
|
777 |
);
|
778 |
-
$age_params =
|
779 |
$age_data = self::api_client()->call(
|
780 |
'ga_api_data',
|
781 |
[$age_params]
|
782 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
783 |
$boxes_data = self::api_client()->call(
|
784 |
'ga_api_data',
|
785 |
[ Ga_Stats::get_query( 'boxes', $selected['view_id'] ) ]
|
@@ -789,9 +815,10 @@ class Ga_Admin {
|
|
789 |
[ Ga_Stats::get_query( 'sources', $selected['view_id'] ) ]
|
790 |
);
|
791 |
|
792 |
-
$chart = ! empty( $stats_data ) ? Ga_Stats::get_chart( $stats_data->getData() ) : array();
|
793 |
-
$
|
794 |
-
$
|
|
|
795 |
$boxes = ! empty( $boxes_data ) ? Ga_Stats::get_boxes( $boxes_data->getData() ) : array();
|
796 |
$last_chart_date = ! empty( $chart ) ? $chart['date'] : strtotime( 'now' );
|
797 |
|
@@ -824,12 +851,12 @@ class Ga_Admin {
|
|
824 |
);
|
825 |
}
|
826 |
|
827 |
-
return [$chart, $age_chart, $gender_chart, $boxes, $labels, $sources];
|
828 |
}
|
829 |
|
830 |
private static function updateDemoData($gender_response = false, $age_response = false)
|
831 |
{
|
832 |
-
|
833 |
$demoSendData = [];
|
834 |
if ($gender_response && $age_response) {
|
835 |
foreach ($age_response as $type => $amount) {
|
@@ -963,7 +990,7 @@ class Ga_Admin {
|
|
963 |
*/
|
964 |
private static function getVendors()
|
965 |
{
|
966 |
-
$response = wp_remote_get('https://
|
967 |
|
968 |
return json_decode(wp_remote_retrieve_body($response), true);
|
969 |
}
|
82 |
delete_option('googleanalytics_gdpr_config');
|
83 |
delete_option('googleanalytics_demographic');
|
84 |
delete_option('googleanalytics_demo_data');
|
85 |
+
delete_option('googleanalytics_demo_date');
|
86 |
delete_option('googleanalytics_send_data');
|
87 |
delete_option('googleanalytics_hide_terms');
|
88 |
delete_option('googleanalytics_sharethis_terms');
|
479 |
* @return string HTML code
|
480 |
*/
|
481 |
public static function get_stats_page() {
|
482 |
+
$age_chart = null;
|
483 |
+
$boxes = null;
|
484 |
+
$chart = null;
|
485 |
+
$device_chart = null;
|
486 |
$gender_chart = null;
|
487 |
+
$labels = null;
|
488 |
+
$sources = null;
|
489 |
+
|
490 |
if ( Ga_Helper::is_authorized() && Ga_Helper::is_account_selected() && ! Ga_Helper::is_all_feature_disabled() ) {
|
491 |
+
list( $chart, $age_chart, $device_chart, $gender_chart, $boxes, $labels, $sources ) = self::generate_stats_data();
|
492 |
}
|
493 |
|
494 |
return Ga_Helper::get_chart_page(
|
495 |
'stats',
|
496 |
+
compact(
|
497 |
+
'age_chart',
|
498 |
+
'boxes',
|
499 |
+
'chart',
|
500 |
+
'device_chart',
|
501 |
+
'gender_chart',
|
502 |
+
'labels',
|
503 |
+
'sources'
|
504 |
)
|
505 |
);
|
506 |
}
|
768 |
public static function generate_stats_data() {
|
769 |
$selected = Ga_Helper::get_selected_account_data( true );
|
770 |
$update_data = self::checkDataDate();
|
771 |
+
|
772 |
+
$current_period = Ga_Helper::getDateRangeFromRequest();
|
773 |
+
|
774 |
+
$current_period['start'] = $current_period['from'] ?: date('Y-m-d', strtotime('-1 week'));
|
775 |
+
$current_period['end'] = $current_period['to'] ?: date('Y-m-d', strtotime('now'));
|
776 |
+
|
777 |
+
$previous_period = Ga_Helper::getPreviousPeriodForDates($current_period['start'], $current_period['end']);
|
778 |
+
|
779 |
+
$period_in_days = Ga_Helper::getPeriodInDays($current_period['start'], $current_period['end']);
|
780 |
+
|
781 |
+
$date_ranges = Ga_Stats::set_date_ranges(
|
782 |
+
$current_period['start'],
|
783 |
+
$current_period['end'],
|
784 |
+
$previous_period['start'],
|
785 |
+
$previous_period['end']
|
786 |
+
);
|
787 |
+
|
788 |
+
$query_params = Ga_Stats::get_query( 'main_chart', $selected['view_id'], $date_ranges );
|
789 |
$stats_data = self::api_client()->call(
|
790 |
+
'ga_api_data',
|
791 |
[ $query_params ]
|
792 |
);
|
793 |
+
$gender_params = Ga_Stats::get_query( 'gender', $selected['view_id'], $date_ranges );
|
794 |
$gender_data = self::api_client()->call(
|
795 |
'ga_api_data',
|
796 |
[$gender_params]
|
797 |
);
|
798 |
+
$age_params = Ga_Stats::get_query( 'age', $selected['view_id'], $date_ranges );
|
799 |
$age_data = self::api_client()->call(
|
800 |
'ga_api_data',
|
801 |
[$age_params]
|
802 |
);
|
803 |
+
$device_params = Ga_Stats::get_query( 'device', $selected['view_id'], $date_ranges );
|
804 |
+
$device_data = self::api_client()->call(
|
805 |
+
'ga_api_data',
|
806 |
+
[ $device_params ]
|
807 |
+
);
|
808 |
+
|
809 |
$boxes_data = self::api_client()->call(
|
810 |
'ga_api_data',
|
811 |
[ Ga_Stats::get_query( 'boxes', $selected['view_id'] ) ]
|
815 |
[ Ga_Stats::get_query( 'sources', $selected['view_id'] ) ]
|
816 |
);
|
817 |
|
818 |
+
$chart = ! empty( $stats_data ) ? Ga_Stats::get_chart( $stats_data->getData(), $period_in_days ) : array();
|
819 |
+
$device_chart = false === empty( $device_data ) ? Ga_Stats::get_device_chart( $device_data->getData() ) : array();
|
820 |
+
$gender_chart = ! empty( $gender_data ) ? Ga_Stats::get_gender_chart( $gender_data->getData() ) : [];
|
821 |
+
$age_chart = ! empty( $age_data ) ? Ga_Stats::get_age_chart( $age_data->getData() ) : [];
|
822 |
$boxes = ! empty( $boxes_data ) ? Ga_Stats::get_boxes( $boxes_data->getData() ) : array();
|
823 |
$last_chart_date = ! empty( $chart ) ? $chart['date'] : strtotime( 'now' );
|
824 |
|
851 |
);
|
852 |
}
|
853 |
|
854 |
+
return [$chart, $age_chart, $device_chart, $gender_chart, $boxes, $labels, $sources];
|
855 |
}
|
856 |
|
857 |
private static function updateDemoData($gender_response = false, $age_response = false)
|
858 |
{
|
859 |
+
$x = 0;
|
860 |
$demoSendData = [];
|
861 |
if ($gender_response && $age_response) {
|
862 |
foreach ($age_response as $type => $amount) {
|
990 |
*/
|
991 |
private static function getVendors()
|
992 |
{
|
993 |
+
$response = wp_remote_get('https://vendor-list.consensu.org/v2/vendor-list.json');
|
994 |
|
995 |
return json_decode(wp_remote_retrieve_body($response), true);
|
996 |
}
|
class/Ga_Helper.php
CHANGED
@@ -544,15 +544,29 @@ class Ga_Helper {
|
|
544 |
}
|
545 |
}
|
546 |
|
|
|
|
|
|
|
|
|
|
|
547 |
public static function is_wp_old() {
|
548 |
return version_compare( get_bloginfo( 'version' ), self::GA_WP_MODERN_VERSION, 'lt' );
|
549 |
}
|
550 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
551 |
public static function should_load_ga_javascript( $web_property_id ) {
|
552 |
return ( self::is_configured( $web_property_id ) && ( self::can_add_ga_code() || self::is_all_feature_disabled() ) );
|
553 |
}
|
554 |
|
555 |
/**
|
|
|
|
|
556 |
* @return string
|
557 |
*/
|
558 |
public static function get_account_id() {
|
@@ -561,16 +575,30 @@ class Ga_Helper {
|
|
561 |
return ! empty( $account_id[0] ) ? $account_id[0] : '';
|
562 |
}
|
563 |
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
|
|
|
|
|
|
|
|
568 |
|
|
|
|
|
|
|
|
|
|
|
569 |
public static function get_plugin_url_with_correct_protocol() {
|
570 |
$url = parse_url( GA_PLUGIN_URL );
|
571 |
return ( ( is_ssl() ) ? 'https://' : 'http://' ) . $url['host'] . $url['path'];
|
572 |
}
|
573 |
|
|
|
|
|
|
|
|
|
|
|
574 |
public static function get_code_manually_label_classes() {
|
575 |
$classes = '';
|
576 |
if ( ! self::are_features_enabled() ){
|
@@ -581,4 +609,135 @@ class Ga_Helper {
|
|
581 |
}
|
582 |
return $classes;
|
583 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
}
|
544 |
}
|
545 |
}
|
546 |
|
547 |
+
/**
|
548 |
+
* Is this version of WordPress considered old (< 4.1)?
|
549 |
+
*
|
550 |
+
* @return bool True if old, False if not.
|
551 |
+
*/
|
552 |
public static function is_wp_old() {
|
553 |
return version_compare( get_bloginfo( 'version' ), self::GA_WP_MODERN_VERSION, 'lt' );
|
554 |
}
|
555 |
|
556 |
+
/**
|
557 |
+
* Should we load GA JavaScript on this property?
|
558 |
+
*
|
559 |
+
* @param string $web_property_id
|
560 |
+
*
|
561 |
+
* @return bool
|
562 |
+
*/
|
563 |
public static function should_load_ga_javascript( $web_property_id ) {
|
564 |
return ( self::is_configured( $web_property_id ) && ( self::can_add_ga_code() || self::is_all_feature_disabled() ) );
|
565 |
}
|
566 |
|
567 |
/**
|
568 |
+
* Get account ID.
|
569 |
+
*
|
570 |
* @return string
|
571 |
*/
|
572 |
public static function get_account_id() {
|
575 |
return ! empty( $account_id[0] ) ? $account_id[0] : '';
|
576 |
}
|
577 |
|
578 |
+
/**
|
579 |
+
* Is curl disabled?
|
580 |
+
*
|
581 |
+
* @return bool True if disabled, false if enabled.
|
582 |
+
*/
|
583 |
+
public static function is_curl_disabled() {
|
584 |
+
return ! function_exists( 'curl_version' );
|
585 |
+
}
|
586 |
|
587 |
+
/**
|
588 |
+
* Get URL with correct protocol.
|
589 |
+
*
|
590 |
+
* @return string URL with correct protocol.
|
591 |
+
*/
|
592 |
public static function get_plugin_url_with_correct_protocol() {
|
593 |
$url = parse_url( GA_PLUGIN_URL );
|
594 |
return ( ( is_ssl() ) ? 'https://' : 'http://' ) . $url['host'] . $url['path'];
|
595 |
}
|
596 |
|
597 |
+
/**
|
598 |
+
* Get code to manually label classes.
|
599 |
+
*
|
600 |
+
* @return string
|
601 |
+
*/
|
602 |
public static function get_code_manually_label_classes() {
|
603 |
$classes = '';
|
604 |
if ( ! self::are_features_enabled() ){
|
609 |
}
|
610 |
return $classes;
|
611 |
}
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Get Previous Period for Dates (date start and date end).
|
615 |
+
*
|
616 |
+
* @param string $date_start Date string.
|
617 |
+
* @param string $date_end Date string.
|
618 |
+
*
|
619 |
+
* @return array Array of start and end dates in Y-m-d format.
|
620 |
+
* @since 2.5.2
|
621 |
+
*/
|
622 |
+
public static function getPreviousPeriodForDates($date_start = '', $date_end = '')
|
623 |
+
{
|
624 |
+
try {
|
625 |
+
// Get distance between dates in days.
|
626 |
+
$start = new DateTime($date_start);
|
627 |
+
$end = new DateTime($date_end);
|
628 |
+
} catch (\Exception $e) {
|
629 |
+
return [
|
630 |
+
'start' => date('Y-m-d', strtotime('-1 week')),
|
631 |
+
'end' => date('Y-m-d'),
|
632 |
+
];
|
633 |
+
}
|
634 |
+
|
635 |
+
// Clone $start date into end_previous so we don't modify $start.
|
636 |
+
$end_previous = clone $start;
|
637 |
+
|
638 |
+
// Set the period to the difference between the start/end dates in days.
|
639 |
+
$period = $end->diff($start)->days;
|
640 |
+
|
641 |
+
// Subtract 1 day from $end_previous so it's one day before $start.
|
642 |
+
$end_previous->modify('-1 day');
|
643 |
+
|
644 |
+
// Clone $end_previous so we can subtract $period from it in days.
|
645 |
+
$start_previous = clone $end_previous;
|
646 |
+
$start_previous->modify(sprintf('-%d day', $period));
|
647 |
+
|
648 |
+
return [
|
649 |
+
'start' => $start_previous->format('Y-m-d'),
|
650 |
+
'end' => $end_previous->format('Y-m-d'),
|
651 |
+
];
|
652 |
+
}
|
653 |
+
|
654 |
+
/**
|
655 |
+
* Get period between dates in days.
|
656 |
+
*
|
657 |
+
* @param string $date_start Start date string.
|
658 |
+
* @param string $date_end End date string.
|
659 |
+
*
|
660 |
+
* @return int
|
661 |
+
* @since 2.5.2
|
662 |
+
*/
|
663 |
+
public static function getPeriodInDays($date_start = '', $date_end = '')
|
664 |
+
{
|
665 |
+
$date_start = empty($date_start) ? date('Y-m-d', strtotime('-1 week')) : $date_start;
|
666 |
+
$date_end = empty($date_end) ? date('Y-m-d') : $date_end;
|
667 |
+
|
668 |
+
try {
|
669 |
+
// Get distance between dates in days.
|
670 |
+
$start = new DateTime($date_start);
|
671 |
+
$end = new DateTime($date_end);
|
672 |
+
} catch (\Exception $e) {
|
673 |
+
return 0;
|
674 |
+
}
|
675 |
+
|
676 |
+
// Set the period to the difference between the start/end dates in days.
|
677 |
+
return intval($start->diff($end)->format('%r%a'));
|
678 |
+
}
|
679 |
+
|
680 |
+
/**
|
681 |
+
* Get period in Days as words.
|
682 |
+
*
|
683 |
+
* @param string $date_start Start date string.
|
684 |
+
* @param string $date_end End date string.
|
685 |
+
*
|
686 |
+
* @return string Words to indicate days.
|
687 |
+
* @since 2.5.2
|
688 |
+
*/
|
689 |
+
public static function getPeriodInDaysWords($date_start = '', $date_end = '')
|
690 |
+
{
|
691 |
+
$days = self::getPeriodInDays($date_start, $date_end);
|
692 |
+
|
693 |
+
$date_end = empty($date_end) ? strtotime('now') : strtotime($date_end);
|
694 |
+
|
695 |
+
// If today is the same as the end date.
|
696 |
+
if (date('Y-m-d', $date_end) === date('Y-m-d')) {
|
697 |
+
if (0 === $days) {
|
698 |
+
return __('Today', 'googleanalytics');
|
699 |
+
}
|
700 |
+
|
701 |
+
if (7 === $days) {
|
702 |
+
return __('This Week', 'googleanalytics');
|
703 |
+
}
|
704 |
+
|
705 |
+
return sprintf(_n('Last %d Day', 'Last %d Days', $days, 'googleanalytics'), $days);
|
706 |
+
}
|
707 |
+
|
708 |
+
return sprintf(_n('%d Day', '%d Days', $days, 'googleanalytics'), $days);
|
709 |
+
}
|
710 |
+
|
711 |
+
/**
|
712 |
+
* Get date range from GET request.
|
713 |
+
*
|
714 |
+
* @return array
|
715 |
+
* @since 2.5.2
|
716 |
+
*/
|
717 |
+
public static function getDateRangeFromRequest()
|
718 |
+
{
|
719 |
+
$date_range = filter_input_array(INPUT_GET, [
|
720 |
+
'date_from' => FILTER_SANITIZE_STRING,
|
721 |
+
'date_to' => FILTER_SANITIZE_STRING,
|
722 |
+
]);
|
723 |
+
|
724 |
+
// If date_from is after date_to, let's reset 'from' to a week before 'to.'
|
725 |
+
if (0 > Ga_Helper::getPeriodInDays($date_range['date_from'], $date_range['date_to'])) {
|
726 |
+
try {
|
727 |
+
$date = new DateTime($date_range['date_to']);
|
728 |
+
$date->modify('-1 week');
|
729 |
+
|
730 |
+
$date_from = $date->format('Y-m-d');
|
731 |
+
} catch (\Exception $e) {
|
732 |
+
$date_from = date('Y-m-d', strtotime('-1 week'));
|
733 |
+
}
|
734 |
+
|
735 |
+
$date_range['date_from'] = $date_from;
|
736 |
+
}
|
737 |
+
|
738 |
+
return [
|
739 |
+
'from' => $date_range['date_from'],
|
740 |
+
'to' => $date_range['date_to'],
|
741 |
+
];
|
742 |
+
}
|
743 |
}
|
class/Ga_Stats.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
*/
|
11 |
class Ga_Stats {
|
12 |
|
13 |
-
private $profile
|
14 |
|
15 |
/**
|
16 |
* Primary class constructor.
|
@@ -19,7 +19,6 @@ class Ga_Stats {
|
|
19 |
* @since 7.0.0
|
20 |
*/
|
21 |
public function __construct() {
|
22 |
-
$this->profile = $this->get_analytics_profile();
|
23 |
}
|
24 |
|
25 |
/**
|
@@ -37,6 +36,8 @@ class Ga_Stats {
|
|
37 |
return self::main_chart_query( $id_view, $date_range, $metric );
|
38 |
} elseif ( $query == 'gender' ) {
|
39 |
return self::gender_chart_query($id_view, $date_range, $metric);
|
|
|
|
|
40 |
} elseif ( $query == 'age' ) {
|
41 |
return self::age_chart_query($id_view, $date_range, $metric);
|
42 |
} elseif ( $query == 'boxes' ) {
|
@@ -44,7 +45,7 @@ class Ga_Stats {
|
|
44 |
} elseif ( $query == 'dashboard_boxes' ) {
|
45 |
return self::dashboard_boxes_query( $id_view, $date_range );
|
46 |
} elseif ( $query == 'sources' ) {
|
47 |
-
return self::sources_query( $id_view );
|
48 |
} else {
|
49 |
return array();
|
50 |
}
|
@@ -54,17 +55,16 @@ class Ga_Stats {
|
|
54 |
* Preparing query for top traffic sources table
|
55 |
*
|
56 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
57 |
-
*
|
58 |
* @return array Sources query
|
59 |
*/
|
60 |
-
public static function sources_query( $id_view ) {
|
61 |
-
$reports_requests
|
62 |
-
$daysAgo = isset($_GET['th']) ? '30daysAgo' : '7daysAgo';
|
63 |
|
64 |
if ( isset( $_GET['ts'] ) ) {
|
65 |
$reports_requests[] = array(
|
66 |
'viewId' => $id_view,
|
67 |
-
'dateRanges' =>
|
68 |
'metrics' => self::set_metrics( array( 'ga:pageviews' ) ),
|
69 |
'includeEmptyRows' => true,
|
70 |
'pageSize' => 10,
|
@@ -74,7 +74,7 @@ class Ga_Stats {
|
|
74 |
} else {
|
75 |
$reports_requests[] = array(
|
76 |
'viewId' => $id_view,
|
77 |
-
'dateRanges' =>
|
78 |
'metrics' => self::set_metrics( array(
|
79 |
'ga:pageviews',
|
80 |
'ga:uniquePageviews',
|
@@ -101,18 +101,17 @@ class Ga_Stats {
|
|
101 |
* Preparing query for dashbord boxes
|
102 |
*
|
103 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
104 |
-
* @param
|
105 |
*
|
106 |
* @return array Dashboard boxes query
|
107 |
*/
|
108 |
-
public static function dashboard_boxes_query( $id_view, $
|
109 |
-
$reports_requests
|
110 |
-
$daysAgo = isset($_GET['th']) ? '30daysAgo' : '7daysAgo';
|
111 |
|
112 |
if ( isset( $_GET['ts'] ) ) {
|
113 |
$reports_requests[] = array(
|
114 |
'viewId' => $id_view,
|
115 |
-
'dateRanges' =>
|
116 |
'metrics' => self::set_metrics( array( 'ga:pageviews' ) ),
|
117 |
'includeEmptyRows' => true,
|
118 |
'pageSize' => 10,
|
@@ -122,7 +121,7 @@ class Ga_Stats {
|
|
122 |
} else {
|
123 |
$reports_requests[] = array(
|
124 |
'viewId' => $id_view,
|
125 |
-
'dateRanges' =>
|
126 |
'metrics' => self::set_metrics( array(
|
127 |
'ga:pageviews',
|
128 |
'ga:uniquePageviews',
|
@@ -179,19 +178,13 @@ class Ga_Stats {
|
|
179 |
* Preparing query for chart
|
180 |
*
|
181 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
182 |
-
* @param
|
183 |
* @param string $metric A metric expression
|
184 |
*
|
185 |
* @return array Chart query
|
186 |
*/
|
187 |
-
public static function main_chart_query( $id_view, $
|
188 |
-
if ( empty( $
|
189 |
-
$date_ranges = self::set_date_ranges( '7daysAgo', 'yesterday', '14daysAgo', '8daysAgo' );
|
190 |
-
} else {
|
191 |
-
$date_ranges = self::set_date_ranges( $date_range, 'yesterday', '14daysAgo', '8daysAgo' );
|
192 |
-
}
|
193 |
-
|
194 |
-
if ( empty( $metric ) ) {
|
195 |
$metric = 'ga:pageviews';
|
196 |
} else {
|
197 |
$metric = 'ga:' . $metric;
|
@@ -216,18 +209,12 @@ class Ga_Stats {
|
|
216 |
* Preparing query for gender chart
|
217 |
*
|
218 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
219 |
-
* @param
|
220 |
* @param string $metric A metric expression
|
221 |
*
|
222 |
* @return array Chart query
|
223 |
*/
|
224 |
-
public static function gender_chart_query( $id_view, $
|
225 |
-
if ( empty( $date_range ) ) {
|
226 |
-
$date_ranges = self::set_date_ranges( '7daysAgo', 'yesterday', '14daysAgo', '8daysAgo' );
|
227 |
-
} else {
|
228 |
-
$date_ranges = self::set_date_ranges( $date_range, 'yesterday', '14daysAgo', '8daysAgo' );
|
229 |
-
}
|
230 |
-
|
231 |
$reports_requests = array();
|
232 |
$reports_requests[] = array(
|
233 |
'viewId' => $id_view,
|
@@ -243,22 +230,40 @@ class Ga_Stats {
|
|
243 |
return $query;
|
244 |
}
|
245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
/**
|
247 |
* Preparing query for age chart
|
248 |
*
|
249 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
250 |
-
* @param
|
251 |
* @param string $metric A metric expression
|
252 |
*
|
253 |
* @return array Chart query
|
254 |
*/
|
255 |
-
public static function age_chart_query( $id_view, $
|
256 |
-
if ( empty( $date_range ) ) {
|
257 |
-
$date_ranges = self::set_date_ranges( '7daysAgo', 'yesterday', '14daysAgo', '8daysAgo' );
|
258 |
-
} else {
|
259 |
-
$date_ranges = self::set_date_ranges( $date_range, 'yesterday', '14daysAgo', '8daysAgo' );
|
260 |
-
}
|
261 |
-
|
262 |
$reports_requests = array();
|
263 |
$reports_requests[] = array(
|
264 |
'viewId' => $id_view,
|
@@ -346,12 +351,12 @@ class Ga_Stats {
|
|
346 |
$date_danges = array();
|
347 |
$date_danges[] = array(
|
348 |
'startDate' => $start_date,
|
349 |
-
'endDate' => $end_date
|
350 |
);
|
351 |
if ( !empty( $prev_start_date ) and ! empty( $prev_end_date ) ) {
|
352 |
$date_danges[] = array(
|
353 |
'startDate' => $prev_start_date,
|
354 |
-
'endDate' => $prev_end_date
|
355 |
);
|
356 |
}
|
357 |
|
@@ -383,7 +388,7 @@ class Ga_Stats {
|
|
383 |
*
|
384 |
* @param array $row Analytics response row
|
385 |
*
|
386 |
-
* @return array Dimensions
|
387 |
*/
|
388 |
public static function get_dimensions( $row ) {
|
389 |
if ( !empty( $row[ 'dimensions' ] ) ) {
|
@@ -398,7 +403,7 @@ class Ga_Stats {
|
|
398 |
*
|
399 |
* @param array $row Analytics response row
|
400 |
*
|
401 |
-
* @return array Metrics
|
402 |
*/
|
403 |
public static function get_metrics( $row ) {
|
404 |
if ( !empty( $row[ 'metrics' ] ) ) {
|
@@ -413,7 +418,7 @@ class Ga_Stats {
|
|
413 |
*
|
414 |
* @param array $report_data Analytics response report data
|
415 |
*
|
416 |
-
* @return array Rows
|
417 |
*/
|
418 |
public static function get_rows( $report_data ) {
|
419 |
if ( !empty( $report_data[ 'rows' ] ) ) {
|
@@ -428,7 +433,7 @@ class Ga_Stats {
|
|
428 |
*
|
429 |
* @param array $report_data Analytics response report data
|
430 |
*
|
431 |
-
* @return array Row count
|
432 |
*/
|
433 |
public static function get_row_count( $report_data ) {
|
434 |
if ( !empty( $report_data[ 'rowCount' ] ) ) {
|
@@ -443,7 +448,7 @@ class Ga_Stats {
|
|
443 |
*
|
444 |
* @param array $report_data Analytics response report data
|
445 |
*
|
446 |
-
* @return array Totals
|
447 |
*/
|
448 |
public static function get_totals( $report_data ) {
|
449 |
if ( !empty( $report_data[ 'totals' ] ) ) {
|
@@ -458,7 +463,7 @@ class Ga_Stats {
|
|
458 |
*
|
459 |
* @param array $data Analytics response data
|
460 |
*
|
461 |
-
* @return array Reports
|
462 |
*/
|
463 |
public static function get_reports_from_response( $data ) {
|
464 |
if ( !empty( $data[ 'reports' ] ) ) {
|
@@ -497,7 +502,7 @@ class Ga_Stats {
|
|
497 |
*
|
498 |
* @param array $data Analytics response data
|
499 |
*
|
500 |
-
* @return array Report
|
501 |
*/
|
502 |
public static function get_single_report( $data ) {
|
503 |
if ( !empty( $data ) ) {
|
@@ -516,7 +521,7 @@ class Ga_Stats {
|
|
516 |
*
|
517 |
* @param array $rows Analytics response data rows
|
518 |
*
|
519 |
-
* @return array Row
|
520 |
*/
|
521 |
public static function get_single_row( $rows ) {
|
522 |
if ( !empty( $rows ) ) {
|
@@ -567,20 +572,20 @@ class Ga_Stats {
|
|
567 |
*
|
568 |
* @return array chart data
|
569 |
*/
|
570 |
-
public static function get_chart( $response_data ) {
|
571 |
$chart_data = array();
|
572 |
-
if ( !empty( $response_data ) ) {
|
573 |
-
$data
|
574 |
-
$rows
|
575 |
-
if ( !empty( $rows ) ) {
|
576 |
foreach ( $rows as $key => $row ) {
|
577 |
-
if ( $key <
|
578 |
-
$chart_data[ $key ][
|
579 |
-
$chart_data[ $key ][
|
580 |
} else {
|
581 |
-
$chart_data[ $key -
|
582 |
-
$chart_data[ $key -
|
583 |
-
$chart_data[
|
584 |
}
|
585 |
}
|
586 |
}
|
@@ -603,7 +608,7 @@ class Ga_Stats {
|
|
603 |
$rows = (!empty( $data[ 'rows' ] ) ) ? $data[ 'rows' ] : array();
|
604 |
if ( !empty( $rows ) ) {
|
605 |
foreach ( $rows as $key => $row ) {
|
606 |
-
$chart_data[$row['dimensions'][0]] = self::
|
607 |
}
|
608 |
}
|
609 |
}
|
@@ -612,11 +617,35 @@ class Ga_Stats {
|
|
612 |
}
|
613 |
|
614 |
/**
|
615 |
-
* Get
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
616 |
*
|
617 |
* @param $metrics
|
|
|
|
|
618 |
*/
|
619 |
-
private static function
|
620 |
{
|
621 |
if (is_array($metrics)) {
|
622 |
foreach($metrics as $metric) {
|
@@ -641,7 +670,7 @@ class Ga_Stats {
|
|
641 |
$rows = (!empty( $data[ 'rows' ] ) ) ? $data[ 'rows' ] : array();
|
642 |
if ( !empty( $rows ) ) {
|
643 |
foreach ( $rows as $key => $row ) {
|
644 |
-
$chart_data[$row['dimensions'][0]] = self::
|
645 |
}
|
646 |
}
|
647 |
}
|
@@ -649,22 +678,6 @@ class Ga_Stats {
|
|
649 |
return $chart_data;
|
650 |
}
|
651 |
|
652 |
-
/**
|
653 |
-
* Get the value of gender response.
|
654 |
-
*
|
655 |
-
* @param $metrics
|
656 |
-
*/
|
657 |
-
private static function getAgeValue($metrics)
|
658 |
-
{
|
659 |
-
if (is_array($metrics)) {
|
660 |
-
foreach($metrics as $metric) {
|
661 |
-
$values[] = $metric['values'][0];
|
662 |
-
}
|
663 |
-
}
|
664 |
-
|
665 |
-
return $values[0];
|
666 |
-
}
|
667 |
-
|
668 |
/**
|
669 |
* Get dasboard chart from response data
|
670 |
*
|
@@ -804,7 +817,7 @@ class Ga_Stats {
|
|
804 |
*
|
805 |
* @param array $data Analytics response data
|
806 |
*
|
807 |
-
* @return array sources data
|
808 |
*/
|
809 |
public static function get_sources( $data ) {
|
810 |
if ( !empty( $data ) ) {
|
@@ -896,6 +909,11 @@ class Ga_Stats {
|
|
896 |
}
|
897 |
}
|
898 |
|
|
|
|
|
|
|
|
|
|
|
899 |
public static function get_empty_boxes_structure() {
|
900 |
$boxes_data = array();
|
901 |
$boxes_data[ 'Sessions' ] = array(
|
10 |
*/
|
11 |
class Ga_Stats {
|
12 |
|
13 |
+
private $profile = array();
|
14 |
|
15 |
/**
|
16 |
* Primary class constructor.
|
19 |
* @since 7.0.0
|
20 |
*/
|
21 |
public function __construct() {
|
|
|
22 |
}
|
23 |
|
24 |
/**
|
36 |
return self::main_chart_query( $id_view, $date_range, $metric );
|
37 |
} elseif ( $query == 'gender' ) {
|
38 |
return self::gender_chart_query($id_view, $date_range, $metric);
|
39 |
+
} elseif ( $query == 'device' ) {
|
40 |
+
return self::device_chart_query($id_view, $date_range, $metric);
|
41 |
} elseif ( $query == 'age' ) {
|
42 |
return self::age_chart_query($id_view, $date_range, $metric);
|
43 |
} elseif ( $query == 'boxes' ) {
|
45 |
} elseif ( $query == 'dashboard_boxes' ) {
|
46 |
return self::dashboard_boxes_query( $id_view, $date_range );
|
47 |
} elseif ( $query == 'sources' ) {
|
48 |
+
return self::sources_query( $id_view, $date_range );
|
49 |
} else {
|
50 |
return array();
|
51 |
}
|
55 |
* Preparing query for top traffic sources table
|
56 |
*
|
57 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
58 |
+
* @param array $date_ranges An array representing the date ranges that will be passed to chart query.
|
59 |
* @return array Sources query
|
60 |
*/
|
61 |
+
public static function sources_query( $id_view, $date_ranges ) {
|
62 |
+
$reports_requests = array();
|
|
|
63 |
|
64 |
if ( isset( $_GET['ts'] ) ) {
|
65 |
$reports_requests[] = array(
|
66 |
'viewId' => $id_view,
|
67 |
+
'dateRanges' => $date_ranges,
|
68 |
'metrics' => self::set_metrics( array( 'ga:pageviews' ) ),
|
69 |
'includeEmptyRows' => true,
|
70 |
'pageSize' => 10,
|
74 |
} else {
|
75 |
$reports_requests[] = array(
|
76 |
'viewId' => $id_view,
|
77 |
+
'dateRanges' => $date_ranges,
|
78 |
'metrics' => self::set_metrics( array(
|
79 |
'ga:pageviews',
|
80 |
'ga:uniquePageviews',
|
101 |
* Preparing query for dashbord boxes
|
102 |
*
|
103 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
104 |
+
* @param array $date_ranges An array representing the date ranges that will be passed to chart query.
|
105 |
*
|
106 |
* @return array Dashboard boxes query
|
107 |
*/
|
108 |
+
public static function dashboard_boxes_query( $id_view, $date_ranges ) {
|
109 |
+
$reports_requests = array();
|
|
|
110 |
|
111 |
if ( isset( $_GET['ts'] ) ) {
|
112 |
$reports_requests[] = array(
|
113 |
'viewId' => $id_view,
|
114 |
+
'dateRanges' => $date_ranges,
|
115 |
'metrics' => self::set_metrics( array( 'ga:pageviews' ) ),
|
116 |
'includeEmptyRows' => true,
|
117 |
'pageSize' => 10,
|
121 |
} else {
|
122 |
$reports_requests[] = array(
|
123 |
'viewId' => $id_view,
|
124 |
+
'dateRanges' => $date_ranges,
|
125 |
'metrics' => self::set_metrics( array(
|
126 |
'ga:pageviews',
|
127 |
'ga:uniquePageviews',
|
178 |
* Preparing query for chart
|
179 |
*
|
180 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
181 |
+
* @param array $date_ranges An array representing the date ranges that will be passed to chart query.
|
182 |
* @param string $metric A metric expression
|
183 |
*
|
184 |
* @return array Chart query
|
185 |
*/
|
186 |
+
public static function main_chart_query( $id_view, $date_ranges = null, $metric = null ) {
|
187 |
+
if ( true === empty( $metric ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
$metric = 'ga:pageviews';
|
189 |
} else {
|
190 |
$metric = 'ga:' . $metric;
|
209 |
* Preparing query for gender chart
|
210 |
*
|
211 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
212 |
+
* @param array $date_ranges An array representing the date ranges that will be passed to chart query.
|
213 |
* @param string $metric A metric expression
|
214 |
*
|
215 |
* @return array Chart query
|
216 |
*/
|
217 |
+
public static function gender_chart_query( $id_view, $date_ranges = null, $metric = null ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
$reports_requests = array();
|
219 |
$reports_requests[] = array(
|
220 |
'viewId' => $id_view,
|
230 |
return $query;
|
231 |
}
|
232 |
|
233 |
+
/**
|
234 |
+
* Preparing query for device chart.
|
235 |
+
*
|
236 |
+
* @param int $id_view The Analytics view ID from which to retrieve data.
|
237 |
+
* @param array $date_ranges An array representing the date ranges that will be passed to chart query.
|
238 |
+
* @param string $metric A metric expression
|
239 |
+
*
|
240 |
+
* @return array Chart query
|
241 |
+
* @since 2.5.2
|
242 |
+
*/
|
243 |
+
public static function device_chart_query( $id_view, $date_ranges = null, $metric = null ) {
|
244 |
+
return array(
|
245 |
+
'reportRequests' => array(
|
246 |
+
array(
|
247 |
+
'viewId' => $id_view,
|
248 |
+
'dateRanges' => $date_ranges,
|
249 |
+
'metrics' => self::set_metrics( 'ga:sessions' ),
|
250 |
+
'includeEmptyRows' => true,
|
251 |
+
'dimensions' => self::set_dimensions( 'ga:deviceCategory' )
|
252 |
+
)
|
253 |
+
)
|
254 |
+
);
|
255 |
+
}
|
256 |
+
|
257 |
/**
|
258 |
* Preparing query for age chart
|
259 |
*
|
260 |
* @param int $id_view The Analytics view ID from which to retrieve data.
|
261 |
+
* @param array $date_ranges An array representing the date ranges that will be passed to chart query.
|
262 |
* @param string $metric A metric expression
|
263 |
*
|
264 |
* @return array Chart query
|
265 |
*/
|
266 |
+
public static function age_chart_query( $id_view, $date_ranges = null, $metric = null ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
$reports_requests = array();
|
268 |
$reports_requests[] = array(
|
269 |
'viewId' => $id_view,
|
351 |
$date_danges = array();
|
352 |
$date_danges[] = array(
|
353 |
'startDate' => $start_date,
|
354 |
+
'endDate' => $end_date,
|
355 |
);
|
356 |
if ( !empty( $prev_start_date ) and ! empty( $prev_end_date ) ) {
|
357 |
$date_danges[] = array(
|
358 |
'startDate' => $prev_start_date,
|
359 |
+
'endDate' => $prev_end_date,
|
360 |
);
|
361 |
}
|
362 |
|
388 |
*
|
389 |
* @param array $row Analytics response row
|
390 |
*
|
391 |
+
* @return array|bool Dimensions
|
392 |
*/
|
393 |
public static function get_dimensions( $row ) {
|
394 |
if ( !empty( $row[ 'dimensions' ] ) ) {
|
403 |
*
|
404 |
* @param array $row Analytics response row
|
405 |
*
|
406 |
+
* @return array|bool Metrics
|
407 |
*/
|
408 |
public static function get_metrics( $row ) {
|
409 |
if ( !empty( $row[ 'metrics' ] ) ) {
|
418 |
*
|
419 |
* @param array $report_data Analytics response report data
|
420 |
*
|
421 |
+
* @return array|bool Rows
|
422 |
*/
|
423 |
public static function get_rows( $report_data ) {
|
424 |
if ( !empty( $report_data[ 'rows' ] ) ) {
|
433 |
*
|
434 |
* @param array $report_data Analytics response report data
|
435 |
*
|
436 |
+
* @return array|bool Row count
|
437 |
*/
|
438 |
public static function get_row_count( $report_data ) {
|
439 |
if ( !empty( $report_data[ 'rowCount' ] ) ) {
|
448 |
*
|
449 |
* @param array $report_data Analytics response report data
|
450 |
*
|
451 |
+
* @return array|bool Totals
|
452 |
*/
|
453 |
public static function get_totals( $report_data ) {
|
454 |
if ( !empty( $report_data[ 'totals' ] ) ) {
|
463 |
*
|
464 |
* @param array $data Analytics response data
|
465 |
*
|
466 |
+
* @return array|bool Reports
|
467 |
*/
|
468 |
public static function get_reports_from_response( $data ) {
|
469 |
if ( !empty( $data[ 'reports' ] ) ) {
|
502 |
*
|
503 |
* @param array $data Analytics response data
|
504 |
*
|
505 |
+
* @return array|bool Report
|
506 |
*/
|
507 |
public static function get_single_report( $data ) {
|
508 |
if ( !empty( $data ) ) {
|
521 |
*
|
522 |
* @param array $rows Analytics response data rows
|
523 |
*
|
524 |
+
* @return array|bool Row
|
525 |
*/
|
526 |
public static function get_single_row( $rows ) {
|
527 |
if ( !empty( $rows ) ) {
|
572 |
*
|
573 |
* @return array chart data
|
574 |
*/
|
575 |
+
public static function get_chart( $response_data, $period_in_days = 7 ) {
|
576 |
$chart_data = array();
|
577 |
+
if ( ! empty( $response_data ) ) {
|
578 |
+
$data = ( ! empty( $response_data['reports'] ) && ! empty( $response_data['reports'][0] ) && ! empty( $response_data['reports'][0]['data'] ) ) ? $response_data['reports'][0]['data'] : array();
|
579 |
+
$rows = ( ! empty( $data['rows'] ) ) ? $data['rows'] : array();
|
580 |
+
if ( ! empty( $rows ) ) {
|
581 |
foreach ( $rows as $key => $row ) {
|
582 |
+
if ( $key < $period_in_days ) {
|
583 |
+
$chart_data[ $key ]['previous'] = ! empty( $row['metrics'][1]['values'][0] ) ? $row['metrics'][1]['values'][0] : 0;
|
584 |
+
$chart_data[ $key ]['previous-day'] = date( 'M j', strtotime( $row['dimensions'][0] ) );
|
585 |
} else {
|
586 |
+
$chart_data[ $key - $period_in_days ]['day'] = date( 'M j', strtotime( $row['dimensions'][0] ) );
|
587 |
+
$chart_data[ $key - $period_in_days ]['current'] = ! empty( $row['metrics'][0]['values'][0] ) ? $row['metrics'][0]['values'][0] : 0;
|
588 |
+
$chart_data['date'] = strtotime( $row['dimensions'][0] );
|
589 |
}
|
590 |
}
|
591 |
}
|
608 |
$rows = (!empty( $data[ 'rows' ] ) ) ? $data[ 'rows' ] : array();
|
609 |
if ( !empty( $rows ) ) {
|
610 |
foreach ( $rows as $key => $row ) {
|
611 |
+
$chart_data[$row['dimensions'][0]] = self::get_metric_value($row['metrics']);
|
612 |
}
|
613 |
}
|
614 |
}
|
617 |
}
|
618 |
|
619 |
/**
|
620 |
+
* Get device chart from response data.
|
621 |
+
*
|
622 |
+
* @param array $response_data Analytics response data array.
|
623 |
+
*
|
624 |
+
* @return array Chart data array.
|
625 |
+
*/
|
626 |
+
public static function get_device_chart( $response_data ) {
|
627 |
+
$chart_data = [];
|
628 |
+
if ( false === empty( $response_data ) ) {
|
629 |
+
$data = (false === empty( $response_data[ 'reports' ] ) && !empty( $response_data[ 'reports' ][ 0 ] ) && !empty( $response_data[ 'reports' ][ 0 ][ 'data' ] ) ) ? $response_data[ 'reports' ][ 0 ][ 'data' ] : array();
|
630 |
+
$rows = ( false === empty( $data['rows'] ) ) ? $data['rows'] : array();
|
631 |
+
if ( false === empty( $rows ) ) {
|
632 |
+
foreach ( $rows as $row ) {
|
633 |
+
$chart_data[$row['dimensions'][0]] = self::get_metric_value($row['metrics']);
|
634 |
+
}
|
635 |
+
}
|
636 |
+
}
|
637 |
+
|
638 |
+
return $chart_data;
|
639 |
+
}
|
640 |
+
|
641 |
+
/**
|
642 |
+
* Get the value of metric data response.
|
643 |
*
|
644 |
* @param $metrics
|
645 |
+
*
|
646 |
+
* @return mixed
|
647 |
*/
|
648 |
+
private static function get_metric_value($metrics)
|
649 |
{
|
650 |
if (is_array($metrics)) {
|
651 |
foreach($metrics as $metric) {
|
670 |
$rows = (!empty( $data[ 'rows' ] ) ) ? $data[ 'rows' ] : array();
|
671 |
if ( !empty( $rows ) ) {
|
672 |
foreach ( $rows as $key => $row ) {
|
673 |
+
$chart_data[$row['dimensions'][0]] = self::get_metric_value($row['metrics']);
|
674 |
}
|
675 |
}
|
676 |
}
|
678 |
return $chart_data;
|
679 |
}
|
680 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
681 |
/**
|
682 |
* Get dasboard chart from response data
|
683 |
*
|
817 |
*
|
818 |
* @param array $data Analytics response data
|
819 |
*
|
820 |
+
* @return array|bool sources data
|
821 |
*/
|
822 |
public static function get_sources( $data ) {
|
823 |
if ( !empty( $data ) ) {
|
909 |
}
|
910 |
}
|
911 |
|
912 |
+
/**
|
913 |
+
* Get Empty Boxes Structure.
|
914 |
+
*
|
915 |
+
* @return array Array of empty boxes structure values.
|
916 |
+
*/
|
917 |
public static function get_empty_boxes_structure() {
|
918 |
$boxes_data = array();
|
919 |
$boxes_data[ 'Sessions' ] = array(
|
class/Ga_Template.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Ga_Template
|
5 |
+
*/
|
6 |
+
class Ga_Template {
|
7 |
+
/**
|
8 |
+
* @var array Array of template properties.
|
9 |
+
*/
|
10 |
+
protected $props;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var string Relative path in view/ folder.
|
14 |
+
*/
|
15 |
+
protected $path;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Ga_Template constructor.
|
19 |
+
*
|
20 |
+
* @param string $path Relative path in view/ folder.
|
21 |
+
* @param array $props Array of props to be passed to the template.
|
22 |
+
*/
|
23 |
+
public function __construct( $path, $props = [] ) {
|
24 |
+
$this->path = $path;
|
25 |
+
$this->props = $props;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Include rendered template inline.
|
30 |
+
*
|
31 |
+
* @param string $path Relative path in view/ folder.
|
32 |
+
* @param array $props Array of props to be passed to the template.
|
33 |
+
*/
|
34 |
+
public static function load( $path, $props = [] ) {
|
35 |
+
( new static( $path, $props ) )->includeTemplate();
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Get rendered template.
|
40 |
+
*
|
41 |
+
* @param string $path Relative path in view/ folder.
|
42 |
+
* @param array $props Array of props to be passed to the template.
|
43 |
+
*
|
44 |
+
* @return string Rendered template.
|
45 |
+
*/
|
46 |
+
public static function render( $path, $props = [] ) {
|
47 |
+
return ( new static( $path, $props ) )->renderTemplate();
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Include template.
|
52 |
+
*/
|
53 |
+
public function includeTemplate() {
|
54 |
+
$template_path = GA_PLUGIN_DIR . '/view/' . $this->path . '.php';
|
55 |
+
|
56 |
+
if ( is_readable( $template_path ) ) {
|
57 |
+
load_template( $template_path, false, $this->props );
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Get rendered template.
|
63 |
+
*
|
64 |
+
* @return string
|
65 |
+
*/
|
66 |
+
public function renderTemplate() {
|
67 |
+
ob_start();
|
68 |
+
$this->includeTemplate();
|
69 |
+
$render = ob_get_contents();
|
70 |
+
|
71 |
+
return $render ?: '';
|
72 |
+
}
|
73 |
+
}
|
css/googleanalytics.css
CHANGED
@@ -44,7 +44,9 @@
|
|
44 |
margin: 10px 5px 10px 0;
|
45 |
}
|
46 |
|
47 |
-
.ga_container .filter-choices a
|
|
|
|
|
48 |
background: #f9f9f9;
|
49 |
width: 105px;
|
50 |
display: inline-block;
|
@@ -58,11 +60,16 @@
|
|
58 |
color: #888888;
|
59 |
}
|
60 |
|
61 |
-
.ga_container .filter-choices a.selected
|
|
|
62 |
background: #c6dafc;
|
63 |
color: #353535;
|
64 |
}
|
65 |
|
|
|
|
|
|
|
|
|
66 |
#exTab1, #exTab2 {
|
67 |
margin-right: 15px !important;
|
68 |
}
|
44 |
margin: 10px 5px 10px 0;
|
45 |
}
|
46 |
|
47 |
+
.ga_container .filter-choices a,
|
48 |
+
.ga_container .filter-choices button
|
49 |
+
{
|
50 |
background: #f9f9f9;
|
51 |
width: 105px;
|
52 |
display: inline-block;
|
60 |
color: #888888;
|
61 |
}
|
62 |
|
63 |
+
.ga_container .filter-choices a.selected,
|
64 |
+
.ga_container .filter-choices button {
|
65 |
background: #c6dafc;
|
66 |
color: #353535;
|
67 |
}
|
68 |
|
69 |
+
.ga_container .filter-choices button {
|
70 |
+
padding: 5px 20px;
|
71 |
+
}
|
72 |
+
|
73 |
#exTab1, #exTab2 {
|
74 |
margin-right: 15px !important;
|
75 |
}
|
googleanalytics.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: ShareThis Dashboard for Google Analytics
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/googleanalytics/
|
5 |
* Description: Use Google Analytics on your WordPress site without touching any code, and view visitor reports right in your WordPress admin dashboard!
|
6 |
-
* Version: 2.5.
|
7 |
* Author: ShareThis
|
8 |
* Author URI: http://sharethis.com
|
9 |
*/
|
@@ -46,7 +46,7 @@ if ( !preg_match( '/(\/|\\\)' . GA_NAME . '(\/|\\\)/', realpath( __FILE__ ), $te
|
|
46 |
die();
|
47 |
}
|
48 |
|
49 |
-
define( 'GOOGLEANALYTICS_VERSION', '2.5.
|
50 |
include_once GA_PLUGIN_DIR . '/overwrite/ga_overwrite.php';
|
51 |
include_once GA_PLUGIN_DIR . '/class/Ga_Autoloader.php';
|
52 |
include_once GA_PLUGIN_DIR . '/tools/class-support-logging.php';
|
3 |
* Plugin Name: ShareThis Dashboard for Google Analytics
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/googleanalytics/
|
5 |
* Description: Use Google Analytics on your WordPress site without touching any code, and view visitor reports right in your WordPress admin dashboard!
|
6 |
+
* Version: 2.5.2
|
7 |
* Author: ShareThis
|
8 |
* Author URI: http://sharethis.com
|
9 |
*/
|
46 |
die();
|
47 |
}
|
48 |
|
49 |
+
define( 'GOOGLEANALYTICS_VERSION', '2.5.2' );
|
50 |
include_once GA_PLUGIN_DIR . '/overwrite/ga_overwrite.php';
|
51 |
include_once GA_PLUGIN_DIR . '/class/Ga_Autoloader.php';
|
52 |
include_once GA_PLUGIN_DIR . '/tools/class-support-logging.php';
|
js/googleanalytics_page.js
CHANGED
@@ -218,7 +218,7 @@ const GA_AUTHENTICATION_CODE_ERROR = 'That looks like your Google Analytics Trac
|
|
218 |
publisherPurposes = [],
|
219 |
display = $( '#sharethis-user-type option:selected' ).val(),
|
220 |
name = $( '#sharethis-publisher-name' ).val(),
|
221 |
-
scope =
|
222 |
color = $( '#sharethis-form-color .color.selected' ).attr('data-value'),
|
223 |
publisherRestrictions = {},
|
224 |
language = $( '#st-language' ).val();
|
@@ -525,6 +525,7 @@ const GA_AUTHENTICATION_CODE_ERROR = 'That looks like your Google Analytics Trac
|
|
525 |
const minWidth = 350;
|
526 |
const wrapperSelector = '#ga-stats-container';
|
527 |
const chartContainer = 'chart_div';
|
|
|
528 |
const demoChartGenderContainer = 'demo_chart_gender_div';
|
529 |
const demoChartAgeContainer = 'demo_chart_age_div';
|
530 |
|
@@ -606,6 +607,20 @@ const GA_AUTHENTICATION_CODE_ERROR = 'That looks like your Google Analytics Trac
|
|
606 |
|
607 |
chart.draw(data, options);
|
608 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
609 |
|
610 |
drawDemoAgeChart: function (data, chartWidth) {
|
611 |
if (typeof chartWidth == 'undefined') {
|
218 |
publisherPurposes = [],
|
219 |
display = $( '#sharethis-user-type option:selected' ).val(),
|
220 |
name = $( '#sharethis-publisher-name' ).val(),
|
221 |
+
scope = 'publisher',
|
222 |
color = $( '#sharethis-form-color .color.selected' ).attr('data-value'),
|
223 |
publisherRestrictions = {},
|
224 |
language = $( '#st-language' ).val();
|
525 |
const minWidth = 350;
|
526 |
const wrapperSelector = '#ga-stats-container';
|
527 |
const chartContainer = 'chart_div';
|
528 |
+
const demoChartDeviceContainer = 'demo_chart_device_div';
|
529 |
const demoChartGenderContainer = 'demo_chart_gender_div';
|
530 |
const demoChartAgeContainer = 'demo_chart_age_div';
|
531 |
|
607 |
|
608 |
chart.draw(data, options);
|
609 |
},
|
610 |
+
drawDemoDeviceChart: function (data, chartWidth) {
|
611 |
+
if (typeof chartWidth == 'undefined') {
|
612 |
+
chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
|
613 |
+
}
|
614 |
+
|
615 |
+
data = google.visualization.arrayToDataTable(data);
|
616 |
+
|
617 |
+
var chart = new google.visualization.PieChart(document.getElementById(demoChartDeviceContainer));
|
618 |
+
var options = {
|
619 |
+
title: 'Device Breakdown'
|
620 |
+
};
|
621 |
+
|
622 |
+
chart.draw(data, options);
|
623 |
+
},
|
624 |
|
625 |
drawDemoAgeChart: function (data, chartWidth) {
|
626 |
if (typeof chartWidth == 'undefined') {
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== ShareThis Dashboard for Google Analytics ===
|
2 |
-
Contributors: sharethis, scottstorebloom
|
3 |
Tags: analytics, google analytics, google analytics plugin, google analytics widget, google analytics dashboard
|
4 |
-
Requires at least:
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag: 2.5.
|
7 |
|
8 |
Use Google Analytics on your Wordpress site without touching any code, and view visitor reports right in your Wordpress admin dashboard!
|
9 |
|
@@ -114,6 +114,12 @@ If you’re using Google Analytics on your WordPress website or a plugin like th
|
|
114 |
|
115 |
== Changelog ==
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
= 2.5.1 =
|
118 |
* Revert array syntax for back compat.
|
119 |
* Update plugin name for trademark infringement.
|
1 |
=== ShareThis Dashboard for Google Analytics ===
|
2 |
+
Contributors: sharethis, scottstorebloom, scottmweaver
|
3 |
Tags: analytics, google analytics, google analytics plugin, google analytics widget, google analytics dashboard
|
4 |
+
Requires at least: 5.2
|
5 |
+
Tested up to: 5.8
|
6 |
+
Stable tag: 2.5.2
|
7 |
|
8 |
Use Google Analytics on your Wordpress site without touching any code, and view visitor reports right in your Wordpress admin dashboard!
|
9 |
|
114 |
|
115 |
== Changelog ==
|
116 |
|
117 |
+
= 2.5.2
|
118 |
+
* Add custom date range selector instead of 7/30-day selector.
|
119 |
+
* Add device breakdown under demographics section.
|
120 |
+
* Fix security issue for URL in admin.
|
121 |
+
* Fix vendors list URL.
|
122 |
+
|
123 |
= 2.5.1 =
|
124 |
* Revert array syntax for back compat.
|
125 |
* Update plugin name for trademark infringement.
|
view/ga_notice.php
CHANGED
@@ -1,11 +1,16 @@
|
|
|
|
|
|
|
|
1 |
<div id="googleanalytics_terms_notice"
|
2 |
-
class="notice notice-warning <?php echo
|
3 |
<p>
|
4 |
-
Google Analytics <?php echo esc_html(
|
5 |
href="http://www.sharethis.com/news/2016/12/sharethis-adds-analytics-plugin-to-suite-of-tools/"
|
6 |
-
target="_blank">has joined the ShareThis family.</a> <strong>A host of new features</strong> have been
|
7 |
-
|
|
|
|
|
8 |
href="http://www.sharethis.com/publisher-terms-of-use/" target="_blank">terms of use</a> to enable them.
|
9 |
-
<a href="<?php echo esc_url(
|
10 |
</p>
|
11 |
</div>
|
1 |
+
<?php
|
2 |
+
$url = isset($url) ? $url : '';
|
3 |
+
?>
|
4 |
<div id="googleanalytics_terms_notice"
|
5 |
+
class="notice notice-warning <?php echo Ga_Helper::is_plugin_page() ? '' : 'is-dismissible'; ?>">
|
6 |
<p>
|
7 |
+
Google Analytics <?php echo esc_html(GOOGLEANALYTICS_VERSION); ?> plugin <a
|
8 |
href="http://www.sharethis.com/news/2016/12/sharethis-adds-analytics-plugin-to-suite-of-tools/"
|
9 |
+
target="_blank">has joined the ShareThis family.</a> <strong>A host of new features</strong> have been
|
10 |
+
added in this version, including Google Analytics dashboards, demographics and device data.
|
11 |
+
The update requires agreeing to the <a href="http://www.sharethis.com/privacy/" target="_blank">privacy
|
12 |
+
policy</a> and <a
|
13 |
href="http://www.sharethis.com/publisher-terms-of-use/" target="_blank">terms of use</a> to enable them.
|
14 |
+
<a href="<?php echo esc_url($url); ?>"><span class="button button-primary">I accept</span></a>
|
15 |
</p>
|
16 |
</div>
|
view/stats.php
CHANGED
@@ -14,21 +14,22 @@ foreach ( $account_data as $properties ) {
|
|
14 |
|
15 |
$demo_enabled = get_option('googleanalytics_demographic');
|
16 |
$demo_enabled = !empty($demo_enabled) && $demo_enabled ? true: false;
|
17 |
-
$sevenorthirty = isset($_GET['th']) ? '30' : '7';
|
18 |
-
$selected7 = '7' === $sevenorthirty ? 'selected' : '';
|
19 |
-
$selected30 = '30' === $sevenorthirty ? 'selected' : '';
|
20 |
$selectedpage = isset($_GET['ts']) ? '' : 'selected';
|
21 |
$selectedsource = isset($_GET['ts']) ? 'selected' : '';
|
22 |
$report_url = 'https://analytics.google.com/analytics/web/#/report/content-pages/a' . $selected_data[0] . 'w' . $internal_prop . 'p' . $selected_data[2];
|
23 |
$source_page_url = isset($_GET['ts']) ? str_replace('content-pages', 'trafficsources-all-traffic', $report_url) : $report_url;
|
24 |
$demographic_page_url = str_replace('content-pages', 'visitors-demographics-overview', $report_url);
|
25 |
$type_label = isset($_GET['ts']) ? 'Traffic Sources' : 'Pages/Posts';
|
26 |
-
$
|
27 |
-
$seven_url = isset($_GET['ts']) ? 'admin.php?page=googleanalytics&ts' : 'admin.php?page=googleanalytics';
|
28 |
-
$source_url = isset($_GET['th']) ? 'admin.php?page=googleanalytics&ts&th' : 'admin.php?page=googleanalytics&ts';
|
29 |
-
$page_view_url = isset($_GET['th']) ? 'admin.php?page=googleanalytics&th' : 'admin.php?page=googleanalytics';
|
30 |
$send_data = get_option('googleanalytics_send_data');
|
31 |
$need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
?>
|
33 |
<?php if (!$demo_enabled) {
|
34 |
echo Ga_Helper::ga_wp_notice(
|
@@ -37,24 +38,24 @@ $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
|
37 |
false,
|
38 |
[
|
39 |
'url' => Ga_Helper::create_url( Ga_Helper::get_current_url(), array( Ga_Controller_Core::ACTION_PARAM_NAME => 'demo-ad' ) ),
|
40 |
-
'label' => __( 'Access Now' ),
|
41 |
]
|
42 |
);
|
43 |
} ?>
|
44 |
-
<div class="wrap ga-wrap" id="ga-stats-container" data-scroll="<?php echo
|
45 |
<?php if ( ! empty( $chart ) ) : ?>
|
46 |
<div class="filter-choices">
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
</div>
|
54 |
<div class="ga-panel ga-panel-default">
|
55 |
<div class="ga-panel-heading">
|
56 |
<strong>
|
57 |
-
<?php echo 'Pageviews -
|
58 |
</strong>
|
59 |
</div>
|
60 |
<div class="ga-panel-body ga-chart">
|
@@ -68,7 +69,7 @@ $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
|
68 |
|
69 |
<?php if ( ! empty( $boxes ) ) : ?>
|
70 |
<div class="ga-panel ga-panel-default">
|
71 |
-
<div class="ga-panel-heading"><strong><?php echo 'Comparison -
|
72 |
</div>
|
73 |
<div class="ga-panel-body">
|
74 |
<div class="ga-row">
|
@@ -95,10 +96,10 @@ $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
|
95 |
|
96 |
if ( ! empty( $sources ) ) : ?>
|
97 |
<div class="filter-choices">
|
98 |
-
<a href="<?php echo get_admin_url('',
|
99 |
Page View
|
100 |
</a>
|
101 |
-
<a href="<?php echo get_admin_url('',
|
102 |
Traffic Source
|
103 |
</a>
|
104 |
</div>
|
@@ -177,9 +178,6 @@ $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
|
177 |
<?php endif; ?>
|
178 |
|
179 |
<?php if ( ! empty( $chart ) ) :
|
180 |
-
|
181 |
-
$label_count = isset($_GET['th']) ? $labels['thisMonth'] : $labels['thisWeek'];
|
182 |
-
|
183 |
?>
|
184 |
<script type="text/javascript">
|
185 |
|
@@ -189,8 +187,8 @@ $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
|
189 |
var demoGenderData = new google.visualization.DataTable();
|
190 |
var demoAgeData = new google.visualization.DataTable();
|
191 |
|
192 |
-
data.addColumn('string', 'Day');
|
193 |
-
data.addColumn('number', '<?php echo
|
194 |
data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
|
195 |
|
196 |
<?php foreach ( $chart as $row ) : ?>
|
@@ -221,6 +219,23 @@ $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
|
221 |
$x++;
|
222 |
} ?>
|
223 |
ga_charts.drawDemoAgeChart(<?php echo json_encode($demoAgeData); ?>);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
ga_loader.hide();
|
225 |
|
226 |
<?php if (Ga_Helper::are_features_enabled() && !empty($send_data) && "true" === $send_data) : ?>
|
14 |
|
15 |
$demo_enabled = get_option('googleanalytics_demographic');
|
16 |
$demo_enabled = !empty($demo_enabled) && $demo_enabled ? true: false;
|
|
|
|
|
|
|
17 |
$selectedpage = isset($_GET['ts']) ? '' : 'selected';
|
18 |
$selectedsource = isset($_GET['ts']) ? 'selected' : '';
|
19 |
$report_url = 'https://analytics.google.com/analytics/web/#/report/content-pages/a' . $selected_data[0] . 'w' . $internal_prop . 'p' . $selected_data[2];
|
20 |
$source_page_url = isset($_GET['ts']) ? str_replace('content-pages', 'trafficsources-all-traffic', $report_url) : $report_url;
|
21 |
$demographic_page_url = str_replace('content-pages', 'visitors-demographics-overview', $report_url);
|
22 |
$type_label = isset($_GET['ts']) ? 'Traffic Sources' : 'Pages/Posts';
|
23 |
+
$source_url = 'admin.php?page=googleanalytics&ts';
|
|
|
|
|
|
|
24 |
$send_data = get_option('googleanalytics_send_data');
|
25 |
$need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
|
26 |
+
|
27 |
+
// Filter GA Action.
|
28 |
+
$ga_action = filter_input( INPUT_GET, 'ga_action', FILTER_SANITIZE_STRING );
|
29 |
+
|
30 |
+
$date_range = Ga_Helper::getDateRangeFromRequest();
|
31 |
+
|
32 |
+
$days_in_english = Ga_Helper::getPeriodInDaysWords($date_range['from'], $date_range['to']);
|
33 |
?>
|
34 |
<?php if (!$demo_enabled) {
|
35 |
echo Ga_Helper::ga_wp_notice(
|
38 |
false,
|
39 |
[
|
40 |
'url' => Ga_Helper::create_url( Ga_Helper::get_current_url(), array( Ga_Controller_Core::ACTION_PARAM_NAME => 'demo-ad' ) ),
|
41 |
+
'label' => __( 'Access Now', 'googleanalytics' ),
|
42 |
]
|
43 |
);
|
44 |
} ?>
|
45 |
+
<div class="wrap ga-wrap" id="ga-stats-container" data-scroll="<?php echo esc_attr($ga_action); ?>">
|
46 |
<?php if ( ! empty( $chart ) ) : ?>
|
47 |
<div class="filter-choices">
|
48 |
+
<div>
|
49 |
+
<?php Ga_Template::load( 'templates/date_custom_range_filter', [
|
50 |
+
'date_from' => $date_range['from'],
|
51 |
+
'date_to' => $date_range['to']
|
52 |
+
] ); ?>
|
53 |
+
</div>
|
54 |
</div>
|
55 |
<div class="ga-panel ga-panel-default">
|
56 |
<div class="ga-panel-heading">
|
57 |
<strong>
|
58 |
+
<?php echo 'Pageviews - ' . $days_in_english; ?>
|
59 |
</strong>
|
60 |
</div>
|
61 |
<div class="ga-panel-body ga-chart">
|
69 |
|
70 |
<?php if ( ! empty( $boxes ) ) : ?>
|
71 |
<div class="ga-panel ga-panel-default">
|
72 |
+
<div class="ga-panel-heading"><strong><?php echo 'Comparison - ' . $days_in_english; ?></strong>
|
73 |
</div>
|
74 |
<div class="ga-panel-body">
|
75 |
<div class="ga-row">
|
96 |
|
97 |
if ( ! empty( $sources ) ) : ?>
|
98 |
<div class="filter-choices">
|
99 |
+
<a href="<?php echo get_admin_url('', 'admin.php?page=googleanalytics'); ?>" class="<?php echo esc_attr( $selectedpage ); ?>">
|
100 |
Page View
|
101 |
</a>
|
102 |
+
<a href="<?php echo get_admin_url('', 'admin.php?page=googleanalytics&ts'); ?>" class="<?php echo esc_attr( $selectedsource ); ?>">
|
103 |
Traffic Source
|
104 |
</a>
|
105 |
</div>
|
178 |
<?php endif; ?>
|
179 |
|
180 |
<?php if ( ! empty( $chart ) ) :
|
|
|
|
|
|
|
181 |
?>
|
182 |
<script type="text/javascript">
|
183 |
|
187 |
var demoGenderData = new google.visualization.DataTable();
|
188 |
var demoAgeData = new google.visualization.DataTable();
|
189 |
|
190 |
+
data.addColumn('string', '<?php echo esc_js( __( 'Day', 'googleanalytics' ) ); ?>');
|
191 |
+
data.addColumn('number', '<?php echo esc_js( __( 'Pageviews', 'googleanalytics' ) ); ?>');
|
192 |
data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
|
193 |
|
194 |
<?php foreach ( $chart as $row ) : ?>
|
219 |
$x++;
|
220 |
} ?>
|
221 |
ga_charts.drawDemoAgeChart(<?php echo json_encode($demoAgeData); ?>);
|
222 |
+
|
223 |
+
// Device chart.
|
224 |
+
<?php
|
225 |
+
$demoDeviceData = array();
|
226 |
+
$demoDeviceData[0] = array(
|
227 |
+
__( 'Device', 'googleanalytics' ),
|
228 |
+
__( 'Device Breakdown', 'googleanalytics' ),
|
229 |
+
);
|
230 |
+
|
231 |
+
$x = 1;
|
232 |
+
foreach( $device_chart as $type => $amount ) {
|
233 |
+
$demoDeviceData[$x] = array($type, intval($amount));
|
234 |
+
$x++;
|
235 |
+
}
|
236 |
+
?>
|
237 |
+
ga_charts.drawDemoDeviceChart(<?php echo json_encode($demoDeviceData); ?>);
|
238 |
+
|
239 |
ga_loader.hide();
|
240 |
|
241 |
<?php if (Ga_Helper::are_features_enabled() && !empty($send_data) && "true" === $send_data) : ?>
|
view/templates/date_custom_range_filter.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Custom Date Range Filter template.
|
4 |
+
*/
|
5 |
+
$args = isset($args) ? $args : [];
|
6 |
+
|
7 |
+
$props = wp_parse_args($args, [
|
8 |
+
'date_from' => date('Y-m-d', strtotime('-1 week')),
|
9 |
+
'date_to' => date('Y-m-d'),
|
10 |
+
]);
|
11 |
+
|
12 |
+
$date_from = false === empty($props['date_from']) ? $props['date_from'] : date('Y-m-d', strtotime('-1 week'));
|
13 |
+
$date_to = false === empty($props['date_to']) ? $props['date_to'] : date('Y-m-d');
|
14 |
+
?>
|
15 |
+
<form action="<?php echo esc_url(admin_url('admin.php')); ?>" method="GET">
|
16 |
+
<input type="hidden" name="page" value="googleanalytics"/>
|
17 |
+
<label>
|
18 |
+
<?php esc_html_e('From:', 'googleanalytics'); ?>
|
19 |
+
<input name="date_from" type="date" value="<?php echo esc_attr($date_from); ?>">
|
20 |
+
</label>
|
21 |
+
<label>
|
22 |
+
<?php esc_html_e('To:', 'googleanalytics'); ?>
|
23 |
+
<input name="date_to" type="date" value="<?php echo esc_attr($date_to); ?>">
|
24 |
+
</label>
|
25 |
+
<button><?php esc_html_e('Filter', 'googleanalytics'); ?></button>
|
26 |
+
</form>
|
view/templates/demographic-chart.php
CHANGED
@@ -8,29 +8,37 @@
|
|
8 |
</button>
|
9 |
</strong>
|
10 |
</div>
|
11 |
-
<img src="<?php echo trailingslashit(get_home_url()) . 'wp-content/plugins/googleanalytics/assets/images/
|
12 |
</div>
|
13 |
<?php elseif ($need_account_demo_enable) : ?>
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
<?php else: ?>
|
27 |
<div class="filter-choices">
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
30 days
|
33 |
-
</a>
|
34 |
</div>
|
35 |
<div class="demo-ad ga-panel ga-panel-default">
|
36 |
<div class="ga-panel-heading">
|
@@ -52,6 +60,14 @@ We recommend viewing your Google Analytics account to determine best solution:')
|
|
52 |
</div>
|
53 |
</div>
|
54 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
</div>
|
56 |
<a href="<?php echo esc_url( $demographic_page_url ); ?>/" class="view-report" target="_blank">
|
57 |
<?php echo esc_html__('View Full Report' ); ?>
|
8 |
</button>
|
9 |
</strong>
|
10 |
</div>
|
11 |
+
<img src="<?php echo trailingslashit(get_home_url()) . 'wp-content/plugins/googleanalytics/assets/images/demographics-ad.png'; ?>"/>
|
12 |
</div>
|
13 |
<?php elseif ($need_account_demo_enable) : ?>
|
14 |
+
<div class="demo-ad ga-panel ga-panel-default">
|
15 |
+
<div class="ga-panel-heading">
|
16 |
+
<strong>
|
17 |
+
<?php esc_html_e(
|
18 |
+
"If no demographics data is shown, you'll most likely need to do one of the following:",
|
19 |
+
'googleanalytics'
|
20 |
+
); ?>
|
21 |
+
<br>
|
22 |
+
<ol>
|
23 |
+
<li><?php esc_html_e('Enable "Demographics" within Google Analytics.', 'googleanalytics'); ?></li>
|
24 |
+
<li><?php esc_html_e('If you just enabled this feature, it may require a refresh prior to seeing data.',
|
25 |
+
'googleanalytics'); ?></li>
|
26 |
+
<li><?php esc_html_e('Wait until there\'s sufficient Demographic data to display.',
|
27 |
+
'googleanalytics'); ?></li>
|
28 |
+
</ol>
|
29 |
+
|
30 |
+
<a href="<?php echo esc_url($demographic_page_url); ?>/" class="view-report" target="_blank">
|
31 |
+
<?php echo esc_html__('Go to my account', 'googleanalytics'); ?>
|
32 |
+
</a>
|
33 |
+
</strong>
|
34 |
+
</div>
|
35 |
+
</div>
|
36 |
<?php else: ?>
|
37 |
<div class="filter-choices">
|
38 |
+
<?php Ga_Template::load( 'templates/date_custom_range_filter', [
|
39 |
+
'date_from' => $date_range['from'],
|
40 |
+
'date_to' => $date_range['to']
|
41 |
+
] ); ?>
|
|
|
|
|
42 |
</div>
|
43 |
<div class="demo-ad ga-panel ga-panel-default">
|
44 |
<div class="ga-panel-heading">
|
60 |
</div>
|
61 |
</div>
|
62 |
</div>
|
63 |
+
<div class="ga-demo-chart">
|
64 |
+
<div class="ga-panel-body ga-chart device">
|
65 |
+
<div id="demo_chart_device_div" style="width: 100%;"></div>
|
66 |
+
<div class="ga-loader-wrapper stats-page">
|
67 |
+
<div class="ga-loader stats-page-loader"></div>
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
</div>
|
71 |
</div>
|
72 |
<a href="<?php echo esc_url( $demographic_page_url ); ?>/" class="view-report" target="_blank">
|
73 |
<?php echo esc_html__('View Full Report' ); ?>
|
view/templates/gdpr-config.php
CHANGED
@@ -44,18 +44,6 @@ $user_types = array(
|
|
44 |
'always' => esc_html__('All visitors globally', 'sharethis-custom'),
|
45 |
);
|
46 |
|
47 |
-
// Consent type options.
|
48 |
-
$consent_types = array(
|
49 |
-
'global' => esc_html__(
|
50 |
-
'Global: Publisher consent = 1st party cookie; Vendors consent = 3rd party cookie',
|
51 |
-
'sharethis-custom'
|
52 |
-
),
|
53 |
-
'publisher' => esc_html__(
|
54 |
-
'Service: publisher consent = 1st party cookie; Vendors consent = 1st party cookie',
|
55 |
-
'sharethis-custom'
|
56 |
-
),
|
57 |
-
);
|
58 |
-
|
59 |
$languages = array(
|
60 |
'English' => 'en',
|
61 |
'German' => 'de',
|
@@ -106,21 +94,7 @@ $enabled = !empty($gdpr_config['enabled']) ? $gdpr_config['enabled'] : false;
|
|
106 |
<?php endforeach; ?>
|
107 |
</select>
|
108 |
</div>
|
109 |
-
|
110 |
-
<?php echo esc_html__('CONSENT SCOPE', 'sharethis-share-buttons'); ?>
|
111 |
-
</label>
|
112 |
-
<div class="input-div">
|
113 |
-
<select id="sharethis-consent-type">
|
114 |
-
<?php foreach ($consent_types as $consent_value => $c_name) : ?>
|
115 |
-
<option
|
116 |
-
value="<?php echo esc_attr($consent_value); ?>"
|
117 |
-
<?php echo isset($gdpr_config['scope']) ? selected($consent_value, $gdpr_config['scope']) : ''; ?>
|
118 |
-
>
|
119 |
-
<?php echo esc_html($c_name); ?>
|
120 |
-
</option>
|
121 |
-
<?php endforeach; ?>
|
122 |
-
</select>
|
123 |
-
</div>
|
124 |
<label class="control-label">
|
125 |
<?php echo esc_html__('SELECT LANGUAGE', 'sharethis-share-buttons'); ?>
|
126 |
</label>
|
44 |
'always' => esc_html__('All visitors globally', 'sharethis-custom'),
|
45 |
);
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
$languages = array(
|
48 |
'English' => 'en',
|
49 |
'German' => 'de',
|
94 |
<?php endforeach; ?>
|
95 |
</select>
|
96 |
</div>
|
97 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
<label class="control-label">
|
99 |
<?php echo esc_html__('SELECT LANGUAGE', 'sharethis-share-buttons'); ?>
|
100 |
</label>
|
view/templates/sidebar/demo-ad.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
</h2>
|
11 |
<div class="row">
|
12 |
<div class="col-md-12">
|
13 |
-
|
14 |
</div>
|
15 |
<div class="col-md-6">
|
16 |
<p>
|
10 |
</h2>
|
11 |
<div class="row">
|
12 |
<div class="col-md-12">
|
13 |
+
<img src="<?php echo esc_url($plugin_uri . 'assets/images/demographics-ex.png'); ?>"/>
|
14 |
</div>
|
15 |
<div class="col-md-6">
|
16 |
<p>
|