|
| 1 | +import React from "react" |
| 2 | +import Chip from "@mui/material/Chip"; |
| 3 | +import Divider from '@mui/material/Divider'; |
| 4 | +import { styled } from "@mui/material/styles" |
| 5 | +import Typography from "@mui/material/Typography" |
| 6 | +import TextField from "@mui/material/TextField" |
| 7 | +import Grid from "@mui/material/Grid" |
| 8 | + |
| 9 | +import LinkedTextField from "@/components/LinkedTextField" |
| 10 | +import ExternalLink from "@/components/ExternalLink" |
| 11 | +import { Label } from "./types" |
| 12 | + |
| 13 | +const Root = styled("div")(({ theme }) => ({ |
| 14 | + marginTop: theme.spacing(3), |
| 15 | +})) |
| 16 | + |
| 17 | +interface GeographicInformationProps { |
| 18 | + user_location_city: string | undefined |
| 19 | + setUserLocationCity: (value: string) => void |
| 20 | + user_location_region_id: string | undefined |
| 21 | + setUserLocationRegionId: (value: string) => void |
| 22 | + user_location_country_id: string | undefined |
| 23 | + setUserLocationCountryId: (value: string) => void |
| 24 | + user_location_subcontinent_id: string | undefined |
| 25 | + setUserLocationSubcontinentId: (value: string) => void |
| 26 | + user_location_continent_id: string | undefined |
| 27 | + setUserLocationContinentId: (value: string) => void |
| 28 | + ip_override: string | undefined |
| 29 | + setIpOverride: (value: string) => void |
| 30 | +} |
| 31 | + |
| 32 | +const GeographicInformation: React.FC<GeographicInformationProps> = ({ |
| 33 | + user_location_city, |
| 34 | + setUserLocationCity, |
| 35 | + user_location_region_id, |
| 36 | + setUserLocationRegionId, |
| 37 | + user_location_country_id, |
| 38 | + setUserLocationCountryId, |
| 39 | + user_location_subcontinent_id, |
| 40 | + setUserLocationSubcontinentId, |
| 41 | + user_location_continent_id, |
| 42 | + setUserLocationContinentId, |
| 43 | + ip_override, |
| 44 | + setIpOverride, |
| 45 | +}) => { |
| 46 | + return ( |
| 47 | + <Root> |
| 48 | + <Divider><Chip label="GEOGRAPHIC INFORMATION" size="small" /></Divider> |
| 49 | + <Typography variant="h6">User Location</Typography> |
| 50 | + <Typography> |
| 51 | + See the{" "} |
| 52 | + <ExternalLink href="https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference#user_location"> |
| 53 | + documentation |
| 54 | + </ExternalLink>{" "} |
| 55 | + for more information about user location attributes. |
| 56 | + </Typography> |
| 57 | + <Grid container spacing={1}> |
| 58 | + <Grid item xs={12} sm={6}> |
| 59 | + <TextField |
| 60 | + fullWidth |
| 61 | + label={Label.City} |
| 62 | + id={Label.City} |
| 63 | + variant="outlined" |
| 64 | + size="small" |
| 65 | + value={user_location_city || ""} |
| 66 | + onChange={e => setUserLocationCity(e.target.value)} |
| 67 | + helperText="The city name, e.g., Mountain View" |
| 68 | + /> |
| 69 | + </Grid> |
| 70 | + <Grid item xs={12} sm={6}> |
| 71 | + <TextField |
| 72 | + fullWidth |
| 73 | + label={Label.RegionId} |
| 74 | + id={Label.RegionId} |
| 75 | + variant="outlined" |
| 76 | + size="small" |
| 77 | + value={user_location_region_id || ""} |
| 78 | + onChange={e => setUserLocationRegionId(e.target.value)} |
| 79 | + helperText="The country and subdivision, e.g., US-CA" |
| 80 | + /> |
| 81 | + </Grid> |
| 82 | + <Grid item xs={12} sm={6}> |
| 83 | + <TextField |
| 84 | + fullWidth |
| 85 | + label={Label.CountryId} |
| 86 | + id={Label.CountryId} |
| 87 | + variant="outlined" |
| 88 | + size="small" |
| 89 | + value={user_location_country_id || ""} |
| 90 | + onChange={e => setUserLocationCountryId(e.target.value)} |
| 91 | + helperText="The country code, e.g., US" |
| 92 | + /> |
| 93 | + </Grid> |
| 94 | + <Grid item xs={12} sm={6}> |
| 95 | + <TextField |
| 96 | + fullWidth |
| 97 | + label={Label.ContinentId} |
| 98 | + id={Label.ContinentId} |
| 99 | + variant="outlined" |
| 100 | + size="small" |
| 101 | + value={user_location_continent_id || ""} |
| 102 | + onChange={e => setUserLocationContinentId(e.target.value)} |
| 103 | + helperText="The continent code, e.g., 019" |
| 104 | + /> |
| 105 | + </Grid> |
| 106 | + <Grid item xs={12} sm={6}> |
| 107 | + <TextField |
| 108 | + fullWidth |
| 109 | + label={Label.SubcontinentId} |
| 110 | + id={Label.SubcontinentId} |
| 111 | + variant="outlined" |
| 112 | + size="small" |
| 113 | + value={user_location_subcontinent_id || ""} |
| 114 | + onChange={e => setUserLocationSubcontinentId(e.target.value)} |
| 115 | + helperText="The subcontinent code, e.g., 021" |
| 116 | + /> |
| 117 | + </Grid> |
| 118 | + </Grid> |
| 119 | + <Typography variant="h6">IP Override</Typography> |
| 120 | + <Typography> |
| 121 | + Provide an IP address to derive the user's geographic location. If |
| 122 | + both an IP override and user location are provided, user location will |
| 123 | + be used. |
| 124 | + </Typography> |
| 125 | + <LinkedTextField |
| 126 | + label={Label.IpOverride} |
| 127 | + id={Label.IpOverride} |
| 128 | + linkTitle="See ip_override on devsite." |
| 129 | + href="https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference#ip_override" |
| 130 | + value={ip_override || ""} |
| 131 | + onChange={setIpOverride} |
| 132 | + helperText="The IP address of the user." |
| 133 | + /> |
| 134 | + </Root> |
| 135 | + ) |
| 136 | +} |
| 137 | + |
| 138 | +export default GeographicInformation |
0 commit comments