Skip to content

Commit

Permalink
WC Analytics: Disable session cookie that was breaking cache (#40937)
Browse files Browse the repository at this point in the history
* Disable setcookie and record

* Add changelogs

* Comment problematic code regarding cache

---------

Co-authored-by: Miguel Pérez Pellicer <[email protected]>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12697080733

Upstream-Ref: Automattic/jetpack@06b5bde
  • Loading branch information
tbradsha authored and matticbot committed Jan 9, 2025
1 parent 61fe373 commit 7980d90
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 123 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is an alpha version! The changes listed here are not final.
- Page & Post: Fix the layout on mobile when details are open
- Testimonials: fix a shortcode related bug which ccurs if the column attribute is added and set to 0
- Tiled Gallery block: ensure movement and close icons are visible when selecting image in editor, by changing focusable element.
- WC Analytics: Temporarily disable setcookie to avoid caching issues.

### Other changes <!-- Non-user-facing changes go here. This section will not be copied to readme.txt. -->
- Jetpack AI: Enable ratings feedback thumbs for all
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"automattic/jetpack-videopress": "^0.25.6",
"automattic/jetpack-waf": "^0.23.1",
"automattic/jetpack-wordads": "^0.4.5",
"automattic/woocommerce-analytics": "^0.4.0",
"automattic/woocommerce-analytics": "^0.4.1-alpha",
"scssphp/scssphp": "1.12.0"
},
"require-dev": {
Expand Down
8 changes: 8 additions & 0 deletions jetpack_vendor/automattic/woocommerce-analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.1-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Fixed
- Temporarily disable setcookie to avoid caching issues.

## [0.4.0] - 2025-01-06
### Added
- Add Search Event & landing Page support. [#40698]
Expand Down Expand Up @@ -83,6 +90,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix namespace issue with WooCommerce class reference. [#35857]
- General: bail early when WooCommerce is not active. [#36278]

[0.4.1-alpha]: https://github.com/Automattic/woocommerce-analytics/compare/v0.4.0...v0.4.1-alpha
[0.4.0]: https://github.com/Automattic/woocommerce-analytics/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/Automattic/woocommerce-analytics/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/Automattic/woocommerce-analytics/compare/v0.2.0...v0.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,24 @@ public function initialize_woocommerceanalytics_session() {
$session_id = wp_generate_uuid4();
$this->session_id = $session_id;
$this->landing_page = sanitize_url( wp_unslash( ( empty( $_SERVER['HTTPS'] ) ? 'http' : 'https' ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidatedNotSanitized -- actually escaped with sanitize_url.
setcookie(
'woocommerceanalytics_session',
wp_json_encode(
array(
'session_id' => $this->session_id,
'landing_page' => $this->landing_page,
)
),
0,
COOKIEPATH,
COOKIE_DOMAIN,
is_ssl(),
true
);
$this->record_event( 'woocommerceanalytics_session_started' );
// Disabled the below temporarily to avoid caching issues.
// phpcs:disable Squiz.PHP.CommentedOutCode.Found
// setcookie(
// 'woocommerceanalytics_session',
// wp_json_encode(
// array(
// 'session_id' => $this->session_id,
// 'landing_page' => $this->landing_page,
// )
// ),
// 0,
// COOKIEPATH,
// COOKIE_DOMAIN,
// is_ssl(),
// true
// );
// $this->record_event( 'woocommerceanalytics_session_started' );
// phpcs:enable Squiz.PHP.CommentedOutCode.Found
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,19 @@ public function find_cart_checkout_content_sources() {
* @return array Array of standard event props.
*/
public function get_common_properties() {
$session_data = json_decode( sanitize_text_field( wp_unslash( $_COOKIE['woocommerceanalytics_session'] ?? '' ) ), true ) ?? array();
$session_id = sanitize_text_field( $session_data['session_id'] ?? $this->session_id );
$landing_page = sanitize_url( $session_data['landing_page'] ?? $this->landing_page );
// phpcs:disable Squiz.PHP.CommentedOutCode.Found
// Disabled the below temporarily to avoid caching issues.
// $session_data = json_decode( sanitize_text_field( wp_unslash( $_COOKIE['woocommerceanalytics_session'] ?? '' ) ), true ) ?? array();
// $session_id = sanitize_text_field( $session_data['session_id'] ?? $this->session_id );
// $landing_page = sanitize_url( $session_data['landing_page'] ?? $this->landing_page );
// phpcs:enable Squiz.PHP.CommentedOutCode.Found
$site_info = array(
'session_id' => $session_id,
'session_id' => null,
'blog_id' => Jetpack_Connection::get_site_id(),
'store_id' => defined( '\\WC_Install::STORE_ID_OPTION' ) ? get_option( \WC_Install::STORE_ID_OPTION ) : false,
'ui' => $this->get_user_id(),
'url' => home_url(),
'landing_page' => $landing_page,
'landing_page' => null,
'woo_version' => WC()->version,
'wp_version' => get_bloginfo( 'version' ),
'store_admin' => in_array( array( 'administrator', 'shop_manager' ), wp_get_current_user()->roles, true ) ? 1 : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Woocommerce_Analytics {
/**
* Package version.
*/
const PACKAGE_VERSION = '0.4.0';
const PACKAGE_VERSION = '0.4.1-alpha';

/**
* Initializer.
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
),
'woocommerce-analytics' => array(
'path' => 'jetpack_vendor/automattic/woocommerce-analytics',
'ver' => '0.4.0',
'ver' => '0.4.1-alpha1736450653',
),
),
);
Loading

0 comments on commit 7980d90

Please sign in to comment.