<commit_before>/**
 * Analytics Tracking Exclusion switches component.
 *
 * Site Kit by Google, Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import {
	useSelect as useSelectHook,
	useDispatch as useDispatchHook,
} from '@wordpress/data';
import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import PropTypes from 'prop-types';
import Switch from 'GoogleComponents/switch';

const STORE_NAME = 'modules/analytics'; // temp

const TRACKING_LOGGED_IN_USERS = 'loggedinUsers';

const trackingExclusionLabels = {
	[ TRACKING_LOGGED_IN_USERS ]: __( 'Logged-in users', 'google-site-kit' ),
};

export default function TrackingExclusionSwitches( { useSelect, useDispatch } ) {
	const trackingDisabled = useSelect( ( select ) => select( STORE_NAME ).getTrackingDisabled() );

	const { setTrackingDisabled } = useDispatch( STORE_NAME );
	const onChange = useCallback( ( e ) => {
		const { checked } = e.target;
		const exclusions = checked ? [ TRACKING_LOGGED_IN_USERS ] : [];
		setTrackingDisabled( exclusions );
	}, [ trackingDisabled ] );

	return (
		<div className="googlesitekit-analytics-trackingdisabled">
			<div className="mdc-form-field">
				<Switch
					label={ trackingExclusionLabels[ TRACKING_LOGGED_IN_USERS ] }
					checked={ trackingDisabled.includes( TRACKING_LOGGED_IN_USERS ) }
					onClick={ onChange }
					hideLabel={ false }
				/>
			</div>

			<p>
				{ trackingDisabled.includes( TRACKING_LOGGED_IN_USERS )
					? __( 'Logged-in users will be excluded from Analytics tracking.', 'google-site-kit' )
					: __( 'Logged-in users will be included in Analytics tracking.', 'google-site-kit' )
				}<commit_msg>Export tracking exclusion labels for use in settings.<commit_after>/**
 * Analytics Tracking Exclusion switches component.
 *
 * Site Kit by Google, Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import {
	useSelect as useSelectHook,
	useDispatch as useDispatchHook,
} from '@wordpress/data';
import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import PropTypes from 'prop-types';
import Switch from 'GoogleComponents/switch';

const STORE_NAME = 'modules/analytics'; // temp

const TRACKING_LOGGED_IN_USERS = 'loggedinUsers';

export const trackingExclusionLabels = {
	[ TRACKING_LOGGED_IN_USERS ]: __( 'Logged-in users', 'google-site-kit' ),
};

export default function TrackingExclusionSwitches( { useSelect, useDispatch } ) {
	const trackingDisabled = useSelect( ( select ) => select( STORE_NAME ).getTrackingDisabled() );

	const { setTrackingDisabled } = useDispatch( STORE_NAME );
	const onChange = useCallback( ( e ) => {
		const { checked } = e.target;
		const exclusions = checked ? [ TRACKING_LOGGED_IN_USERS ] : [];
		setTrackingDisabled( exclusions );
	}, [ trackingDisabled ] );

	return (
		<div className="googlesitekit-analytics-trackingdisabled">
			<div className="mdc-form-field">
				<Switch
					label={ trackingExclusionLabels[ TRACKING_LOGGED_IN_USERS ] }
					checked={ trackingDisabled.includes( TRACKING_LOGGED_IN_USERS ) }
					onClick={ onChange }
					hideLabel={ false }
				/>
			</div>

			<p>
				{ trackingDisabled.includes( TRACKING_LOGGED_IN_USERS )
					? __( 'Logged-in users will be excluded from Analytics tracking.', 'google-site-kit' )
					: __( 'Logged-in users will be included in Analytics tracking.', 'google-site-kit' )
				}
{'fraction_non_alphanumeric': 0.10433026699573704, 'fraction_numerical': 0.004487323311644604, 'mean_word_length': 4.232394366197183, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2892117', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1291, 'n_words': 404}