Skip to content

Commit cf40241

Browse files
committed
remove conversion access token field
1 parent adea883 commit cf40241

File tree

13 files changed

+16
-248
lines changed

13 files changed

+16
-248
lines changed

includes/API/Site/Controllers/RedditConnectionController.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,6 @@ public function do_config( WP_REST_Request $request ) {
376376
Options::set( OptionDefaults::PIXEL_ID, sanitize_text_field( $params['pixel_id'] ) );
377377
}
378378

379-
if ( isset( $params['capi_token'] ) ) {
380-
Options::set( OptionDefaults::CONVERSION_ACCESS_TOKEN, sanitize_text_field( $params['capi_token'] ) );
381-
}
382-
383379
$is_jetpack_connected = 'yes' === Options::get( OptionDefaults::IS_JETPACK_CONNECTED );
384380
$business_id = Options::get( OptionDefaults::BUSINESS_ID );
385381
$ad_account_id = Options::get( OptionDefaults::AD_ACCOUNT_ID );
@@ -431,7 +427,6 @@ public function get_connection_details() {
431427
'ad_account_id' => Options::get( OptionDefaults::AD_ACCOUNT_ID ),
432428
'ad_account_name' => Options::get( OptionDefaults::AD_ACCOUNT_NAME ),
433429
'pixel_id' => Options::get( OptionDefaults::PIXEL_ID ),
434-
'capi_token' => Options::get( OptionDefaults::CONVERSION_ACCESS_TOKEN ),
435430
)
436431
);
437432
}
@@ -598,10 +593,6 @@ public function config_schema() {
598593
'description' => 'Selected Pixel id.',
599594
'type' => 'string',
600595
),
601-
'capi_token' => array(
602-
'description' => 'Conversion Access token.',
603-
'type' => 'string',
604-
),
605596
),
606597
);
607598
}

