Skip to content

Commit c7b9142

Browse files
authored
Merge pull request #2158 from google/fix/2157-gtm-settings-feedback
Consolidate GTM FormInstructions for consistent feedback
2 parents 546ac71 + b755286 commit c7b9142

File tree

4 files changed

+52
-92
lines changed

4 files changed

+52
-92
lines changed

assets/js/modules/tagmanager/components/common/FormInstructions.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,69 @@
1919
/**
2020
* WordPress dependencies
2121
*/
22-
import { __ } from '@wordpress/i18n';
22+
import { __, sprintf } from '@wordpress/i18n';
2323

2424
/**
2525
* Internal dependencies
2626
*/
2727
import Data from 'googlesitekit-data';
2828
import { STORE_NAME as CORE_SITE } from '../../../../googlesitekit/datastore/site/constants';
29+
import { STORE_NAME as CORE_MODULES } from '../../../../googlesitekit/modules/datastore/constants';
2930
import { STORE_NAME } from '../../datastore/constants';
31+
import { STORE_NAME as MODULES_ANALYTICS } from '../../../analytics/datastore/constants';
3032
import ExistingTagNotice from './ExistingTagNotice';
33+
import ErrorText from '../../../../components/error-text';
3134
const { useSelect } = Data;
3235

3336
export default function FormInstructions() {
3437
const hasExistingTag = useSelect( ( select ) => select( STORE_NAME ).hasExistingTag() );
3538
const isSecondaryAMP = useSelect( ( select ) => select( CORE_SITE ).isSecondaryAMP() );
39+
const singleAnalyticsPropertyID = useSelect( ( select ) => select( STORE_NAME ).getSingleAnalyticsPropertyID() );
40+
const hasMultipleAnalyticsPropertyIDs = useSelect( ( select ) => select( STORE_NAME ).hasMultipleAnalyticsPropertyIDs() );
41+
const analyticsPropertyID = useSelect( ( select ) => select( MODULES_ANALYTICS ).getPropertyID() );
42+
const analyticsModuleActive = useSelect( ( select ) => select( CORE_MODULES ).isModuleActive( 'analytics' ) );
43+
44+
// Multiple property IDs implies secondary AMP where selected containers don't reference the same Analytics property ID.
45+
if ( hasMultipleAnalyticsPropertyIDs ) {
46+
const message = __( 'Looks like you’re already using Google Analytics within your Google Tag Manager configurations. However, the configured Analytics tags reference different property IDs. You need to configure the same Analytics property in both containers.', 'google-site-kit' );
47+
48+
return <ErrorText message={ message } />;
49+
}
50+
51+
if ( analyticsModuleActive && singleAnalyticsPropertyID ) {
52+
// If the selected containers reference a different property ID
53+
// than is currently set in the Analytics module, display an error explaining why the user is blocked.
54+
if ( singleAnalyticsPropertyID !== analyticsPropertyID ) {
55+
/* translators: %1$s: Tag Manager Analytics property ID, %2$s: Analytics property ID */
56+
const message = __( 'Looks like you’re already using Google Analytics within your Google Tag Manager configuration. However, its Analytics property %1$s is different from the Analytics property %2$s, which is currently selected in the plugin. You need to configure the same Analytics property in both places.', 'google-site-kit' );
57+
58+
return <ErrorText message={ sprintf( message, singleAnalyticsPropertyID, analyticsPropertyID ) } />;
59+
}
60+
// If the Analytics property ID in the container(s) matches
61+
// the property ID configured for the Analytics module,
62+
// inform the user that Tag Manager will take over outputting the tag/snippet.
63+
return (
64+
<p>
65+
{
66+
sprintf(
67+
/* translators: %s: Analytics property ID */
68+
__( 'Looks like you’re using Google Analytics. Your Analytics property %s is already set up in your Google Tag Manager configuration, so Site Kit will switch to using Google Tag Manager for Analytics.', 'google-site-kit' ),
69+
singleAnalyticsPropertyID
70+
)
71+
}
72+
</p>
73+
);
74+
}
75+
76+
// If the Analytics module is not active, and selected containers reference a singular property ID,
77+
// recommend continuing with Analytics setup.
78+
if ( ! analyticsModuleActive && singleAnalyticsPropertyID ) {
79+
return (
80+
<p>
81+
{ __( 'Looks like you’re already using Google Analytics within your Google Tag Manager configuration. Activate the Google Analytics module in Site Kit to see relevant insights in your dashboard.', 'google-site-kit' ) }
82+
</p>
83+
);
84+
}
3685

3786
if ( hasExistingTag ) {
3887
return <ExistingTagNotice />;

assets/js/modules/tagmanager/components/setup/SetupForm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
import Button from '../../../../components/button';
4646
import Link from '../../../../components/link';
4747
import SetupErrorNotice from './SetupErrorNotice';
48-
import SetupFormInstructions from './SetupFormInstructions';
48+
import FormInstructions from '../common/FormInstructions';
4949
const { useSelect, useDispatch } = Data;
5050

5151
export default function SetupForm( { finishSetup } ) {
@@ -134,7 +134,7 @@ export default function SetupForm( { finishSetup } ) {
134134
onSubmit={ onSubmit }
135135
>
136136
<SetupErrorNotice />
137-
<SetupFormInstructions />
137+
<FormInstructions />
138138

139139
<div className="googlesitekit-setup-module__inputs">
140140
<AccountSelect />

assets/js/modules/tagmanager/components/setup/SetupFormInstructions.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

assets/js/modules/tagmanager/components/setup/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818

1919
export { default as SetupErrorNotice } from './SetupErrorNotice';
2020
export { default as SetupForm } from './SetupForm';
21-
export { default as SetupFormInstructions } from './SetupFormInstructions';
2221
export { default as SetupMain } from './SetupMain';

0 commit comments

Comments
 (0)