Skip to content

Commit

Permalink
Jetpack AI: point upgrade buttons to checkout instead of product inte…
Browse files Browse the repository at this point in the history
…rstitial (#39469)

* Use checkout URL instead of My Jetpack interstitial page for plan upgrade on Jetpack sites

* Changelog

* Change the upgrade URL on the logo generator

* changelog

* Update redirect URL to use relative path, so the redirect works

* Use another redirect rule that already contains the redirect_to parameter

* Use a different redirect source for Jetpack sites on the logo gen checkout hook

* Refactor the wpcom checkout URL builder to remove duplicated code
  • Loading branch information
lhkowalski committed Sep 20, 2024
1 parent 7b91eb5 commit a14e3a5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Jetpack AI: point upgrade links and buttons to checkout instead of product interstitial.
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,37 @@ export const useCheckout = () => {
};
}, [] );

const isJetpackSite = ! isAtomicSite() && ! isSimpleSite();
const redirectSource = isJetpackSite
? 'jetpack-ai-upgrade-url-for-jetpack-sites'
: 'jetpack-ai-yearly-tier-upgrade-nudge';

/**
* Use the Jetpack redirect URL to open the checkout page
* Determine the post-checkout URL for non-Jetpack sites
*/
const wpcomCheckoutUrl = new URL( `https://jetpack.com/redirect/` );
wpcomCheckoutUrl.searchParams.set( 'source', 'jetpack-ai-yearly-tier-upgrade-nudge' );
wpcomCheckoutUrl.searchParams.set( 'site', getSiteFragment() as string );
const siteFragment = getSiteFragment() as string;
const wpcomRedirectToURL = `https://wordpress.com/home/${ siteFragment }`;

wpcomCheckoutUrl.searchParams.set(
/**
* Use the Jetpack redirect URL to open the checkout page
*/
const checkoutUrl = new URL( `https://jetpack.com/redirect/` );
checkoutUrl.searchParams.set( 'source', redirectSource );
checkoutUrl.searchParams.set( 'site', siteFragment );
checkoutUrl.searchParams.set(
'path',
tierPlansEnabled ? `jetpack_ai_yearly:-q-${ nextTier?.limit }` : 'jetpack_ai_yearly'
);

/**
* Open the product interstitial page
*/
const jetpackCheckoutUrl = `${ window?.Jetpack_Editor_Initial_State?.adminUrl }admin.php?redirect_to_referrer=1&page=my-jetpack#/add-jetpack-ai`;
// For Jetpack sites, the redirect_to parameter is handled by the Jetpack redirect source
if ( ! isJetpackSite ) {
checkoutUrl.searchParams.set(
'query',
`redirect_to=${ encodeURIComponent( wpcomRedirectToURL ) }`
);
}

const nextTierCheckoutURL =
isAtomicSite() || isSimpleSite() ? wpcomCheckoutUrl.toString() : jetpackCheckoutUrl;
const nextTierCheckoutURL = checkoutUrl.toString();

debug( 'Next tier checkout URL: ', nextTierCheckoutURL );

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

Jetpack AI: point upgrade links and buttons to checkout instead of product interstitial.
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,18 @@ export default function useAICheckout(): {

const wpcomRedirectToURL = getWPComRedirectToURL();

const wpcomCheckoutUrl = tierPlansEnabled
? getRedirectUrl( 'jetpack-ai-yearly-tier-upgrade-nudge', {
site: getSiteFragment() as string,
path: `jetpack_ai_yearly:-q-${ nextTier?.limit }`,
query: `redirect_to=${ encodeURIComponent( wpcomRedirectToURL ) }`,
} )
: getRedirectUrl( 'jetpack-ai-yearly-tier-upgrade-nudge', {
site: getSiteFragment() as string,
path: 'jetpack_ai_yearly',
query: `redirect_to=${ encodeURIComponent( wpcomRedirectToURL ) }`,
} );

const checkoutUrl =
isAtomicSite() || isSimpleSite()
? wpcomCheckoutUrl
: `${ window?.Jetpack_Editor_Initial_State?.adminUrl }admin.php?redirect_to_referrer=1&page=my-jetpack#/add-jetpack-ai`;
const wpcomCheckoutUrl = getRedirectUrl( 'jetpack-ai-yearly-tier-upgrade-nudge', {
site: getSiteFragment() as string,
path: tierPlansEnabled ? `jetpack_ai_yearly:-q-${ nextTier?.limit }` : 'jetpack_ai_yearly',
query: `redirect_to=${ encodeURIComponent( wpcomRedirectToURL ) }`,
} );

const jetpackCheckoutUrl = getRedirectUrl( 'jetpack-ai-upgrade-url-for-jetpack-sites', {
site: getSiteFragment() as string,
path: 'jetpack_ai_yearly',
} );

const checkoutUrl = isAtomicSite() || isSimpleSite() ? wpcomCheckoutUrl : jetpackCheckoutUrl;

const { autosaveAndRedirect, isRedirecting } = useAutosaveAndRedirect( checkoutUrl );

Expand Down

0 comments on commit a14e3a5

Please sign in to comment.