includes/API/Site/Controllers/SettingsController.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,11 @@ public function get_settings() {
7575
* @return WP_REST_Response
7676
*/
7777
public function set_settings( $request ) {
78-
$capi_token = null;
79-
8078
if ( isset( $request['capi_enabled'] ) ) {
8179
$capi_status = rest_sanitize_boolean( $request['capi_enabled'] );
8280
Options::set( OptionDefaults::CONVERSIONS_ENABLED, $capi_status ? 'yes' : 'no' );
8381
}
8482

85-
if ( isset( $request['capi_token'] ) ) {
86-
$capi_token = sanitize_text_field( $request['capi_token'] );
87-
Options::set( OptionDefaults::CONVERSION_ACCESS_TOKEN, $capi_token );
88-
89-
if ( empty( $capi_token ) ) {
90-
Options::set( OptionDefaults::CONVERSIONS_ENABLED, 'no' );
91-
}
92-
}
93-
9483
if ( isset( $request['products_token'] ) ) {
9584
Options::set( OptionDefaults::WCS_PRODUCTS_TOKEN, sanitize_text_field( $request['products_token'] ) );
9685
}
@@ -115,7 +104,6 @@ private function get_settings_response() {
115104

116105
return rest_ensure_response(
117106
array(
118-
'capi_token' => Options::get( OptionDefaults::CONVERSION_ACCESS_TOKEN ),
119107
'capi_enabled' => 'yes' === Options::get( OptionDefaults::CONVERSIONS_ENABLED ),
120108
'trigger_export' => ! file_exists( $csv_path ) && Helper::has_products() && (int) $timestamp <= ( time() - DAY_IN_SECONDS ),
121109
'last_export_timestamp' => Helper::get_formatted_timestamp( $timestamp ),

includes/Tracking/RemoteConversionTracker.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,9 @@ public function track_page_view( string $event_id = '' ): void {
245245
* @return void
246246
*/
247247
public function send( array $event_payload, array $args = array() ): void {
248-
$token = Options::get( OptionDefaults::CONVERSION_ACCESS_TOKEN );
249248
$pixel_id = Options::get( OptionDefaults::PIXEL_ID );
250249

251-
if ( ! $token || ! $pixel_id ) {
250+
if ( ! $pixel_id ) {
252251
return;
253252
}
254253

@@ -258,10 +257,7 @@ public function send( array $event_payload, array $args = array() ): void {
258257
$response = $this->client->proxy_post(
259258
$path,
260259
$event_payload,
261-
false,
262-
array(
263-
'reddit-authorization' => sprintf( 'Bearer %s', $token ),
264-
)
260+
false
265261
);
266262

267263
if ( Helper::is_logging_enabled() ) {

includes/Utils/Storage/OptionDefaults.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ final class OptionDefaults {
102102
*/
103103
public const CONVERSIONS_ENABLED = 'conversion_enabled';
104104

105-
/**
106-
* Option key for the Ad Partner's Conversion Token.
107-
*
108-
* @since 0.1.0
109-
*/
110-
public const CONVERSION_ACCESS_TOKEN = 'conversion_access_token';
111-
112105
/**
113106
* Option key for the Ad Partner's Catalog ID.
114107
*
@@ -197,7 +190,6 @@ public static function get_all(): array {
197190
self::PIXEL_ENABLED => 'yes',
198191
self::PIXEL_ID => '',
199192
self::CONVERSIONS_ENABLED => 'no',
200-
self::CONVERSION_ACCESS_TOKEN => '',
201193
self::CATALOG_ID => '',
202194
self::PRODUCT_FEED_ID => '',
203195
self::FEED_STATUS => 'empty',

js/src/data/actions.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,11 @@ export async function updateSettings( updatedSettings ) {
185185
data: {
186186
// Convert settings keys to match REST keys
187187
capi_enabled: updatedSettings.trackConversions,
188-
capi_token: updatedSettings.capiToken,
189188
products_token: updatedSettings.productsToken,
190189
},
191190
} );
192191

193192
return receiveSettings( {
194-
capiToken: response.capi_token,
195193
catalogId: response.catalog_id,
196194
exportFileUrl: response.export_file_url,
197195
lastExportTimeStamp: response.last_export_timestamp,

js/src/data/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const store = createReduxStore( STORE_KEY, {
3636
reddit: null,
3737
trackConversions: null,
3838
settings: {
39-
capiToken: '',
4039
catalogId: '',
4140
exportFileUrl: '',
4241
lastExportTimeStamp: '',

js/src/data/resolvers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export function getSettings() {
125125

126126
dispatch(
127127
receiveSettings( {
128-
capiToken: response.capi_token,
129128
catalogId: response.catalog_id,
130129
exportFileUrl: response.export_file_url,
131130
lastExportTimeStamp: response.last_export_timestamp,

js/src/data/selectors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
* @property {string} ad_account_id The Reddit ad account ID.
4848
* @property {string} ad_account_name The name of the Reddit ad account.
4949
* @property {string} pixel_id The Reddit pixel ID.
50-
* @property {string} capi_token The Reddit CAPI token.
5150
*/
5251

5352
/**

js/src/hooks/useSettings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const useSettings = () => {
2828

2929
return {
3030
productsToken: settings.productsToken,
31-
capiToken: settings.capiToken,
3231
isCapiEnabled: settings.trackConversions,
3332
shouldTriggerExport: settings.triggerExport,
3433
lastExportTimeStamp: settings.lastExportTimeStamp,

js/src/pages/settings/conversions-api/index.js

Lines changed: 14 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22
* External dependencies
33
*/
44
import { __ } from '@wordpress/i18n';
5-
import { CheckboxControl, TextControl } from '@wordpress/components';
6-
import {
7-
useState,
8-
useCallback,
9-
useEffect,
10-
createInterpolateElement,
11-
} from '@wordpress/element';
5+
import { CheckboxControl } from '@wordpress/components';
6+
import { useState, useCallback } from '@wordpress/element';
127

138
/**
149
* Internal dependencies
1510
*/
1611
import { useAppDispatch } from '~/data';
17-
import AppDocumentationLink from '~/components/app-documentation-link';
1812
import useSettings from '~/hooks/useSettings';
1913
import useDispatchCoreNotices from '~/hooks/useDispatchCoreNotices';
20-
import useDebouncedInput from '~/hooks/useDebouncedInput';
2114
import AccountCard from '~/components/account-card';
2215
import SpinnerCard from '~/components/spinner-card';
2316
import './index.scss';
@@ -32,24 +25,15 @@ import './index.scss';
3225
* @return {JSX.Element} The rendered ConversionsAPI settings card.
3326
*/
3427
const ConversionsAPI = () => {
35-
const { isCapiEnabled, capiToken, hasFinishedResolution } = useSettings();
28+
const { isCapiEnabled, hasFinishedResolution } = useSettings();
3629
const [ isSaving, setIsSaving ] = useState( false );
37-
const [ localCapiToken, setLocalCapiToken, debouncedLocalCapiToken ] =
38-
useDebouncedInput( '' );
3930
const { createNotice } = useDispatchCoreNotices();
4031
const { updateSettings } = useAppDispatch();
4132

4233
const toggleTrackConversions = useCallback( async () => {
4334
await updateSettings( { trackConversions: ! isCapiEnabled } );
4435
}, [ updateSettings, isCapiEnabled ] );
4536

46-
const updateConversionAccessToken = useCallback(
47-
async ( val ) => {
48-
await updateSettings( { capiToken: val } );
49-
},
50-
[ updateSettings ]
51-
);
52-
5337
const handleCapiStatusOnChange = async () => {
5438
try {
5539
setIsSaving( true );
@@ -69,59 +53,6 @@ const ConversionsAPI = () => {
6953
}
7054
};
7155

72-
const handleCapiTokenOnChange = useCallback(
73-
async ( val = '' ) => {
74-
try {
75-
setIsSaving( true );
76-
await updateConversionAccessToken( val );
77-
78-
createNotice(
79-
'success',
80-
__(
81-
'Conversions API Access Token updated successfully.',
82-
'reddit-for-woocommerce'
83-
)
84-
);
85-
} catch ( error ) {
86-
// Silently fail because the error is handled within `updateSettings` action.
87-
} finally {
88-
setIsSaving( false );
89-
}
90-
},
91-
[ updateConversionAccessToken, createNotice ]
92-
);
93-
94-
/**
95-
* Validates and sets the CAPI token state.
96-
*
97-
* @param {string} token Input CAPI token
98-
*/
99-
function setToken( token ) {
100-
if ( token !== '' && token.trim() === '' ) {
101-
// Return early if the string is only '\s'
102-
return;
103-
}
104-
105-
setLocalCapiToken( token );
106-
}
107-
108-
useEffect( () => {
109-
if ( hasFinishedResolution ) {
110-
setLocalCapiToken( capiToken );
111-
}
112-
}, [ hasFinishedResolution, setLocalCapiToken, capiToken ] );
113-
114-
useEffect( () => {
115-
if ( undefined === capiToken ) {
116-
return;
117-
}
118-
119-
if ( capiToken !== debouncedLocalCapiToken ) {
120-
handleCapiTokenOnChange( debouncedLocalCapiToken );
121-
}
122-
// eslint-disable-next-line react-hooks/exhaustive-deps
123-
}, [ debouncedLocalCapiToken, handleCapiTokenOnChange ] );
124-
12556
if ( ! hasFinishedResolution ) {
12657
return <SpinnerCard />;
12758
}
@@ -135,54 +66,17 @@ const ConversionsAPI = () => {
13566
'reddit-for-woocommerce'
13667
) }
13768
actions={
138-
<>
139-
<div>
140-
<TextControl
141-
label={ __(
142-
'Conversion Access Token',
143-
'reddit-for-woocommerce'
144-
) }
145-
id="rfw-settings-capi-token"
146-
value={ localCapiToken }
147-
readOnly={ isSaving }
148-
onChange={ setToken }
149-
help={
150-
<>
151-
{ createInterpolateElement(
152-
__(
153-
'Need help? <link>Follow this guide</link>',
154-
'reddit-for-woocommerce'
155-
),
156-
{
157-
link: (
158-
<AppDocumentationLink href="https://ads.reddit.com/events-manager/conversion-tokens" />
159-
),
160-
}
161-
) }
162-
</>
163-
}
164-
/>
165-
</div>
166-
<div className="rfw-settings-track-conversions__actions">
167-
<CheckboxControl
168-
label={ __(
169-
'Enable Conversions API tracking',
170-
'reddit-for-woocommerce'
171-
) }
172-
checked={ isCapiEnabled }
173-
disabled={ isSaving || ! localCapiToken }
174-
onChange={ handleCapiStatusOnChange }
175-
help={
176-
! localCapiToken
177-
? __(
178-
'Set the Conversion Access Token to enable tracking',
179-
'reddit-for-woocommerce'
180-
)
181-
: ''
182-
}
183-
/>
184-
</div>
185-
</>
69+
<div className="rfw-settings-track-conversions__actions">
70+
<CheckboxControl
71+
label={ __(
72+
'Enable Conversions API tracking',
73+
'reddit-for-woocommerce'
74+
) }
75+
checked={ isCapiEnabled }
76+
disabled={ isSaving }
77+
onChange={ handleCapiStatusOnChange }
78+
/>
79+
</div>
18680
}
18781
/>
18882
);

0 commit comments

Comments
 (0)