Skip to content

Commit

Permalink
Merge pull request #5916 from google/followup/5621-alt
Browse files Browse the repository at this point in the history
Fix GA4 issues when connecting after initial setup
  • Loading branch information
techanvil authored Sep 27, 2022
2 parents 91a5f1d + c89702b commit 5a442c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions assets/js/modules/analytics-4/datastore/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
PROPERTY_CREATE,
WEBDATASTREAM_CREATE,
} from './constants';
import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants';

// Invariant error messages.
export const INVARIANT_INVALID_PROPERTY_SELECTION =
Expand Down Expand Up @@ -96,6 +97,14 @@ export async function submitChanges( { select, dispatch } ) {
if ( error ) {
return { error };
}

if (
select( CORE_MODULES ).isModuleConnected( 'analytics' ) &&
! select( CORE_MODULES ).isModuleConnected( 'analytics-4' )
) {
// Refresh modules from server if GA4 was connected after initial setup.
await dispatch( CORE_MODULES ).fetchGetModules();
}
}

await API.invalidateCache( 'modules', 'analytics-4' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,21 @@ export default function GA4SettingsControls( { hasModuleAccess } ) {

useEffect( () => {
// Ensure preselection of the GA4 property works when navigating from the "Connect Google Analytics 4" CTA button.
if ( enableGA4 && ! propertyID && matchedProperty ) {
if (
enableGA4 &&
! propertyID &&
matchedProperty &&
matchedWebDataStream
) {
onActivate();
}
}, [ enableGA4, matchedProperty, onActivate, propertyID ] );
}, [
enableGA4,
matchedProperty,
matchedWebDataStream,
onActivate,
propertyID,
] );

if ( isAdminAPIWorking === undefined ) {
return <ProgressBar height={ isDisabled ? 180 : 212 } small />;
Expand Down

0 comments on commit 5a442c2

Please sign in to comment.