BunnyNetPage.js
1 month ago
EmailCapturePage.js
1 month ago
GoogleAnalyticsPage.js
1 month ago
WebhooksPage.js
1 month ago
YouTubePage.js
1 month ago
GoogleAnalyticsPage.js
98 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { Container, Switch, Label, Input } from '@bsf/force-ui'; |
| 3 | import SettingsPageShell from '../shared/SettingsPageShell'; |
| 4 | import SectionCard from '../shared/SectionCard'; |
| 5 | import ProGate from '../shared/ProGate'; |
| 6 | import useSimpleSettingsPage from '../../../hooks/useSimpleSettingsPage'; |
| 7 | import { OPTION_KEYS } from '../config'; |
| 8 | |
| 9 | const DEFAULTS = { |
| 10 | enable: false, |
| 11 | use_existing_tag: false, |
| 12 | measurement_id: '', |
| 13 | }; |
| 14 | |
| 15 | const isPremium = window.prestoPlayer?.isPremium ?? false; |
| 16 | |
| 17 | const GoogleAnalyticsPage = ( { registerActivePage } ) => { |
| 18 | const { data, update, handleSave, isDirty, isSaving, isLoading } = |
| 19 | useSimpleSettingsPage( |
| 20 | OPTION_KEYS.googleAnalytics, |
| 21 | DEFAULTS, |
| 22 | registerActivePage |
| 23 | ); |
| 24 | |
| 25 | return ( |
| 26 | <SettingsPageShell |
| 27 | title={ __( 'Google Analytics', 'presto-player' ) } |
| 28 | isDirty={ isDirty } |
| 29 | isSaving={ isSaving } |
| 30 | isLoading={ isLoading } |
| 31 | onSave={ handleSave } |
| 32 | > |
| 33 | <SectionCard> |
| 34 | <ProGate |
| 35 | enabled={ isPremium } |
| 36 | title={ __( 'Google Analytics', 'presto-player' ) } |
| 37 | description={ __( |
| 38 | 'Send media events directly to your Google Analytics account.', |
| 39 | 'presto-player' |
| 40 | ) } |
| 41 | > |
| 42 | <Container direction="column" className="gap-4"> |
| 43 | <Switch |
| 44 | size="md" |
| 45 | value={ !! data.enable } |
| 46 | onChange={ ( val ) => update( { enable: val } ) } |
| 47 | label={ { |
| 48 | heading: __( 'Enable', 'presto-player' ), |
| 49 | description: __( |
| 50 | 'Send analytics events to your Google Analytics account.', |
| 51 | 'presto-player' |
| 52 | ), |
| 53 | } } |
| 54 | /> |
| 55 | |
| 56 | { data.enable && ( |
| 57 | <> |
| 58 | <Switch |
| 59 | size="md" |
| 60 | value={ !! data.use_existing_tag } |
| 61 | onChange={ ( val ) => update( { use_existing_tag: val } ) } |
| 62 | label={ { |
| 63 | heading: __( 'Use existing on-page tag?', 'presto-player' ), |
| 64 | description: __( |
| 65 | "Should we use an existing Google Analytics (v4) tag? If not, we'll output one for you.", |
| 66 | 'presto-player' |
| 67 | ), |
| 68 | } } |
| 69 | /> |
| 70 | |
| 71 | <Container.Item className="flex flex-col gap-2"> |
| 72 | <Label size="sm"> |
| 73 | { __( 'Measurement ID', 'presto-player' ) } |
| 74 | </Label> |
| 75 | <Input |
| 76 | size="md" |
| 77 | value={ data.measurement_id || '' } |
| 78 | onChange={ ( val ) => update( { measurement_id: val } ) } |
| 79 | placeholder="G-XXXXXXXXXX" |
| 80 | /> |
| 81 | <Label size="xs" variant="help"> |
| 82 | { __( |
| 83 | 'Enter a Google Analytics Measurement ID, which can be found on your analytics admin page.', |
| 84 | 'presto-player' |
| 85 | ) } |
| 86 | </Label> |
| 87 | </Container.Item> |
| 88 | </> |
| 89 | ) } |
| 90 | </Container> |
| 91 | </ProGate> |
| 92 | </SectionCard> |
| 93 | </SettingsPageShell> |
| 94 | ); |
| 95 | }; |
| 96 | |
| 97 | export default GoogleAnalyticsPage; |
| 98 |