Skip to content

Commit

Permalink
Paid stats: enable UTM and Devices stats on WPCOM paid stats feature (#…
Browse files Browse the repository at this point in the history
…97160)

* Enable utm/device stats on paid stats (premium plans)

* Update supports checks to allow utm/device stats on dotcom

* Replaced `StatsCardUpsellJetpack` with `StatsCardUpsell` in UTM and Devices module overlay

StatsCardUpsell determines whether to render the WPCOM or Jetpack upsell prompt, depending on whether the site is Jetpack (non-atomic) or not.

* Remove gating of advanced stats for non-Jetpack sites and add unit tests

Now relies on checking if the site has the paid stats feature for access control.

* Update unit tests comment

* Refactor unit test formatting

---------

Co-authored-by: Rafael Agostini <[email protected]>
  • Loading branch information
lsl and Initsogar authored Dec 9, 2024
1 parent dd5c9e2 commit 1f099cc
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from 'clsx';
import React from 'react';
import StatsCardUpsell from 'calypso/my-sites/stats/stats-card-upsell';
import { STATS_TYPE_DEVICE_STATS } from '../../../constants';
import StatsCardUpsellJetpack from '../../../stats-card-upsell/stats-card-upsell-jetpack';
import StatsListCard from '../../../stats-list/stats-list-card';

