|
19 | 19 | /**
|
20 | 20 | * WordPress dependencies
|
21 | 21 | */
|
22 |
| -import { __ } from '@wordpress/i18n'; |
| 22 | +import { __, sprintf } from '@wordpress/i18n'; |
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * Internal dependencies
|
26 | 26 | */
|
27 | 27 | import Data from 'googlesitekit-data';
|
28 | 28 | import { STORE_NAME as CORE_SITE } from '../../../../googlesitekit/datastore/site/constants';
|
| 29 | +import { STORE_NAME as CORE_MODULES } from '../../../../googlesitekit/modules/datastore/constants'; |
29 | 30 | import { STORE_NAME } from '../../datastore/constants';
|
| 31 | +import { STORE_NAME as MODULES_ANALYTICS } from '../../../analytics/datastore/constants'; |
30 | 32 | import ExistingTagNotice from './ExistingTagNotice';
|
| 33 | +import ErrorText from '../../../../components/error-text'; |
31 | 34 | const { useSelect } = Data;
|
32 | 35 |
|
33 | 36 | export default function FormInstructions() {
|
34 | 37 | const hasExistingTag = useSelect( ( select ) => select( STORE_NAME ).hasExistingTag() );
|
35 | 38 | 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 | + } |
36 | 85 |
|
37 | 86 | if ( hasExistingTag ) {
|
38 | 87 | return <ExistingTagNotice />;
|
|
0 commit comments