@@ -21,15 +21,18 @@ import clsx from "classnames"
2121import useValidateEvent from "./useValidateEvent"
2222import Loadable from "@/components/Loadable"
2323import Typography from "@mui/material/Typography"
24+ import Grid from "@mui/material/Grid"
25+ import Switch from "@mui/material/Switch"
2426import { PAB , PlainButton } from "@/components/Buttons"
2527import { Check , Warning , Error as ErrorIcon } from "@mui/icons-material"
2628import PrettyJson from "@/components/PrettyJson"
2729import usePayload from "./usePayload"
2830import { ValidationMessage } from "../types"
2931import Spinner from "@/components/Spinner"
3032import { EventCtx , Label } from ".."
31- import { Card } from "@mui/material"
33+ import { Box , Card } from "@mui/material"
3234import { green , red } from "@mui/material/colors"
35+ import WithHelpText from "@/components/WithHelpText"
3336
3437const PREFIX = 'ValidateEvent' ;
3538
@@ -47,6 +50,7 @@ interface TemplateProps {
4750 sent ?: boolean
4851 payloadErrors ?: string | undefined
4952 useTextBox ?: boolean
53+ useEuEndpoint : boolean
5054}
5155
5256export interface ValidateEventProps {
@@ -166,16 +170,14 @@ const Template: React.FC<TemplateProps> = ({
166170 error,
167171 valid,
168172 payloadErrors,
169- useTextBox
173+ useTextBox,
174+ useEuEndpoint,
170175} ) => {
171176
172177 const { instanceId, api_secret } = useContext ( EventCtx ) !
173178 const payload = usePayload ( )
174179 return (
175- < Card
176- className = { clsx ( classes . form , classes . template ) }
177- data-testid = "validate and send"
178- >
180+ < >
179181 < Typography className = { classes . heading } variant = "h3" >
180182 { headingIcon }
181183 { heading }
@@ -249,9 +251,9 @@ const Template: React.FC<TemplateProps> = ({
249251 { instanceId . firebase_app_id &&
250252 `&firebase_app_id=${ instanceId . firebase_app_id } ` }
251253 { instanceId . measurement_id &&
252- `&measurement_id=${ instanceId . measurement_id } ` } { " " }
254+ `&measurement_id=${ instanceId . measurement_id } ` } { " " } < br />
253255 HTTP/1.1 < br />
254- HOST: www.google-analytics.com < br />
256+ HOST: { useEuEndpoint ? "region1.google-analytics.com" : " www.google-analytics.com" } < br />
255257 Content-Type: application/json
256258 </ Typography >
257259
@@ -265,87 +267,124 @@ const Template: React.FC<TemplateProps> = ({
265267 tooltipText = "Copy payload"
266268 />
267269 </ section >
268- </ Card >
270+ </ >
269271 )
270272}
271273
272274const ValidateEvent : React . FC < ValidateEventProps > = ( { formatPayload, payloadErrors, useTextBox} ) => {
273- const request = useValidateEvent ( )
275+ const [ useEuEndpoint , setUseEuEndpoint ] = React . useState ( false )
276+ const request = useValidateEvent ( useEuEndpoint )
274277
275278 return (
276- < Loadable
277- request = { request }
278- renderNotStarted = { ( { validateEvent } ) => (
279- < Template
280- heading = "This event has not been validated"
281- headingIcon = { < Warning /> }
282- body = {
283- < Root >
284- < Typography >
285- Update the event using the controls above.
286- </ Typography >
287- < Typography >
288- When you're done editing the event, click "Validate Event" to
289- check if the event is valid.
290- </ Typography >
291- </ Root >
292- }
293- validateEvent = { ( ) => {
279+ < Root className = { classes . form } >
280+ < Box mb = { 1 } className = { clsx ( classes . form , classes . template ) } >
281+ < WithHelpText
282+ notched
283+ shrink
284+ label = "server endpoint"
285+ helpText = "The default endpoint is https://www.google-analytics.com. If 'EU' is selected, the https://region1.google-analytics.com endpoint will be used to validate and send events."
286+ >
287+ < Grid component = "label" container alignItems = "center" spacing = { 1 } >
288+ < Grid item > Default</ Grid >
289+ < Grid item >
290+ < Switch
291+ data-testid = "use-eu-endpoint"
292+ checked = { useEuEndpoint }
293+ onChange = { e => setUseEuEndpoint ( e . target . checked ) }
294+ name = "use-eu-endpoint"
295+ color = "primary"
296+ />
297+ </ Grid >
298+ < Grid item > EU</ Grid >
299+ </ Grid >
300+ </ WithHelpText >
301+ </ Box >
302+ < Card className = { clsx ( classes . form , classes . template ) } data-testid = "validate and send" >
303+ < Loadable
304+ request = { request }
305+ renderNotStarted = { ( { validateEvent } ) => (
306+ < Template
307+ useEuEndpoint = { useEuEndpoint }
308+ heading = "This event has not been validated"
309+ headingIcon = { < Warning /> }
310+ body = {
311+ < >
312+ < Typography >
313+ Update the event using the controls above.
314+ </ Typography >
315+ < Typography >
316+ When you're done editing the event, click "Validate Event" to
317+ check if the event is valid.
318+ </ Typography >
319+ </ >
320+ }
321+ validateEvent = { ( ) => {
294322 if ( formatPayload ) {
295323 formatPayload ( )
296324 }
297325
298326 validateEvent ( )
299- }
300- }
301- />
302- ) }
303- renderInProgress = { ( ) => (
304- < Template heading = "Validating" body = { < Spinner ellipses /> } />
305- ) }
306- renderFailed = { ( { validationMessages, validateEvent} ) => (
307- < Template
308- error
309- headingIcon = { < ErrorIcon /> }
310- heading = "Event is invalid"
311- body = ""
312- validateEvent = { ( ) => {
327+ } }
328+ />
329+ ) }
330+ renderInProgress = { ( ) => (
331+ < Template
332+ useEuEndpoint = { useEuEndpoint }
333+ heading = "Validating"
334+ body = { < Spinner ellipses /> }
335+ />
336+ ) }
337+ renderFailed = { ( { validationMessages, validateEvent } ) => (
338+ < Template
339+ useEuEndpoint = { useEuEndpoint }
340+ error
341+ headingIcon = { < ErrorIcon /> }
342+ heading = "Event is invalid"
343+ body = ""
344+ validateEvent = { ( ) => {
313345 if ( formatPayload ) {
314346 formatPayload ( )
315347 }
316348
317349 validateEvent ( )
350+ } }
351+ validationMessages = { validationMessages }
352+ payloadErrors = { payloadErrors }
353+ useTextBox = { useTextBox }
354+ />
355+ ) }
356+ renderSuccessful = { ( {
357+ sendToGA,
358+ copyPayload,
359+ copySharableLink,
360+ sent,
361+ } ) => (
362+ < Template
363+ useEuEndpoint = { useEuEndpoint }
364+ sent = { sent }
365+ valid
366+ heading = "Event is valid"
367+ headingIcon = { < Check /> }
368+ sendToGA = { sendToGA }
369+ copyPayload = { copyPayload }
370+ copySharableLink = { copySharableLink }
371+ body = {
372+ < >
373+ < Typography >
374+ Use the controls below to copy the event payload or share it
375+ with coworkers.
376+ </ Typography >
377+ < Typography >
378+ You can also send the event to Google Analytics and watch it in
379+ action in the Real Time view.
380+ </ Typography >
381+ </ >
318382 }
319- }
320- validationMessages = { validationMessages }
321- payloadErrors = { payloadErrors }
322- useTextBox = { useTextBox }
323- />
324- ) }
325- renderSuccessful = { ( { sendToGA, copyPayload, copySharableLink, sent} ) => (
326- < Template
327- sent = { sent }
328- valid
329- heading = "Event is valid"
330- headingIcon = { < Check /> }
331- sendToGA = { sendToGA }
332- copyPayload = { copyPayload }
333- copySharableLink = { copySharableLink }
334- body = {
335- < >
336- < Typography >
337- Use the controls below to copy the event payload or share it
338- with coworkers.
339- </ Typography >
340- < Typography >
341- You can also send the event to Google Analytics and watch it in
342- action in the Real Time view.
343- </ Typography >
344- </ >
345- }
383+ />
384+ ) }
346385 />
347- ) }
348- / >
386+ </ Card >
387+ </ Root >
349388 ) ;
350389}
351390
0 commit comments