Skip to content

Commit 7ce9329

Browse files
chore: disable prompt usage tracking
1 parent 310d548 commit 7ce9329

File tree

2 files changed

+88
-81
lines changed

2 files changed

+88
-81
lines changed

inc/server/class-prompt-server.php

+76-68
Original file line numberDiff line numberDiff line change
@@ -116,74 +116,6 @@ function ( $key ) {
116116
// Remove the values which keys start with 'otter_'.
117117
$body = array_diff_key( $body, $otter_data );
118118

119-
120-
if ( isset( $otter_data['otter_used_action'] ) && isset( $otter_data['otter_user_content'] ) ) {
121-
122-
$action = $otter_data['otter_used_action'];
123-
$user_content = $otter_data['otter_user_content'];
124-
125-
$usage = get_option( 'themeisle_otter_ai_usage' );
126-
127-
if ( ! is_array( $usage ) ) {
128-
$usage = array(
129-
'usage_count' => array(),
130-
'prompts' => array(),
131-
);
132-
}
133-
134-
if ( ! is_array( $usage['usage_count'] ) ) {
135-
$usage['usage_count'] = array();
136-
}
137-
138-
if ( ! is_array( $usage['prompts'] ) ) {
139-
$usage['prompts'] = array();
140-
}
141-
142-
$is_missing = true;
143-
144-
foreach ( $usage['usage_count'] as &$u ) {
145-
if ( isset( $u['key'] ) && $u['key'] === $action ) {
146-
$u['value']++;
147-
$is_missing = false;
148-
}
149-
}
150-
151-
unset( $u );
152-
153-
if ( $is_missing ) {
154-
$usage['usage_count'][] = array(
155-
'key' => $action,
156-
'value' => 1,
157-
);
158-
}
159-
160-
$is_missing = true;
161-
162-
foreach ( $usage['prompts'] as &$u ) {
163-
if ( isset( $u['key'] ) && $u['key'] === $action ) {
164-
$u['values'][] = $user_content;
165-
$is_missing = false;
166-
167-
// Keep only the last 10 prompts.
168-
if ( count( $u['values'] ) > 10 ) {
169-
array_shift( $u['values'] );
170-
}
171-
}
172-
}
173-
174-
unset( $u );
175-
176-
if ( $is_missing ) {
177-
$usage['prompts'][] = array(
178-
'key' => $action,
179-
'values' => array( $user_content ),
180-
);
181-
}
182-
183-
update_option( 'themeisle_otter_ai_usage', $usage );
184-
}
185-
186-
187119
$response = wp_remote_post(
188120
$open_ai_endpoint,
189121
array(
@@ -343,6 +275,82 @@ public function check_prompt_structure( $response ) {
343275
return true;
344276
}
345277

278+
/**
279+
* Record prompt usage.
280+
*
281+
* @param array $otter_metadata The metadata from the prompt usage request.
282+
* @return void
283+
* @phpstan-ignore-next-line
284+
*/
285+
private function record_prompt_usage( $otter_metadata ) {
286+
if ( ! isset( $otter_metadata['otter_used_action'] ) || ! isset( $otter_metadata['otter_user_content'] ) ) {
287+
return;
288+
}
289+
290+
$action = $otter_metadata['otter_used_action'];
291+
$user_content = $otter_metadata['otter_user_content'];
292+
293+
$usage = get_option( 'themeisle_otter_ai_usage' );
294+
295+
if ( ! is_array( $usage ) ) {
296+
$usage = array(
297+
'usage_count' => array(),
298+
'prompts' => array(),
299+
);
300+
}
301+
302+
if ( ! is_array( $usage['usage_count'] ) ) {
303+
$usage['usage_count'] = array();
304+
}
305+
306+
if ( ! is_array( $usage['prompts'] ) ) {
307+
$usage['prompts'] = array();
308+
}
309+
310+
$is_missing = true;
311+
312+
foreach ( $usage['usage_count'] as &$u ) {
313+
if ( isset( $u['key'] ) && $u['key'] === $action ) {
314+
$u['value']++;
315+
$is_missing = false;
316+
}
317+
}
318+
319+
unset( $u );
320+
321+
if ( $is_missing ) {
322+
$usage['usage_count'][] = array(
323+
'key' => $action,
324+
'value' => 1,
325+
);
326+
}
327+
328+
$is_missing = true;
329+
330+
foreach ( $usage['prompts'] as &$u ) {
331+
if ( isset( $u['key'] ) && $u['key'] === $action ) {
332+
$u['values'][] = $user_content;
333+
$is_missing = false;
334+
335+
// Keep only the last 10 prompts.
336+
if ( count( $u['values'] ) > 10 ) {
337+
array_shift( $u['values'] );
338+
}
339+
}
340+
}
341+
342+
unset( $u );
343+
344+
if ( $is_missing ) {
345+
$usage['prompts'][] = array(
346+
'key' => $action,
347+
'values' => array( $user_content ),
348+
);
349+
}
350+
351+
update_option( 'themeisle_otter_ai_usage', $usage );
352+
}
353+
346354

347355
/**
348356
* The instance method for the static class.

src/blocks/components/prompt/index.tsx

+12-13
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ const PromptPlaceholder = ( props: PromptPlaceholderProps ) => {
220220
}
221221
if ( 'yes' === getOption( 'otter_blocks_logger_flag' ) ) {
222222
setTrackingConsent( true );
223-
console.log( 'tracking consent', getOption( 'otter_blocks_logger_flag' ) );
224223
setShowTrackingConsent( false );
225224
}
226225
}
@@ -438,18 +437,18 @@ const PromptPlaceholder = ( props: PromptPlaceholderProps ) => {
438437
placeholder={ props.promptPlaceholder }
439438
/>
440439

441-
{
442-
showTrackingConsent && (
443-
<TrackingConsentToggle
444-
onToggle={ onToggleTrackingConsent }
445-
value={ trackingConsent }
446-
onClose={() => {
447-
setShowTrackingConsent( false );
448-
localStorage.setItem( 'o-tracking-consent', 'true' );
449-
}}
450-
/>
451-
)
452-
}
440+
{/*{*/}
441+
{/* showTrackingConsent && (*/}
442+
{/* <TrackingConsentToggle*/}
443+
{/* onToggle={ onToggleTrackingConsent }*/}
444+
{/* value={ trackingConsent }*/}
445+
{/* onClose={() => {*/}
446+
{/* setShowTrackingConsent( false );*/}
447+
{/* localStorage.setItem( 'o-tracking-consent', 'true' );*/}
448+
{/* }}*/}
449+
{/* />*/}
450+
{/* )*/}
451+
{/*}*/}
453452

454453
{props.children}
455454
</PromptBlockEditor>

0 commit comments

Comments
 (0)