Skip to content

Commit

Permalink
Ai Assistant: track Write with AI... click events (#31082)
Browse files Browse the repository at this point in the history
* [not verified] record jetpack_editor_ai_assistant_block_toolbar_button_click event

* [not verified] rename promp name to onPromptSelect

* [not verified] rename prop to onSuggestionSelect

* [not verified] track Write with AI `suggestion`

* changelog
  • Loading branch information
retrofox authored May 31, 2023
1 parent e52edf7 commit 2c94d44
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: enhancement

AI Assistant: track 'Write with AI...' button events
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const AIControl = ( {
promptType,
onChange,
requireUpgrade,
recordEvent,
} ) => {
const promptUserInputRef = useRef( null );
const [ isSm ] = useBreakpointMatch( 'sm' );
Expand Down Expand Up @@ -114,6 +115,7 @@ const AIControl = ( {
}, 25 * i );
}
} }
recordEvent={ recordEvent }
/>
) }
<div
Expand Down Expand Up @@ -197,6 +199,7 @@ const ToolbarControls = ( {
wholeContent,
promptType,
setUserPrompt,
recordEvent,
} ) => {
return (
<>
Expand Down Expand Up @@ -248,8 +251,21 @@ const ToolbarControls = ( {
hasContentBefore={ !! contentBefore?.length }
hasContent={ !! wholeContent?.length }
hasPostTitle={ hasPostTitle }
onPromptSelected={ setUserPrompt }
getSuggestionFromOpenAI={ getSuggestionFromOpenAI }
onPromptSelect={ prompt => {
recordEvent( 'jetpack_editor_ai_assistant_block_toolbar_button_click', {
type: 'prompt-template',
prompt,
} );

setUserPrompt( prompt );
} }
onSuggestionSelect={ suggestion => {
recordEvent( 'jetpack_editor_ai_assistant_block_toolbar_button_click', {
type: 'suggestion',
suggestion,
} );
getSuggestionFromOpenAI( suggestion );
} }
/>
) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId }
promptType={ attributes.promptType }
onChange={ () => setErrorDismissed( true ) }
requireUpgrade={ errorData?.code === 'error_quota_exceeded' }
recordEvent={ tracks.recordEvent }
/>
{ ! loadingImages && resultImages.length > 0 && (
<Flex direction="column" style={ { width: '100%' } }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type PromptTemplatesControlProps = {
hasContentBefore: boolean;
hasContent: boolean;
hasPostTitle: boolean;
onPromptSelected: ( prompt: string ) => void;
getSuggestionFromOpenAI: ( type: string, options?: object ) => void;
onPromptSelect: ( prompt: string ) => void;
onSuggestionSelect: ( suggestion: string ) => void;
};

type PromptTemplateProps = {
Expand Down Expand Up @@ -66,11 +66,11 @@ const promptTemplates = [
];

export default function PromptTemplatesControl( {
onPromptSelected,
hasContentBefore,
hasContent,
hasPostTitle,
getSuggestionFromOpenAI,
onPromptSelect,
onSuggestionSelect,
}: PromptTemplatesControlProps ) {
const label = __( 'Write with AI…', 'jetpack' );

Expand All @@ -89,21 +89,21 @@ export default function PromptTemplatesControl( {
<MenuItem
icon={ postContent }
iconPosition="left"
onClick={ () => getSuggestionFromOpenAI( 'continue' ) }
onClick={ () => onSuggestionSelect( 'continue' ) }
>
{ __( 'Expand on preceding content', 'jetpack' ) }
</MenuItem>
<MenuItem
icon={ termDescription }
iconPosition="left"
onClick={ () => getSuggestionFromOpenAI( 'correctSpelling' ) }
onClick={ () => onSuggestionSelect( 'correctSpelling' ) }
>
{ __( 'Correct spelling and grammar of preceding content', 'jetpack' ) }
</MenuItem>
<MenuItem
icon={ post }
iconPosition="left"
onClick={ () => getSuggestionFromOpenAI( 'simplify' ) }
onClick={ () => onSuggestionSelect( 'simplify' ) }
>
{ __( 'Simplify preceding content', 'jetpack' ) }
</MenuItem>
Expand All @@ -115,7 +115,7 @@ export default function PromptTemplatesControl( {
<MenuItem
icon={ postExcerpt }
iconPosition="left"
onClick={ () => getSuggestionFromOpenAI( 'summarize' ) }
onClick={ () => onSuggestionSelect( 'summarize' ) }
>
{ __( 'Summarize', 'jetpack' ) }
</MenuItem>
Expand All @@ -124,7 +124,7 @@ export default function PromptTemplatesControl( {
<MenuItem
icon={ title }
iconPosition="left"
onClick={ () => getSuggestionFromOpenAI( 'generateTitle' ) }
onClick={ () => onSuggestionSelect( 'generateTitle' ) }
>
{ __( 'Generate a post title', 'jetpack' ) }
</MenuItem>
Expand All @@ -136,7 +136,7 @@ export default function PromptTemplatesControl( {
<MenuItem
icon={ pencil }
iconPosition="left"
onClick={ () => getSuggestionFromOpenAI( 'titleSummary' ) }
onClick={ () => onSuggestionSelect( 'titleSummary' ) }
>
{ __( 'Summary based on title', 'jetpack' ) }
</MenuItem>
Expand All @@ -148,7 +148,7 @@ export default function PromptTemplatesControl( {
key={ `key-${ i }` }
onClick={ () => {
onClose();
onPromptSelected( prompt.description );
onPromptSelect( prompt.description );
} }
>
{ prompt.label }
Expand Down

0 comments on commit 2c94d44

Please sign in to comment.