Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test ExPlat implementation #37973

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds a new component to fetch experiments specifically for authenticated users
7 changes: 2 additions & 5 deletions projects/packages/explat/src/class-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ public function get_assignments( $request ) {

if ( $request['as_connected_user'] && $is_user_connected ) {
$response = Client::wpcom_json_api_request_as_user(
$request_path,
'v2',
$args,
null,
'wpcom'
add_query_arg( $args, $request_path ),
'v2'
);
} else {
$response = wp_remote_get(
Expand Down
33 changes: 19 additions & 14 deletions projects/packages/explat/src/client/assignment.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';

export const fetchExperimentAssignment = async ( {
experimentName,
anonId,
}: {
experimentName: string;
anonId: string | null;
} ): Promise< unknown > => {
const params = {
experiment_name: experimentName,
anon_id: anonId ?? undefined,
as_connected_user: false,
const fetchExperimentAssignment =
( asConnectedUser = false ) =>
async ( {
experimentName,
anonId,
}: {
experimentName: string;
anonId: string | null;
} ): Promise< unknown > => {
const params = {
experiment_name: experimentName,
anon_id: anonId ?? undefined,
as_connected_user: asConnectedUser,
};
const assignmentsRequestUrl = addQueryArgs( 'jetpack/v4/explat/assignments', params );

return await apiFetch( { path: assignmentsRequestUrl } );
};
const assignmentsRequestUrl = addQueryArgs( 'jetpack/v4/explat/assignments', params );

return await apiFetch( { path: assignmentsRequestUrl } );
};
export const fetchExperimentAssignmentAnonymously = fetchExperimentAssignment( false );
export const fetchExperimentAssignmentWithAuth = fetchExperimentAssignment( true );
25 changes: 23 additions & 2 deletions projects/packages/explat/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import createExPlatClientReactHelpers from '@automattic/explat-client-react-help
* Internal dependencies
*/
import { getAnonId, initializeAnonId } from './anon';
import { fetchExperimentAssignment } from './assignment';
import {
fetchExperimentAssignmentAnonymously,
fetchExperimentAssignmentWithAuth,
} from './assignment';
import { logError } from './error';
import { isDevelopmentMode } from './utils';

Expand All @@ -18,7 +21,7 @@ export const initializeExPlat = (): void => {
initializeExPlat();

const exPlatClient = createExPlatClient( {
fetchExperimentAssignment,
fetchExperimentAssignment: fetchExperimentAssignmentAnonymously,
getAnonId,
logError,
isDevelopmentMode,
Expand All @@ -28,3 +31,21 @@ export const { loadExperimentAssignment, dangerouslyGetExperimentAssignment } =

export const { useExperiment, Experiment, ProvideExperimentData } =
createExPlatClientReactHelpers( exPlatClient );

const exPlatClientWithAuth = createExPlatClient( {
fetchExperimentAssignment: fetchExperimentAssignmentWithAuth,
getAnonId,
logError,
isDevelopmentMode,
} );

export const {
loadExperimentAssignment: loadExperimentAssignmentWithAuth,
dangerouslyGetExperimentAssignment: dangerouslyGetExperimentAssignmentWithAuth,
} = exPlatClientWithAuth;

export const {
useExperiment: useExperimentWithAuth,
Experiment: ExperimentWithAuth,
ProvideExperimentData: ProvideExperimentDataWithAuth,
} = createExPlatClientReactHelpers( exPlatClientWithAuth );
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useBreakpointMatch,
ActionButton,
} from '@automattic/jetpack-components';
import { ExperimentWithAuth } from '@automattic/jetpack-explat';
import { __ } from '@wordpress/i18n';
import clsx from 'clsx';
import { useContext, useEffect, useLayoutEffect, useState } from 'react';
Expand Down Expand Up @@ -146,7 +147,11 @@ export default function MyJetpackScreen() {
<Container horizontalSpacing={ 5 } horizontalGap={ noticeMessage ? 3 : 6 }>
<Col sm={ 4 } md={ 8 } lg={ 12 }>
<Text variant="headline-small">
{ __( 'Discover all Jetpack Products', 'jetpack-my-jetpack' ) }
<ExperimentWithAuth
name="explat_test_jetpack_plugin_explat_implementation"
defaultExperience={ __( 'Discover all Jetpack Products', 'jetpack-my-jetpack' ) }
treatmentExperience={ __( 'Explore all Jetpack Products', 'jetpack-my-jetpack' ) }
/>
</Text>
</Col>
{ noticeMessage && ! isWelcomeBannerVisible && (
Expand Down
4 changes: 4 additions & 0 deletions projects/packages/my-jetpack/changelog/add-test-explat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

This PR implements the ExPlat package in My Jetpack
3 changes: 2 additions & 1 deletion projects/packages/my-jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"automattic/jetpack-assets": "@dev",
"automattic/jetpack-boost-speed-score": "@dev",
"automattic/jetpack-connection": "@dev",
"automattic/jetpack-explat": "@dev",
"automattic/jetpack-jitm": "@dev",
"automattic/jetpack-licensing": "@dev",
"automattic/jetpack-plugins-installer": "@dev",
Expand Down Expand Up @@ -79,7 +80,7 @@
"link-template": "https://github.com/Automattic/jetpack-my-jetpack/compare/${old}...${new}"
},
"branch-alias": {
"dev-trunk": "4.27.x-dev"
"dev-trunk": "4.28.x-dev"
},
"version-constants": {
"::PACKAGE_VERSION": "src/class-initializer.php"
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/my-jetpack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-my-jetpack",
"version": "4.27.3-alpha",
"version": "4.28.0-alpha",
"description": "WP Admin page with information and configuration shared among all Jetpack stand-alone plugins",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/my-jetpack/#readme",
"bugs": {
Expand Down Expand Up @@ -29,6 +29,7 @@
"@automattic/jetpack-boost-score-api": "workspace:*",
"@automattic/jetpack-components": "workspace:*",
"@automattic/jetpack-connection": "workspace:*",
"@automattic/jetpack-explat": "workspace:*",
"@automattic/jetpack-licensing": "workspace:*",
"@tanstack/react-query": "5.20.5",
"@wordpress/api-fetch": "7.2.0",
Expand Down
5 changes: 4 additions & 1 deletion projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Connection\Rest_Authentication as Connection_Rest_Authentication;
use Automattic\Jetpack\Constants as Jetpack_Constants;
use Automattic\Jetpack\ExPlat;
use Automattic\Jetpack\JITMS\JITM;
use Automattic\Jetpack\Licensing;
use Automattic\Jetpack\Modules;
Expand All @@ -37,7 +38,7 @@ class Initializer {
*
* @var string
*/
const PACKAGE_VERSION = '4.27.3-alpha';
const PACKAGE_VERSION = '4.28.0-alpha';

/**
* HTML container ID for the IDC screen on My Jetpack page.
Expand Down Expand Up @@ -108,6 +109,8 @@ public static function init() {
// This is later than the admin-ui package, which runs on 1000
add_action( 'admin_init', array( __CLASS__, 'maybe_show_red_bubble' ), 1001 );

ExPlat::init();

// Sets up JITMS.
JITM::configure();

Expand Down
5 changes: 5 additions & 0 deletions projects/plugins/backup/changelog/add-test-explat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


5 changes: 5 additions & 0 deletions projects/plugins/backup/changelog/add-test-explat#2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


5 changes: 5 additions & 0 deletions projects/plugins/backup/changelog/add-test-explat#3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


77 changes: 75 additions & 2 deletions projects/plugins/backup/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/boost/changelog/add-test-explat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


5 changes: 5 additions & 0 deletions projects/plugins/boost/changelog/add-test-explat#2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


5 changes: 5 additions & 0 deletions projects/plugins/boost/changelog/add-test-explat#3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


Loading
Loading