From f32b67f1780f91a43dc0b7497eac70eae7044b5b Mon Sep 17 00:00:00 2001 From: Asvin Balloo Date: Fri, 2 Feb 2024 15:56:31 +0400 Subject: [PATCH 01/95] Save WIP. --- js/src/data/action-types.js | 2 + js/src/data/actions.js | 7 ++ js/src/data/reducer.js | 16 ++++ js/src/data/resolvers.js | 28 ++++++- js/src/data/selectors.js | 10 +++ .../wordpress/guide/index.js | 4 + js/src/hooks/useAcceptedCustomerDataTerms.js | 23 ++++++ js/src/hooks/useAllowEnhancedConversions.js | 23 ++++++ .../EnhancedConversion.js | 57 +++++++++++++ .../EnhancedConversionFooter.js | 40 +++++++++ .../submission-success-guide/index.js | 82 ++++++++++--------- src/API/Google/Ads.php | 8 ++ .../Controllers/Ads/AccountController.php | 22 +++++ src/Ads/AccountService.php | 13 +++ 14 files changed, 294 insertions(+), 41 deletions(-) create mode 100644 js/src/hooks/useAcceptedCustomerDataTerms.js create mode 100644 js/src/hooks/useAllowEnhancedConversions.js create mode 100644 js/src/product-feed/submission-success-guide/EnhancedConversion.js create mode 100644 js/src/product-feed/submission-success-guide/EnhancedConversionFooter.js diff --git a/js/src/data/action-types.js b/js/src/data/action-types.js index 86556c5fda..7f54b4b323 100644 --- a/js/src/data/action-types.js +++ b/js/src/data/action-types.js @@ -49,6 +49,8 @@ const TYPES = { RECEIVE_TOUR: 'RECEIVE_TOUR', UPSERT_TOUR: 'UPSERT_TOUR', HYDRATE_PREFETCHED_DATA: 'HYDRATE_PREFETCHED_DATA', + RECEIVE_ACCEPTED_CUSTOMER_DATA_TERMS: + 'RECEIVE_ACCEPTED_CUSTOMER_DATA_TERMS', }; export default TYPES; diff --git a/js/src/data/actions.js b/js/src/data/actions.js index 8aba535605..97acd252cb 100644 --- a/js/src/data/actions.js +++ b/js/src/data/actions.js @@ -578,6 +578,13 @@ export function receiveGoogleMCContactInformation( data ) { }; } +export function receiveAcceptedTerms( data ) { + return { + type: TYPES.RECEIVE_ACCEPTED_CUSTOMER_DATA_TERMS, + data, + }; +} + /** * Update the contact information to user's account of Google Merchant Center. * It will update the store address of WooCommerce Settings to Google Merchant Center if they are different. diff --git a/js/src/data/reducer.js b/js/src/data/reducer.js index daf7b223e2..ac6ebc35d3 100644 --- a/js/src/data/reducer.js +++ b/js/src/data/reducer.js @@ -64,6 +64,10 @@ const DEFAULT_STATE = { report: {}, store_categories: [], tours: {}, + conversion_tracking_setting: { + accepted_customer_data_terms: false, + allow_enhanced_conversions: false, + }, }; /** @@ -491,6 +495,18 @@ const reducer = ( state = DEFAULT_STATE, action ) => { return stateSetter.end(); } + case TYPES.RECEIVE_ACCEPTED_CUSTOMER_DATA_TERMS: { + const { + data: { status }, + } = action; + + return setIn( + state, + 'conversion_tracking_setting.accepted_customer_data_terms', + status + ); + } + // Page will be reloaded after all accounts have been disconnected, so no need to mutate state. case TYPES.DISCONNECT_ACCOUNTS_ALL: default: diff --git a/js/src/data/resolvers.js b/js/src/data/resolvers.js index 37f4a564d5..268450bf31 100644 --- a/js/src/data/resolvers.js +++ b/js/src/data/resolvers.js @@ -45,6 +45,7 @@ import { receiveMappingRules, receiveStoreCategories, receiveTour, + receiveAcceptedTerms, } from './actions'; export function* getShippingRates() { @@ -470,13 +471,13 @@ getMappingRules.shouldInvalidate = ( action ) => { /** * Resolver for getting the Store categories. */ -export function* getStoreCategories() { +export function* getAcceptedCustomerDataTerms() { try { const response = yield apiFetch( { - path: `${ API_NAMESPACE }/mc/mapping/categories`, + path: `${ API_NAMESPACE }/ads/accepted-customer-data-terms`, } ); - yield receiveStoreCategories( response ); + yield receiveAcceptedTerms( response ); } catch ( error ) { handleApiError( error, @@ -519,3 +520,24 @@ export function* getTour( tourId ) { ); } } + +/** + * Resolver for getting the Store categories. + */ +export function* getStoreCategories() { + try { + const response = yield apiFetch( { + path: `${ API_NAMESPACE }/mc/mapping/categories`, + } ); + + yield receiveStoreCategories( response ); + } catch ( error ) { + handleApiError( + error, + __( + 'There was an error getting the store categories.', + 'google-listings-and-ads' + ) + ); + } +} diff --git a/js/src/data/selectors.js b/js/src/data/selectors.js index 181fb6c427..8498da7aa0 100644 --- a/js/src/data/selectors.js +++ b/js/src/data/selectors.js @@ -400,3 +400,13 @@ export const getStoreCategories = ( state ) => { export const getTour = ( state, tourId ) => { return state.tours[ tourId ] || null; }; + +export const getAcceptedCustomerDataTerms = ( state ) => { + return ( + state.conversion_tracking_setting.accepted_customer_data_terms || false + ); +}; + +export const getAllowEnhanceConversions = ( state ) => { + return state.allow_enhanced_conversions || false; +}; diff --git a/js/src/external-components/wordpress/guide/index.js b/js/src/external-components/wordpress/guide/index.js index de07985dfd..fd7d805d25 100644 --- a/js/src/external-components/wordpress/guide/index.js +++ b/js/src/external-components/wordpress/guide/index.js @@ -135,6 +135,9 @@ export default function Guide( { { backButtonText || __( 'Previous' ) } ) } + + { pages[ currentPage ]?.footer } + { canGoForward && ( ) } - { pages[ currentPage ]?.footer } - { canGoForward && (