-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Woo
committed
Oct 18, 2024
1 parent
041e451
commit e4ed22f
Showing
1,215 changed files
with
119,600 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace AutomateWoo\Admin; | ||
|
||
use Automattic\WooCommerce\Admin\PageController; | ||
|
||
/** | ||
* AutomateWoo Analytics. | ||
* Formerly AutomateWoo > Reports. | ||
* | ||
* @since 5.6.1 | ||
*/ | ||
class Analytics { | ||
|
||
/** | ||
* Init. | ||
*/ | ||
public static function init() { | ||
add_action( 'init', array( __CLASS__, 'setup' ) ); | ||
} | ||
|
||
/** | ||
* Setup Analytics. | ||
* Add report items and register scripts. | ||
*/ | ||
public static function setup() { | ||
if ( self::is_enabled() ) { | ||
// Analytics init. | ||
add_filter( 'woocommerce_analytics_report_menu_items', array( __CLASS__, 'add_report_menu_item' ) ); | ||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'register_script' ) ); | ||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'register_style' ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Add "Bundles" as a Analytics submenu item. | ||
* | ||
* @param array $report_pages Report page menu items. | ||
* @return array | ||
*/ | ||
public static function add_report_menu_item( $report_pages ) { | ||
|
||
$report_pages[] = array( | ||
'id' => 'automatewoo-analytics-runs-by-date', | ||
'title' => '<automatewoo-icon aria-label="AutomateWoo"></automatewoo-icon>' . __( 'Workflows', 'automatewoo' ), | ||
'parent' => 'woocommerce-analytics', | ||
'path' => '/analytics/automatewoo-runs-by-date', | ||
); | ||
$report_pages[] = array( | ||
'id' => 'automatewoo-analytics-email-tracking', | ||
'title' => '<automatewoo-icon aria-label="AutomateWoo"></automatewoo-icon>' . __( 'Email & SMS Tracking', 'automatewoo' ), | ||
'parent' => 'woocommerce-analytics', | ||
'path' => '/analytics/automatewoo-email-tracking', | ||
); | ||
$report_pages[] = array( | ||
'id' => 'automatewoo-analytics-conversions', | ||
'title' => '<automatewoo-icon aria-label="AutomateWoo"></automatewoo-icon>' . __( 'Conversions', 'automatewoo' ), | ||
'parent' => 'woocommerce-analytics', | ||
'path' => '/analytics/automatewoo-conversions', | ||
); | ||
return $report_pages; | ||
} | ||
|
||
/** | ||
* Register analytics JS. | ||
*/ | ||
public static function register_script() { | ||
if ( ! PageController::is_admin_page() ) { | ||
return; | ||
} | ||
|
||
$script_asset = require AW()->admin_path( '/assets/build/analytics.asset.php' ); | ||
|
||
wp_register_script( | ||
'automatewoo-analytics', | ||
AW()->admin_assets_url( '/build/analytics.js' ), | ||
$script_asset['dependencies'], | ||
$script_asset['version'], | ||
true | ||
); | ||
|
||
// Load JS translations. | ||
wp_set_script_translations( 'automatewoo-analytics', 'automatewoo', AW()->path( '/languages' ) ); | ||
|
||
// Enqueue script. | ||
wp_enqueue_script( 'automatewoo-analytics' ); | ||
} | ||
|
||
/** | ||
* Register analytics CSS. | ||
*/ | ||
public static function register_style() { | ||
if ( PageController::is_admin_page() ) { | ||
wp_enqueue_style( | ||
'automatewoo-analytics', | ||
AW()->admin_assets_url( '/build/analytics.css' ), | ||
[ 'wc-admin-app' ], | ||
AW()->version | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Whether or not the new Analytics reports are enabled. | ||
* | ||
* @return bool | ||
*/ | ||
public static function is_enabled() { | ||
$is_enabled = WC()->is_wc_admin_active(); | ||
|
||
/** | ||
* Whether AutomateWoo's analytics reports should be added to the WooCommerce Analytics menu. | ||
* | ||
* @filter automatewoo/admin/analytics_enabled | ||
*/ | ||
return (bool) apply_filters( 'automatewoo/admin/analytics_enabled', $is_enabled ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace AutomateWoo\Admin\Analytics; | ||
|
||
use AutomateWoo\Admin\Analytics; | ||
|
||
/** | ||
* AutomateWoo Analytics. | ||
* Formerly AutomateWoo > Reports. | ||
* | ||
* @since 5.6.3 | ||
*/ | ||
class Rest_API { | ||
|
||
/** | ||
* Init. | ||
*/ | ||
public static function init() { | ||
add_action( 'init', array( __CLASS__, 'setup' ) ); | ||
} | ||
|
||
/** | ||
* Setup Analytics. | ||
* Register controllers and data stores. | ||
*/ | ||
public static function setup() { | ||
if ( self::is_enabled() ) { | ||
|
||
// REST API Controllers. | ||
add_filter( 'woocommerce_admin_rest_controllers', array( __CLASS__, 'add_rest_api_controllers' ) ); | ||
|
||
// Register data stores. | ||
add_filter( 'woocommerce_data_stores', array( __CLASS__, 'register_data_stores' ) ); | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Whether or not the Rest APIs for Analytic reports are enabled. | ||
* | ||
* @return bool | ||
*/ | ||
public static function is_enabled() { | ||
return Analytics::is_enabled(); | ||
} | ||
|
||
/** | ||
* Adds Analytics REST contollers. | ||
* To be used with `woocommerce_admin_rest_controllers` filter. | ||
* | ||
* @param array $controllers | ||
* @return array Extended with AW Analytics controllers. | ||
*/ | ||
public static function add_rest_api_controllers( $controllers ) { | ||
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Controller'; | ||
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Stats\Controller'; | ||
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Email_Tracking\Stats_Controller'; | ||
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Unsubscribers\Stats_Controller'; | ||
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Workflow_Runs\Stats_Controller'; | ||
|
||
return $controllers; | ||
} | ||
|
||
/** | ||
* Register Analytics data stores. | ||
* To be used with `woocommerce_data_stores` filter. | ||
* | ||
* @param array $stores | ||
* @return array Extended with AW Analytics stores. | ||
*/ | ||
public static function register_data_stores( $stores ) { | ||
$stores['report-conversions-list'] = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Store'; | ||
$stores['report-conversions-stats'] = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Stats\Store'; | ||
$stores['report-email-tracking-stats'] = 'AutomateWoo\Admin\Analytics\Rest_API\Email_Tracking\Data_Store'; | ||
$stores['report-unsubscribers-stats'] = 'AutomateWoo\Admin\Analytics\Rest_API\Unsubscribers\Data_Store'; | ||
$stores['report-workflow-runs-stats'] = 'AutomateWoo\Admin\Analytics\Rest_API\Workflow_Runs\Data_Store'; | ||
|
||
return $stores; | ||
} | ||
} |
Oops, something went wrong.