Abilities
4 weeks ago
AbilitiesApi
7 months ago
AddressProvider
7 months ago
Admin
5 days ago
Agentic
7 months ago
Api
4 weeks ago
BatchProcessing
4 weeks ago
CLI
5 months ago
Caches
4 months ago
ComingSoon
9 months ago
CostOfGoodsSold
9 months ago
Customers
9 months ago
DataStores
4 weeks ago
DependencyManagement
5 months ago
Email
4 weeks ago
EmailEditor
4 weeks ago
Features
5 days ago
Integrations
7 months ago
Jetpack
5 months ago
Logging
2 months ago
MCP
4 weeks ago
OrderReviews
4 weeks ago
Orders
4 weeks ago
ProductAttributes
4 weeks ago
ProductAttributesLookup
4 weeks ago
ProductDownloads
5 months ago
ProductFeed
1 week ago
ProductFilters
4 weeks ago
ProductImage
1 year ago
PushNotifications
5 days ago
ReceiptRendering
2 months ago
RestApi
4 weeks ago
Settings
1 year ago
ShopperLists
2 weeks ago
StockNotifications
4 weeks ago
Traits
4 months ago
TransientFiles
4 weeks ago
Utilities
4 weeks ago
VariationGallery
4 weeks ago
WCCom
2 years ago
AssignDefaultCategory.php
1 year ago
Brands.php
11 months ago
DownloadPermissionsAdjuster.php
2 months ago
McStats.php
1 year ago
OrderCouponDataMigrator.php
1 year ago
RegisterHooksInterface.php
1 year ago
RestApiControllerBase.php
1 year ago
RestApiParameterUtil.php
2 years ago
RestockRefundedItemsAdjuster.php
2 months ago
McStats.php
77 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce MC Stats package |
| 4 | */ |
| 5 | |
| 6 | declare( strict_types = 1 ); |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal; |
| 9 | |
| 10 | use Automattic\Jetpack\A8c_Mc_Stats; |
| 11 | |
| 12 | /** |
| 13 | * Class MC Stats, used to record internal usage stats for Automattic. |
| 14 | * |
| 15 | * This class is a wrapper around the Jetpack MC Stats package. |
| 16 | * See https://github.com/Automattic/jetpack-a8c-mc-stats/tree/trunk for more details. |
| 17 | */ |
| 18 | class McStats extends A8c_Mc_Stats { |
| 19 | |
| 20 | /** |
| 21 | * Return the stats from a group in an array ready to be added as parameters in a query string |
| 22 | * |
| 23 | * Jetpack MC Stats package prefixes group names with "x_jetpack-" so we override this method to prefix group names with "x_woocommerce-". |
| 24 | * |
| 25 | * @param string $group_name The name of the group to retrieve. |
| 26 | * @return array Array with one item, where the key is the prefixed group and the value are all stats concatenated with a comma. If group not found, an empty array will be returned |
| 27 | */ |
| 28 | public function get_group_query_args( $group_name ) { |
| 29 | $stats = $this->get_current_stats(); |
| 30 | if ( isset( $stats[ $group_name ] ) && ! empty( $stats[ $group_name ] ) ) { |
| 31 | return array( "x_woocommerce-{$group_name}" => implode( ',', $stats[ $group_name ] ) ); |
| 32 | } |
| 33 | return array(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Outputs the tracking pixels for the current stats and empty the stored stats from the object |
| 38 | * |
| 39 | * @return void |
| 40 | */ |
| 41 | public function do_stats() { |
| 42 | if ( ! \WC_Site_Tracking::is_tracking_enabled() ) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | parent::do_stats(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Runs stats code for a one-off, server-side. |
| 51 | * |
| 52 | * @param string $url string The URL to be pinged. Should include `x_woocommerce-{$group}={$stats}` or whatever we want to store. |
| 53 | * |
| 54 | * @return bool If it worked. |
| 55 | */ |
| 56 | public function do_server_side_stat( $url ) { |
| 57 | if ( ! \WC_Site_Tracking::is_tracking_enabled() ) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | return parent::do_server_side_stat( $url ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Pings the stats server for the current stats and empty the stored stats from the object |
| 66 | * |
| 67 | * @return void |
| 68 | */ |
| 69 | public function do_server_side_stats() { |
| 70 | if ( ! \WC_Site_Tracking::is_tracking_enabled() ) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | parent::do_server_side_stats(); |
| 75 | } |
| 76 | } |
| 77 |