From 8b881989118ab1f8a2940b2a1c620c3f7eb7d07d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 2 Oct 2023 10:29:08 +0200 Subject: [PATCH] Telemetry: set `pluginVersion` user property --- includes/Tracking.php | 4 ++++ tests/phpunit/integration/tests/Tracking.php | 3 +++ 2 files changed, 7 insertions(+) diff --git a/includes/Tracking.php b/includes/Tracking.php index 0df7bcf27d62..6184c09bb6ea 100644 --- a/includes/Tracking.php +++ b/includes/Tracking.php @@ -237,6 +237,10 @@ private function get_user_properties(): array { 'adNetwork' => $ad_network, 'analytics' => $analytics, 'activePlugins' => implode( ',', $active_plugins ), + // This doesn't seem to be fully working for web properties. + // So we send it as both app_version and a user property. + // See https://support.google.com/analytics/answer/9268042. + 'pluginVersion' => WEBSTORIES_VERSION, ]; } } diff --git a/tests/phpunit/integration/tests/Tracking.php b/tests/phpunit/integration/tests/Tracking.php index bf76389b2438..a168b642bd76 100644 --- a/tests/phpunit/integration/tests/Tracking.php +++ b/tests/phpunit/integration/tests/Tracking.php @@ -170,6 +170,7 @@ public function test_get_settings(): void { $this->assertArrayHasKey( 'analytics', $settings['userProperties'] ); $this->assertArrayHasKey( 'serverEnvironment', $settings['userProperties'] ); $this->assertArrayHasKey( 'activePlugins', $settings['userProperties'] ); + $this->assertArrayHasKey( 'pluginVersion', $settings['userProperties'] ); $this->assertSame( get_locale(), $settings['userProperties']['siteLocale'] ); $this->assertSame( get_user_locale(), $settings['userProperties']['userLocale'] ); $this->assertSame( wp_get_environment_type(), $settings['userProperties']['serverEnvironment'] ); @@ -177,6 +178,7 @@ public function test_get_settings(): void { $this->assertSame( get_bloginfo( 'version' ), $settings['userProperties']['wpVersion'] ); $this->assertSame( 'administrator', $settings['userProperties']['userRole'] ); $this->assertSame( 'enableFoo,enableBar', $settings['userProperties']['enabledExperiments'] ); + $this->assertSame( WEBSTORIES_VERSION, $settings['userProperties']['pluginVersion'] ); $this->assertIsString( $settings['userProperties']['wpVersion'] ); $this->assertIsString( $settings['userProperties']['phpVersion'] ); $this->assertIsInt( $settings['userProperties']['isMultisite'] ); @@ -184,6 +186,7 @@ public function test_get_settings(): void { $this->assertIsString( $settings['userProperties']['analytics'] ); $this->assertIsString( $settings['userProperties']['activePlugins'] ); $this->assertIsString( $settings['userProperties']['serverEnvironment'] ); + $this->assertIsString( $settings['userProperties']['pluginVersion'] ); } /**