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

Boost: Add tracks event to clickable events on settings page #40246

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ const OtherErrors = ( { cssState, retry, showRetry, supportLink }: ShowStopperEr
href={ supportLink }
target="_blank"
rel="noreferrer"
onClick={ () => {
recordBoostEvent( 'critical_css_contact_support', {} );
} }
>
{ __( 'Contact Support', 'jetpack-boost' ) }
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getProvidersWithErrors } from '../lib/critical-css-errors';
import ShowStopperError from '../show-stopper-error/show-stopper-error';
import { Button } from '@automattic/jetpack-components';
import styles from './status.module.scss';
import { recordBoostEvent } from '$lib/utils/analytics';

type StatusTypes = {
cssState: CriticalCssState;
Expand Down Expand Up @@ -38,6 +39,11 @@ const Status: React.FC< StatusTypes > = ( {
cssState.providers.filter( provider => provider.status === 'success' ).length || 0;
const providersWithErrors = getProvidersWithErrors( cssState );

const handleClickRegenerate = () => {
recordBoostEvent( 'critical_css_regenerate_clicked', {} );
regenerateAction.mutate();
};

// If there has been a fatal error, show it.
if ( showFatalError ) {
return (
Expand Down Expand Up @@ -104,7 +110,7 @@ const Status: React.FC< StatusTypes > = ( {
variant={ highlightRegenerateButton ? 'primary' : 'link' }
size="small"
weight="regular"
onClick={ () => regenerateAction.mutate() }
onClick={ handleClickRegenerate }
icon={ highlightRegenerateButton ? undefined : <RefreshIcon /> }
disabled={ cssState.status === 'pending' }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Button } from '@automattic/jetpack-components';
import React, { useState } from 'react';
import CloseIcon from '$svg/close';
import PencilIcon from '$svg/pencil';
import { recordBoostEvent } from '$lib/utils/analytics';

type CollapsibleMetaProps = {
children: React.ReactNode;
header: React.ReactNode;
summary: React.ReactNode;
editText: string;
closeEditText: string;
tracksEventName: string;
};

const CollapsibleMeta = ( {
Expand All @@ -18,6 +20,7 @@ const CollapsibleMeta = ( {
summary,
editText,
closeEditText,
tracksEventName,
}: CollapsibleMetaProps ) => {
const [ isEditing, setIsEditing ] = useState( false );
return (
Expand All @@ -37,6 +40,9 @@ const CollapsibleMeta = ( {
}
className={ styles[ 'edit-button' ] }
onClick={ () => {
recordBoostEvent( tracksEventName, {
status: isEditing ? 'open' : 'close',
} );
setIsEditing( ! isEditing );
} }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const meta: Meta< typeof CollapsibleMeta > = {
summary: { control: 'text' },
editText: { control: 'text' },
closeEditText: { control: 'text' },
tracksEventName: { control: 'text' },
},
decorators: [
Story => (
Expand All @@ -25,6 +26,7 @@ const defaultValues = {
summary: 'Something to show in the summary',
editText: 'Edit',
closeEditText: 'Close',
tracksEventName: 'tracks_event_name',
};

export default meta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const QualitySettings = ( { isPremium }: QualitySettingsProps ) => {
closeEditText={ __( 'Hide', 'jetpack-boost' ) }
header={ <Header /> }
summary={ <Summary imageCdnQuality={ imageCdnQuality } /> }
tracksEventName="image_cdn_panel_toggle"
>
<div className={ styles.body }>
<h5>Adjust image quality per format</h5>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ const Meta = () => {
const [ clearedCacheMessage, runClearPageCacheAction ] = useClearPageCacheAction();

const clearPageCache = () => {
recordBoostEvent( 'page_cache_clear_clicked', {} );
runClearPageCacheAction.mutate();
};

const totalBypassPatterns = bypassPatterns?.length || 0;

const toggleExpanded = ( newValue: boolean ) => {
recordBoostEvent( 'page_cache_panel_toggle', {
status: newValue ? 'open' : 'close',
} );
setIsExpanded( newValue );
};

const getSummary = () => {
if ( runClearPageCacheAction.isPending ) {
return __( 'Clearing cache…', 'jetpack-boost' );
Expand Down Expand Up @@ -110,7 +118,7 @@ const Meta = () => {
weight="regular"
iconSize={ 16 }
icon={ isExpanded ? <ChevronUp /> : <ChevronDown /> }
onClick={ () => setIsExpanded( ! isExpanded ) }
onClick={ () => toggleExpanded( ! isExpanded ) }
>
{ __( 'Show Options', 'jetpack-boost' ) }
</Button>
Expand Down Expand Up @@ -198,6 +206,7 @@ const BypassPatterns = ( {
}, [ showErrorNotice ] );

function save() {
recordBoostEvent( 'page_cache_exceptions_save_clicked', {} );
setPatterns( inputValue );
}

Expand Down Expand Up @@ -269,6 +278,7 @@ const BypassPatternsExample = ( { children }: BypassPatternsExampleProps ) => {
href="#"
className={ styles[ 'example-button' ] }
onClick={ e => {
recordBoostEvent( 'page_cache_see_example_clicked', {} );
e.preventDefault();
setShow( ! show );
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ReactNode, useState } from 'react';
import { Button } from '@wordpress/components';
import { useDismissibleAlertState } from '$features/performance-history/lib/hooks';
import { getRedirectUrl } from '@automattic/jetpack-components';
import { recordBoostEvent } from '$lib/utils/analytics';

type Props = {
scoreChange: number | false; // Speed score shift to show, or false if none.
Expand Down Expand Up @@ -77,6 +78,8 @@ function PopOut( { scoreChange }: Props ) {

const hideAlert = () => setClose( true );

hasScoreChanged && recordBoostEvent( 'speed_score_alert_shown', {} );

const animationStyles = useSpring( {
from: {
right: '-100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { queryClient } from '@automattic/jetpack-react-data-sync-client';
import ErrorBoundary from '$features/error-boundary/error-boundary';
import PopOut from './pop-out/pop-out';
import { useCornerstonePages } from '$features/cornerstone-pages/lib/stores/cornerstone-pages';
import { recordBoostEvent } from '$lib/utils/analytics';

const SpeedScore = () => {
const [ cornerstonePages ] = useCornerstonePages();
Expand Down Expand Up @@ -55,6 +56,11 @@ const SpeedScore = () => {
}
}, [ site.online, status ] );

const handleClickRefresh = () => {
recordBoostEvent( 'speed_score_refresh_clicked', {} );
loadScore( true );
};

// Ask the API to recompute the score.
const refreshScore = useCallback( async () => {
if ( site.online ) {
Expand Down Expand Up @@ -100,7 +106,7 @@ const SpeedScore = () => {
size="small"
weight="regular"
className={ styles[ 'action-button' ] }
onClick={ () => loadScore( true ) }
onClick={ handleClickRefresh }
disabled={ status === 'loading' }
icon={ <RefreshIcon /> }
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { __ } from '@wordpress/i18n';
import LeftArrow from '$svg/left-arrow';
import { useNavigate } from 'react-router-dom';
import { recordBoostEvent } from '$lib/utils/analytics';

type BackButtonProps = {
route?: string;
Expand All @@ -9,6 +10,10 @@ type BackButtonProps = {
const BackButton: React.FC< BackButtonProps > = ( { route = '/' } ) => {
const navigate = useNavigate();
const handleBack = () => {
recordBoostEvent( 'back_button_clicked', {
current_page: window.location.pathname + window.location.search + window.location.hash,
destination: route,
} );
navigate( route );
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { __ } from '@wordpress/i18n';
import { Button } from '@automattic/jetpack-components';
import styles from './support.module.scss';
import { recordBoostEvent } from '$lib/utils/analytics';

const Support = () => {
const openPaidSupport = () => {
recordBoostEvent( 'support_contact_us_clicked', {} );
const supportUrl = 'https://jetpackme.wordpress.com/contact-support/';
window.open( supportUrl, '_blank' );
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

General: add Tracks events to clickable events on settings page
Loading