import './stats-module-devices.scss';
Expand Down Expand Up @@ -64,7 +64,7 @@ const StatsModuleUpgradeOverlay: React.FC< StatsModuleUpgradeOverlayProps > = (
splitHeader
overlay={
overlay ?? (
<StatsCardUpsellJetpack
<StatsCardUpsell
className="stats-module__upsell"
siteId={ siteId }
statType={ STATS_TYPE_DEVICE_STATS }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from 'clsx';
import React from 'react';
import StatsCardUpsell from 'calypso/my-sites/stats/stats-card-upsell';
import { STATS_FEATURE_UTM_STATS } from '../../../constants';
import StatsCardUpsellJetpack from '../../../stats-card-upsell/stats-card-upsell-jetpack';
import StatsListCard from '../../../stats-list/stats-list-card';

import './stats-module-utm-overlay.scss';
Expand Down Expand Up @@ -62,7 +62,7 @@ const StatsModuleUTMOverlay: React.FC< StatsModuleUTMOverlayProps > = ( {
} }
overlay={
overlay ?? (
<StatsCardUpsellJetpack
<StatsCardUpsell
className="stats-module__upsell"
siteId={ siteId }
statType={ STATS_FEATURE_UTM_STATS }
Expand Down
86 changes: 86 additions & 0 deletions client/my-sites/stats/hooks/test/use-should-gate-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,92 @@ describe( 'shouldGateStats in Calypso', () => {
const isGatedStats = shouldGateStats( mockState, siteId, gatedStatType );
expect( isGatedStats ).toBe( true );
} );

it( 'should gate advanced stats modules for Simple site without commercial stats feature', () => {
const mockState = {
sites: {
features: {
[ siteId ]: {
data: {
active: [],
},
},
},
items: {
[ siteId ]: {
jetpack: false,
options: {
is_wpcom_atomic: false,
},
},
},
},
purchases: {
data: [],
},
};
const isGatedStats = shouldGateStats( mockState, siteId, jetpackStatsAdvancedStatType );
expect( isGatedStats ).toBe( true );
} );

// Note: Once FEATURE_STATS_COMMERCIAL is introduced and fully rolled out,
// we should replace FEATURE_STATS_PAID with FEATURE_STATS_COMMERCIAL in
// the following test to ensure consistent gating logic for commercial stats.
// @see: https://github.com/Automattic/wp-calypso/pull/97041

it( 'should not gate advanced stats modules for Simple site with commercial stats feature', () => {
const mockState = {
sites: {
features: {
[ siteId ]: {
data: {
active: [ FEATURE_STATS_PAID ], // FEATURE_STATS_COMMERCIAL
},
},
},
items: {
[ siteId ]: {
jetpack: false,
options: {
is_wpcom_atomic: false,
},
},
},
},
purchases: {
data: [],
},
};
const isGatedStats = shouldGateStats( mockState, siteId, jetpackStatsAdvancedStatType );
expect( isGatedStats ).toBe( false );
} );

it( 'should not gate advanced stats for Atomic site with commercial stats feature', () => {
const mockState = {
sites: {
features: {
[ siteId ]: {
data: {
active: [ FEATURE_STATS_PAID ], // FEATURE_STATS_COMMERCIAL
},
},
},
items: {
[ siteId ]: {
jetpack: true,
options: {
is_wpcom_atomic: true,
},
},
},
},
purchases: {
data: [],
},
};
const isGatedStats = shouldGateStats( mockState, siteId, jetpackStatsAdvancedStatType );
expect( isGatedStats ).toBe( false );
} );
} );

describe( 'shouldGateStats in Odyssey stats', () => {
Expand Down
12 changes: 6 additions & 6 deletions client/my-sites/stats/hooks/use-should-gate-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ const paidStats = [
STAT_TYPE_TOP_AUTHORS,
STAT_TYPE_SEARCH_TERMS,
STAT_TYPE_VIDEO_PLAYS,

// Paid stats is currently a premium plan feature.
// Legacy sites will inadvertantly get these temporarily but paywalling
// these again later is fine. (https://github.com/Automattic/wp-calypso/pull/97041)
STATS_TYPE_DEVICE_STATS,
STATS_FEATURE_UTM_STATS,
];

// Gated controls for WPCOM sites without the FEATURE_STATS_PAID feature.
Expand Down Expand Up @@ -165,12 +171,6 @@ export const shouldGateStats = ( state: object, siteId: number | null, statType:
return [ ...jetpackStatsAdvancedPaywall ].includes( statType );
}

// Gate advanced stats for non-Jetpack sites unless they have a Jetpack Stats commercial purchase.
// Dotcom sites are not able to see these modules yet, so the line wouldn't apply to them.
if ( jetpackStatsAdvancedPaywall.includes( statType ) ) {
return ! supportStatsCommercialUse;
}

const siteFeatures = getSiteFeatures( state, siteId );
const siteHasPaidStats = siteHasFeature( state, siteId, FEATURE_STATS_PAID );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { preventWidows } from 'calypso/lib/formatting';
import { toggleUpsellModal } from 'calypso/state/stats/paid-stats-upsell/actions';
import {
STATS_FEATURE_DATE_CONTROL,
STATS_FEATURE_UTM_STATS,
STATS_TYPE_DEVICE_STATS,
STAT_TYPE_CLICKS,
STAT_TYPE_REFERRERS,
STAT_TYPE_SEARCH_TERMS,
Expand Down Expand Up @@ -33,6 +35,10 @@ const getUpsellCopy = ( statType: string ) => {
return translate( 'Compare different time periods to analyze your site’s growth.' );
case STAT_TYPE_VIDEO_PLAYS:
return translate( 'Discover your most popular videos and find out how they performed.' );
case STATS_FEATURE_UTM_STATS:
return translate( 'Generate UTM parameters and track your campaign performance data.' );
case STATS_TYPE_DEVICE_STATS:
return translate( 'See which devices your visitors are using.' );
default:
return translate( 'Upgrade your plan to unlock Jetpack Stats.' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ function getEnvStatsFeatureSupportChecks( state: object, siteId: number | null )
'0.16.0-alpha',
isOdysseyStats
),
supportsUTMStats:
// UTM stats are only available for Jetpack sites for now.
isSiteJetpackNotAtomic && ( ! isOdysseyStats || !! statsAdminVersion ),
supportsDevicesStats:
// UTM stats are only available for Jetpack sites for now.
isSiteJetpackNotAtomic && ( ! isOdysseyStats || !! statsAdminVersion ),
supportsUTMStats: ! isOdysseyStats || !! statsAdminVersion,
supportsDevicesStats: ! isOdysseyStats || !! statsAdminVersion,
supportsOnDemandCommercialClassification: version_greater_than_or_equal(
statsAdminVersion,
'0.18.0-alpha',
Expand Down

0 comments on commit 1f099cc

Please sign in to comment.